ReadBuffer { public Integer getInt() { if (byteBuffer.position() + 4 > limit) { throw new LimitReachedException(); } return byteBuffer.getInt(); } ReadBuffer(ByteBuffer byteBuffer); private  ReadBuffer(ByteBuffer byteBuffer, int limit); Boolean getBoolean(); Double getDouble(); Long getLong(); Character getChar(); Integer getInt(); int getVlqInt(); ByteBuffer getByteBuffer(int size); String getString(int size); boolean limitReached(); void skipAll(); void skip(int size); ReadBuffer limit(int size);  }
@Test public void testReadBufferOverPartiallyReadByteBuffer() throws Exception { ByteBuffer byteBuffer = ByteBuffer.allocate(4); byteBuffer.put((byte) 1); ReadBuffer readBuffer = new ReadBuffer(byteBuffer); try { readBuffer.getInt(); fail(); } catch (LimitReachedException e) { } }