[Edit]
+
0
-
0

Java - write output stream to memory (OutputStream to byte array)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import java.io.OutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; class Program { public static void main(String[] args) throws IOException { byte[] bytes; try (ByteArrayOutputStream memoryStream = new ByteArrayOutputStream()) { OutputStream outputStream = (OutputStream) memoryStream; // ... bytes = memoryStream.toByteArray(); } // ... } }