public static byte[] toByteArray(final InputStream in) throws IOException {
    assert in != null : "The input stream to read bytes from cannot be null!";

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final byte[] buffer = new byte[BUFFER_SIZE];
    int bytesRead;

    try {
      while ((bytesRead = in.read(buffer)) != -1) {
        out.write(buffer, 0, bytesRead);
        out.flush();
      }
    } finally {
      IOUtils.close(in);
      IOUtils.close(out);
    }

    return out.toByteArray();
  }
Reads the contents of the specified InputStream into a byte array.
<p>

@param in the InputStream to read content from.
@return a byte array containing the content of the specified InputStream.
@throws IOException if an I/O error occurs while reading the InputStream.
@see java.io.ByteArrayOutputStream
@see java.io.InputStream
geode-core/src/main/java/org/apache/geode/internal/util/IOUtils.java