| Code highlighting produced by Actipro CodeHighlighter (freeware) |
| http://www.CodeHighlighter.com/ |
|
| -->/** |
| * 逆转字节数组 |
| * |
| * @param b |
| * @return |
| */ |
| private static byte[] reverse(byte[] b) { |
|
| byte[] temp = new byte[b.length]; |
| for (int i = 0; i < b.length; i++) { |
| temp = b[b.length - 1 - i]; |
| } |
| return temp; |
| } |
|
| /** |
| * 读取无符号位的Short数,16位 |
| * |
| * @param readBuffer |
| * @return |
| * @throws IOException |
| */ |
| private static final BigInteger readUnsignedShort(byte[] readBuffer) |
| throws IOException { |
| if (readBuffer == null | | readBuffer.length < 2) |
| return new BigInteger("0"); |
| // 处理成无符号数 |
| byte[] uint64 = new byte[3]; |
| uint64[2] = 0; |
| System.arraycopy(readBuffer, 0, uint64, 0, 2); |
| return new BigInteger(reverse(uint64)); |
| } |
|
| /** |
| * 读取无符号位的长整数,64位 |
| * |
| * @param readBuffer |
| * @return |
| * @throws IOException |
| */ |
| private static final BigInteger readUnsignedInt64(byte[] readBuffer) |
| throws IOException { |
| if (readBuffer == null | | readBuffer.length < 8) |
| return new BigInteger("0"); |
| // 处理成无符号数 |
| byte[] uint64 = new byte[9]; |
| uint64[8] = 0; |
| System.arraycopy(readBuffer, 0, uint64, 0, 8); |
| return new BigInteger(reverse(uint64)); |
| } |