IoBufferUtil { public static boolean canAccomodate(ByteBuffer existingBuffer, int additionalLength) { return ((existingBuffer.position() + additionalLength) <= existingBuffer.limit()); }  static ByteBuffer expandBuffer(ByteBuffer existingBuffer, int additionalRequired); static boolean canAccomodate(ByteBuffer existingBuffer, int additionalLength);  }
@Test public void testIoBufferUtilCanAccomodate() { ByteBuffer buf = ByteBuffer.allocate(10); buf.put("012345".getBytes()); assertTrue(IoBufferUtil.canAccomodate(buf, 4)); assertFalse(IoBufferUtil.canAccomodate(buf, 5)); buf.put("6789".getBytes()); }