CompressedByteBuffer { public void add(long i) { if (i < 1 << 7) { addRaw((int) (i | 0x80)); } else if (i < 1 << 14) { addRaw((int) (i >> 0) & 0x7f); addRaw((int) ((i >> 7) & 0x7f) | 0x80); } else if (i < 1 << 21) { addRaw((int) (i >> 0) & 0x7f); addRaw((int) (i >> 7) & 0x7f); addRaw((int) ((i >> 14) & 0x7f) | 0x80); } else { while (i >= 1 << 7) { addRaw((int) (i & 0x7f)); i >>= 7; } addRaw((int) (i | 0x80)); } } CompressedByteBuffer();  CompressedByteBuffer(int resetSize); void addRaw(int value); void add(long i); void addFloat(float value); void addDouble(double value); void add(CompressedByteBuffer other); void clear(); byte[] getBytes(); long length(); void write(OutputStream stream); public TByteArrayList values; }
@Test public void testAdd() throws Exception { CompressedByteBuffer instance = new CompressedByteBuffer(); instance.add( 5 ); instance.add( 10 ); instance.add( 200 ); instance.add( 400 ); byte[] result = new byte[] { (byte) (5 | 1<<7), (byte) (10 | 1<<7), 72, (byte) (1 | 1<<7), 16, (byte) (3 | 1<<7) }; assertEquals( result.length, instance.length() ); for( int i=0; i<result.length; i++ ) { assertEquals( result[i], instance.getBytes()[i] ); } }