code: public static byte[] toByteArray(InputStream source, int bufferSize) throws IOException {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          copy(source, baos, bufferSize);
          source.close();
          return baos.toByteArray();
      }
docs: Reads the given input stream into a byte array and closes the input stream
  
  @param source     The source of the bytes
  @param bufferSize The size of the byte buffer to use when copying streams
  @return Returns a byte array
  @throws IOException If there is an error reading from the stream