code: public static byte[] toByteArray(InputStream inputStream) throws IOException {
          ByteArrayOutputStream buffer = new ByteArrayOutputStream();
          int nRead;
          byte[] bytes = new byte[1024];
          while ((nRead = inputStream.read(bytes, 0, 1024)) != -1) {
              buffer.write(bytes, 0, nRead);
          }
          return buffer.toByteArray();
      }
docs: Convert an
  <a href="http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html">InputSteam</a> to a byte array.
  
  @param inputStream the <code>InputStream</code> to convert.
  @return a byte array containing the data from the input stream.
  @throws IOException if the <code>InputStream</code> could not be converted.