//https://www.techiedelight.com/convert-inputstream-byte-array-java/ private static byte[] toByteArray(InputStream in) throws IOException{ ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; //Reads up to len bytes of data from the input stream into an array of bytes. //Check: https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html#read-byte:A- while((len = in.read(buffer)) != -1){ //指定されたバイト配列のオフセット位置offから始まるlenバイトをこのバイト配列出力ストリームに書き込みます。 os.write(buffer, 0, len); } return os.toByteArray(); }