code: public static byte[] toByteArray(InputStream in, int bufferSize) throws IOException {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          copyData(in, out, bufferSize);
          return out.toByteArray();
      }
docs: Copies all available data from {@code in} to byte array.
  
  @param in
  input stream to copy data from.
  @param bufferSize
  buffer size to use.
  
  @return An array of bytes read from input stream.
  
  @throws IOException