VarLenIntEncoderDecoder { public static int getBytesRequired(int length) { if (length < 0) { throw new IllegalArgumentException("The length must be an non-negative value"); } int byteCount = 0; while (length > ENCODE_MASK) { length = length >>> 7; byteCount++; } return byteCount + 1; }  static int getBytesRequired(int length); static int decode(DataInput in); static int decode(byte[] srcBytes, int startPos); static int encode(int lengthVal, byte[] destBytes, int startPos); static VarLenIntDecoder createDecoder(); static final int BOUND_ONE_BYTE; static final int BOUND_TWO_BYTE; static final int BOUND_THREE_BYTE; static final int BOUND_FOUR_BYTE; static final int BOUND_FIVE_BYTE; static final int ENCODE_MASK; static final byte CONTINUE_CHUNK; static final byte DECODE_MASK; }
@Test public void testGetBytesRequired() throws Exception { for (int bound = 0; bound < bounds.length - 1; bound++) { assertEquals(bound + 1, getBytesRequired(bounds[bound])); assertEquals(bound + 1, getBytesRequired(bounds[bound + 1] - 1)); } }