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) < 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 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 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 >> 24) & 0xFF;</div>
<div style="line-height:25px"> int ch2 = (value >> 16) & 0xFF;</div>
<div style="line-height:25px"> int ch3 = (value >> 8) & 0xFF;</div>
<div style="line-height:25px"> int ch4 = value & 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) < 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 << 8) + (ch1 << 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 >> 8) & 0xFF;</div>
<div style="line-height:25px"> int ch2 = value & 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>