diff --git a/Dorkbox-Util/src/dorkbox/util/IO.java b/Dorkbox-Util/src/dorkbox/util/IO.java index 6dfbc2f..1ef194b 100644 --- a/Dorkbox-Util/src/dorkbox/util/IO.java +++ b/Dorkbox-Util/src/dorkbox/util/IO.java @@ -15,12 +15,15 @@ */ package dorkbox.util; +import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -@SuppressWarnings("unused") +import javax.imageio.stream.ImageInputStream; + +@SuppressWarnings({"unused", "Duplicates"}) public class IO { /** @@ -70,7 +73,7 @@ class IO { /** * Copy the contents of the input stream to the output stream. - *
+ ** DOES NOT CLOSE THE STEAMS! */ public static @@ -85,4 +88,60 @@ class IO { return outputStream; } + + /** + * Copy the contents of the input stream to the output stream. + *
+ * DOES NOT CLOSE THE STEAMS!
+ */
+ public static
+
+ * DOES NOT CLOSE THE STEAMS!
+ */
+ public static
+ ByteArrayOutputStream copyStream(final InputStream inputStream) throws IOException {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(4096);
+ byte[] buffer = new byte[4096];
+ int read;
+
+ while ((read = inputStream.read(buffer)) > 0) {
+ outputStream.write(buffer, 0, read);
+ }
+ outputStream.flush();
+
+ return outputStream;
+ }
+
+ /**
+ * Copy the contents of the input stream to a new output stream.
+ *
+ * DOES NOT CLOSE THE STEAMS!
+ */
+ public static
+ ByteArrayOutputStream copyStream(final ImageInputStream inputStream) throws IOException {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(4096);
+ byte[] buffer = new byte[4096];
+ int read;
+
+ while ((read = inputStream.read(buffer)) > 0) {
+ outputStream.write(buffer, 0, read);
+ }
+ outputStream.flush();
+
+ return outputStream;
+ }
}