- Timestamp:
- 07/23/12 18:23:18 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Tests/JAVA/test/src/main/java/test/ivan/FileParser.java
r556 r557 19 19 public class FileParser { 20 20 private static final Log log = LogFactory.getLog( FileParser.class ); 21 protected static final int HASH_LENGTH = 16; 21 22 private static final boolean PRINT_PACKETS = Boolean.getBoolean( "print-packets" ); 23 24 protected static final int HASH_LENGTH = 20; 22 25 protected static final long MAGIC_NUMBER = 0xa1b2c3d4L; 23 26 … … 106 109 throw new IOException( "Unexpected EOF: actualBufferLength=" + actualBufferLength + ", but only " + read + " actually read" ); 107 110 } 111 if( PRINT_PACKETS ) { 112 log.info( toHexString( buffer, actualBufferLength ) ); 113 } 108 114 109 115 final byte packetType = buffer[12]; … … 133 139 final byte[] hash = Arrays.copyOfRange( 134 140 buffer, 135 5 4,136 5 4+ HASH_LENGTH141 50, 142 50 + HASH_LENGTH 137 143 ); 138 144 … … 176 182 return signedShort & 0xFFFF; 177 183 } 184 185 private static String toHexString( final byte[] bytes, 186 final int length ) { 187 final StringBuilder sb = new StringBuilder( 1024 ); 188 final Formatter fmt = new Formatter( sb ); 189 for( int i = 0; i < length; i++ ) { 190 if( i % 16 == 0 ) { 191 fmt.format( "\n%04x: ", i ); 192 } 193 final byte b = bytes[i]; 194 fmt.format( "%02x", b ); 195 } 196 fmt.flush(); 197 return sb.toString(); 198 } 178 199 }
Note: See TracChangeset
for help on using the changeset viewer.