BooleanCodec implements BlockCodec<Boolean> { @Override public byte[] encode(Boolean data, int bitLength) throws BlockCodecException { int value = Boolean.TRUE.equals(data) ? this.trueValue : this.falseValue; IntegerCodec ic = new IntegerCodec(true); return ic.encode(value, bitLength); } BooleanCodec(); String getTrueValue(); void setTrueValue(String value); String getFalseValue(); void setFalseValue(String value); @Override Boolean zeroValue(); @Override Boolean decode(byte[] data, int bitLength); @Override byte[] encode(Boolean data, int bitLength); @Override void reset(); @Override String getValueType();  }
@Test public void testEncode() throws BlockCodecException { BooleanCodec codec = new BooleanCodec(); Assert.assertEquals((byte) 0x80, codec.encode(true, 1)[0]); Assert.assertEquals((byte) 0x40, codec.encode(true, 2)[0]); Assert.assertEquals((byte) 0x20, codec.encode(true, 3)[0]); Assert.assertEquals((byte) 0x10, codec.encode(true, 4)[0]); Assert.assertEquals((byte) 0x08, codec.encode(true, 5)[0]); Assert.assertEquals((byte) 0x04, codec.encode(true, 6)[0]); Assert.assertEquals((byte) 0x02, codec.encode(true, 7)[0]); Assert.assertEquals((byte) 0x01, codec.encode(true, 8)[0]); }