IntegerCodec implements BlockCodec<Integer> { @Override public Integer decode(byte[] data, int bitLength) throws BlockCodecException { try { return new Integer(ByteUtils.intValue(data, bitLength, this.unsigned)); } catch (Exception ex) { throw new BlockCodecException("integer decode failure. " + ex.getMessage(), ex); } } IntegerCodec();  IntegerCodec(boolean unsigned); void setUnsigned(String yn); String getUnsigned(); @Override Integer zeroValue(); @Override Integer decode(byte[] data, int bitLength); @Override byte[] encode(Integer data, int bitLength); @Override void reset(); @Override String getValueType();  }
@Test public void testDecode() throws Exception { IntegerCodec codec = new IntegerCodec(); Assert.assertEquals(-2, codec.decode(new byte[] { (byte) 0xfe }, 8), 0); Assert.assertEquals(-1, codec.decode(new byte[] { (byte) 0xfe }, 7), 0); Assert.assertEquals(-2, codec.decode(new byte[] { (byte) 0xff, (byte) 0xfe }, 16), 0); Assert.assertEquals(-2, codec.decode(new byte[] { (byte) 0xff, (byte) 0xfd }, 15), 0); Assert.assertEquals(-4, codec.decode(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xfc, (byte) 0x8f }, 24), 0); Assert.assertEquals(-1024, codec.decode(new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xfc, (byte) 0x00 }, 32), 0); }