exportSprite之八(Util)

本文介绍了一个名为Util的Java工具类,该类提供了多种用于数据读写的方法,包括按不同格式写入整数和短整型数据,以及字符串处理和输入输出流的关闭等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Util.java文件源码:<wbr style="line-height:25px"><div style="line-height:25px"> <div style="line-height:25px">import java.io.*;</div> <div style="line-height:25px"><br style="line-height:25px"></div> <div style="line-height:25px"><span style="color:#993300; line-height:25px">public class Util</span></div> <div style="line-height:25px">{</div> <div style="line-height:25px"> final static int kHeightForwardFormatWrite=0;</div> <div style="line-height:25px"> final static int kHeightBackwardFormatWrite=1;</div> <div style="line-height:25px"> final static int kCFormatWrite=kHeightBackwardFormatWrite;</div> <div style="line-height:25px"> final static int kJavaFormatWrite=kHeightForwardFormatWrite; </div> <div style="line-height:25px"> static int dataWriteFormat=kCFormatWrite;</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">static void setDataWriteFormat(int format)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> dataWriteFormat=format;</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">static String trimSemicolon(String str)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> str = str.replaceAll("\"", "");</div> <div style="line-height:25px"> str = str.replaceAll("\"", "");</div> <div style="line-height:25px"> return str;</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"><br style="line-height:25px"></div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">static int readInt2(DataInputStream in)</span> </div> <div style="line-height:25px"> throws IOException</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> int ch1 = in.read();</div> <div style="line-height:25px"> int ch2 = in.read();</div> <div style="line-height:25px"> int ch3 = in.read();</div> <div style="line-height:25px"> int ch4 = in.read();</div> <div style="line-height:25px"> if ((ch1 | ch2 | ch3 | ch4) &lt; 0)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> throw new EOFException();</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> return ((ch4 &lt;&lt; 24) + (ch3 &lt;&lt; 16) + (ch2 &lt;&lt; 8) + (ch1 &lt;&lt; 0));</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">public static void writeInt(DataOutputStream os, int value)</span> </div> <div style="line-height:25px"> throws IOException</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> if(dataWriteFormat==kCFormatWrite)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> writeInt2(os,value);</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> else</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> os.writeInt(value);</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">private static void writeInt2(DataOutputStream os, int value)</span> </div> <div style="line-height:25px"> throws IOException</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> int ch1 = (value &gt;&gt; 24) &amp; 0xFF;</div> <div style="line-height:25px"> int ch2 = (value &gt;&gt; 16) &amp; 0xFF;</div> <div style="line-height:25px"> int ch3 = (value &gt;&gt; 8) &amp; 0xFF;</div> <div style="line-height:25px"> int ch4 = value &amp; 0xFF;</div> <div style="line-height:25px"> os.writeByte(ch4);</div> <div style="line-height:25px"> os.writeByte(ch3);</div> <div style="line-height:25px"> os.writeByte(ch2);</div> <div style="line-height:25px"> os.writeByte(ch1);</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"><br style="line-height:25px"></div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">static short readShort2(DataInputStream in)</span> </div> <div style="line-height:25px"> throws IOException</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> int ch1 = in.read();</div> <div style="line-height:25px"> int ch2 = in.read();</div> <div style="line-height:25px"> if ((ch1 | ch2) &lt; 0)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> throw new EOFException();</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> return (short) ((ch2 &lt;&lt; 8) + (ch1 &lt;&lt; 0));</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">public static void writeShort(DataOutputStream os, int value)</span> </div> <div style="line-height:25px"> throws IOException</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> if(dataWriteFormat==kCFormatWrite)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> writeShort2(os,value);</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> else</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> os.writeShort(value);</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">private static void writeShort2(DataOutputStream os, int value)</span> </div> <div style="line-height:25px"> throws IOException</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> int ch1 = (value &gt;&gt; 8) &amp; 0xFF;</div> <div style="line-height:25px"> int ch2 = value &amp; 0xFF;</div> <div style="line-height:25px"> os.writeByte(ch2);</div> <div style="line-height:25px"> os.writeByte(ch1);</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"><br style="line-height:25px"></div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">static void closeInputStream(DataInputStream in)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> try</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> if (in != null)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> in.close();</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> } catch (IOException e)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> e.printStackTrace();</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"><br style="line-height:25px"></div> <div style="line-height:25px"> <span style="color:#FF6600; line-height:25px">static void closeDataputStream(DataOutputStream out)</span> </div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> try</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> if (out != null)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> out.close();</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> } catch (IOException e)</div> <div style="line-height:25px"> {</div> <div style="line-height:25px"> e.printStackTrace();</div> <div style="line-height:25px"> }</div> <div style="line-height:25px"> }</div> <div style="line-height:25px">}</div> </div> </wbr>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值