### Question:
IOUtils { public static byte[] readFully(InputStream in) throws IOException { List<ByteBuffer> buffers = new ArrayList<>(4); while(true) { ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE); int count = in.read(buffer.array(), 0, BUFFER_SIZE); if(count > 0) { buffer.limit(count); buffers.add(buffer); } if (count < BUFFER_SIZE) break; } return getAsBytes(buffers); }  static Object readObject(DataInput in); static void writeObject(DataOutput out, Object obj); static void serialize(Configuration conf, DataOutput out
      , T obj, Class<T> objClass); @SuppressWarnings("unchecked") static void serialize(Configuration conf, DataOutput out
      , T obj); static byte[] serialize(Configuration conf, T obj); static void serialize(OutputStream os,
      SpecificDatumWriter<T> datumWriter, T object); static void serialize(OutputStream os,
      SpecificDatumWriter<T> datumWriter, T object); static byte[] serialize(SpecificDatumWriter<T> datumWriter
      , T object); static byte[] serialize(SpecificDatumWriter<T> datumWriter
      , T object); @SuppressWarnings("unchecked") static T deserialize(Configuration conf, DataInput in
      , T obj , String objClass); static T deserialize(Configuration conf, DataInput in
      , T obj , Class<T> objClass); @SuppressWarnings("unchecked") static T deserialize(Configuration conf, DataInput in
      , T obj); static T deserialize(Configuration conf, byte[] in
      , T obj); static T deserialize(InputStream is,
      SpecificDatumReader<T> datumReader, T object); static T deserialize(byte[] bytes,
      SpecificDatumReader<T> datumReader, T object); static T deserialize(byte[] bytes,
      SpecificDatumReader<T> datumReader, T object); static void writeNullFieldsInfo(DataOutput out, Object ... fields); static boolean[] readNullFieldsInfo(DataInput in); static void writeBoolArray(DataOutput out, boolean[] boolArray); static boolean[] readBoolArray(DataInput in); static void writeBoolArray(Encoder out, boolean[] boolArray); static boolean[] readBoolArray(Decoder in); static void writeStringArray(DataOutput out, String[] arr); static String[] readStringArray(DataInput in); static void storeToConf(T obj, Configuration conf, String dataKey); @SuppressWarnings("unchecked") static T loadFromConf(Configuration conf, String dataKey); static byte[] getAsBytes(List<ByteBuffer> buffers); static byte[] readFully(InputStream in); static final int BUFFER_SIZE; }### Answer:
@Test public void testReadFullyBufferLimit() throws IOException { for(int i=-2; i<=2; i++) { byte[] bytes = new byte[IOUtils.BUFFER_SIZE + i]; for(int j=0; j<bytes.length; j++) { bytes[j] = (byte)j; } ByteArrayInputStream is = new ByteArrayInputStream(bytes); byte[] readBytes = IOUtils.readFully(is); assertByteArrayEquals(bytes, readBytes); } }