OrderedCode { public void writeTrailingBytes(byte[] value) { if ((value == null) || (value.length == 0)) { throw new IllegalArgumentException("Value cannot be null or have 0 elements"); } encodedArrays.add(value); } OrderedCode();  OrderedCode(byte[] encodedByteArray); void writeBytes(byte[] value); void writeNumIncreasing(long value); void writeSignedNumIncreasing(long val); void writeInfinity(); void writeTrailingBytes(byte[] value); byte[] readBytes(); long readNumIncreasing(); long readSignedNumIncreasing(); boolean readInfinity(); byte[] readTrailingBytes(); byte[] readBytes(int len); byte[] getEncodedBytes(); boolean hasRemainingEncodedBytes(); static final byte ESCAPE1; static final byte NULL_CHARACTER; static final byte SEPARATOR; static final byte ESCAPE2; static final byte INFINITY; static final byte FF_CHARACTER; static final byte[] ESCAPE1_SEPARATOR; }
@Test public void testWriteTrailingBytes() { byte[] escapeChars = new byte[] { OrderedCode.ESCAPE1, OrderedCode.NULL_CHARACTER, OrderedCode.SEPARATOR, OrderedCode.ESCAPE2, OrderedCode.INFINITY, OrderedCode.FF_CHARACTER }; byte[] anotherArray = new byte[] {'a', 'b', 'c', 'd', 'e'}; OrderedCode orderedCode = new OrderedCode(); orderedCode.writeTrailingBytes(escapeChars); assertArrayEquals(orderedCode.getEncodedBytes(), escapeChars); assertArrayEquals(orderedCode.readTrailingBytes(), escapeChars); try { orderedCode.readInfinity(); fail("Expected IllegalArgumentException."); } catch (IllegalArgumentException e) { } orderedCode = new OrderedCode(); orderedCode.writeTrailingBytes(anotherArray); assertArrayEquals(orderedCode.getEncodedBytes(), anotherArray); assertArrayEquals(orderedCode.readTrailingBytes(), anotherArray); }