@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); } }
public static byte[] readFully(InputStream in) throws IOException { List<ByteBuffer> buffers = new ArrayList<ByteBuffer>(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); }
IOUtils { public static byte[] readFully(InputStream in) throws IOException { List<ByteBuffer> buffers = new ArrayList<ByteBuffer>(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); } }
IOUtils { public static byte[] readFully(InputStream in) throws IOException { List<ByteBuffer> buffers = new ArrayList<ByteBuffer>(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); }  }
IOUtils { public static byte[] readFully(InputStream in) throws IOException { List<ByteBuffer> buffers = new ArrayList<ByteBuffer>(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,
      PersistentDatumWriter<T> datumWriter, Schema schema, Object object); static byte[] serialize(PersistentDatumWriter<T> datumWriter
      , Schema schema, Object 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); @SuppressWarnings("unchecked") static K deserialize(InputStream is,
      PersistentDatumReader<T> datumReader, Schema schema, K object); @SuppressWarnings("unchecked") static K deserialize(byte[] bytes,
      PersistentDatumReader<T> datumReader, Schema schema, K object); static byte[] deserialize(PersistentDatumWriter<T> datumWriter
      , Schema schema, Object 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); }
IOUtils { public static byte[] readFully(InputStream in) throws IOException { List<ByteBuffer> buffers = new ArrayList<ByteBuffer>(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,
      PersistentDatumWriter<T> datumWriter, Schema schema, Object object); static byte[] serialize(PersistentDatumWriter<T> datumWriter
      , Schema schema, Object 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); @SuppressWarnings("unchecked") static K deserialize(InputStream is,
      PersistentDatumReader<T> datumReader, Schema schema, K object); @SuppressWarnings("unchecked") static K deserialize(byte[] bytes,
      PersistentDatumReader<T> datumReader, Schema schema, K object); static byte[] deserialize(PersistentDatumWriter<T> datumWriter
      , Schema schema, Object 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; }