code: public static byte[] toByteArray(InputStream is) throws IOException {
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          try {
              byte[] b = new byte[BUFFER_SIZE];
              int n = 0;
              while ((n = is.read(b)) != -1) {
                  output.write(b, 0, n);
              }
              return output.toByteArray();
          } finally {
              output.close();
          }
      }
docs: Reads and returns the rest of the given input stream as a byte array.
  Caller is responsible for closing the given input stream.
  @param is input stream
  @return byte[] byte array
  @throws IOException IOException