code: public static byte[] inputStreamToBytes(InputStream in) {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          try {
              byte[] buffer = new byte[1024];
              int len;
              while ((len = in.read(buffer)) != -1) {
                  out.write(buffer, 0, len);
              }
          } catch (Exception e) {
              System.out.println("Error converting InputStream to byte[]: "
                      + e.getMessage());
          }
          return out.toByteArray();
      }
docs: Converts an InputStream to a byte[]