public static byte[] toByteArray(InputStream in) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    copy(in, out);
    return out.toByteArray();
  }
Reads all bytes from an input stream into a byte array. Does not close the stream.

@param in the input stream to read from
@return a byte array containing all the bytes from the stream
@throws IOException if an I/O error occurs
fbcore/src/main/java/com/facebook/common/internal/ByteStreams.java