/** * Calculate the CRC32 value of this record. * @return the CRC32 value of this record. */ public int calculateCrc32() { CRC32 crc32 = new CRC32(); crc32.update(Encoder.intToBytes(status)); crc32.update(Encoder.intToBytes(recordLength)); crc32.update(Encoder.intToBytes(headerLength)); crc32.update(Encoder.longToBytes(time)); crc32.update(Encoder.intToBytes(sequenceNumber)); crc32.update(gtrid.getArray()); crc32.update(Encoder.intToBytes(uniqueNames.size())); for (String name : uniqueNames) { crc32.update(Encoder.shortToBytes((short) name.length())); try { crc32.update(name.getBytes("US-ASCII")); } catch (UnsupportedEncodingException ex) { log.error("unable to convert unique name bytes to US-ASCII", ex); } } crc32.update(Encoder.intToBytes(endRecord)); return (int) crc32.getValue(); }
/** * Calculate the CRC32 value of this record. * @return the CRC32 value of this record. */ public int calculateCrc32() { CRC32 crc32 = new CRC32(); crc32.update(Encoder.intToBytes(status)); crc32.update(Encoder.intToBytes(recordLength)); crc32.update(Encoder.intToBytes(headerLength)); crc32.update(Encoder.longToBytes(time)); crc32.update(Encoder.intToBytes(sequenceNumber)); crc32.update(gtrid.getArray()); crc32.update(Encoder.intToBytes(uniqueNames.size())); for (String name : uniqueNames) { crc32.update(Encoder.shortToBytes((short) name.length())); try { crc32.update(name.getBytes("US-ASCII")); } catch (UnsupportedEncodingException ex) { log.error("unable to convert unique name bytes to US-ASCII", ex); } } crc32.update(Encoder.intToBytes(endRecord)); return (int) crc32.getValue(); }
public void testHexaStringEncoder() throws Exception { byte[] result = Encoder.intToBytes(0x80); String hexString = new Uid(result).toString(); assertEquals("00000080", hexString); result = Encoder.longToBytes(0x81); hexString = new Uid(result).toString(); assertEquals("0000000000000081", hexString); result = Encoder.shortToBytes((short) 0xff); hexString = new Uid(result).toString(); assertEquals("00FF", hexString); }
public void testHexaStringEncoder() throws Exception { byte[] result = Encoder.intToBytes(0x80); String hexString = new Uid(result).toString(); assertEquals("00000080", hexString); result = Encoder.longToBytes(0x81); hexString = new Uid(result).toString(); assertEquals("0000000000000081", hexString); result = Encoder.shortToBytes((short) 0xff); hexString = new Uid(result).toString(); assertEquals("00FF", hexString); }