core/src/main/java/nl/nn/adapterframework/util/Misc.java
/**
	 * Writes the content of an input stream to a byte array.
	 * <p>
	 *     Example:
	 *     <pre>
	 *         String test = "test";
	 *         ByteArrayInputStream bais = new ByteArrayInputStream(test.getBytes());
	 *         byte[] arr = Misc.streamToBytes(bais);
	 *         System.out.println(new String(arr, StandardCharsets.UTF_8)); // prints "test"
	 *     </pre>
	 * </p>
	 */
Writes the content of an input stream to a byte array.
Writes the content of an input stream to a byte array .
public static byte[] streamToBytes(InputStream inputStream) throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		while (true) {
			int r = inputStream.read(buffer);
			if (r == -1) {
				break;
			}
			out.write(buffer, 0, r);
		}
		return out.toByteArray();
	}
public static byte [ ] streamToBytes ( InputStream inputStream ) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; byte [ ] buffer = new byte [ 1024 ] ; while ( true ) { int r = inputStream . read ( buffer ) ; if ( r == - 1 ) { break ; } out . write ( buffer , 0 , r ) ; } return out . toByteArray ( ) ; }
Writes the content of an input stream to a byte array.
Writes the content of an input stream to a byte array .