diff options
Diffstat (limited to 'dexlib2/src/main/java/com/android/tools/smali/util/InputStreamUtil.java')
-rw-r--r-- | dexlib2/src/main/java/com/android/tools/smali/util/InputStreamUtil.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/dexlib2/src/main/java/com/android/tools/smali/util/InputStreamUtil.java b/dexlib2/src/main/java/com/android/tools/smali/util/InputStreamUtil.java index 46f696a1..0532f0c2 100644 --- a/dexlib2/src/main/java/com/android/tools/smali/util/InputStreamUtil.java +++ b/dexlib2/src/main/java/com/android/tools/smali/util/InputStreamUtil.java @@ -38,6 +38,7 @@ import java.io.DataInput; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayDeque; import java.util.Arrays; import java.util.Queue; @@ -259,4 +260,30 @@ public final class InputStreamUtil { } return total; } + + /** + * Copies all bytes from the input stream to the output stream. Does not close or flush either + * stream. + * + * @param from the input stream to read from + * @param to the output stream to write to + * @return the number of bytes copied + * @throws IOException if an I/O error occurs + */ + public static long copy(InputStream from, OutputStream to) throws IOException { + if (from == null || to == null) { + throw new NullPointerException(); + } + byte[] buf = new byte[BUFFER_SIZE]; + long total = 0; + while (true) { + int r = from.read(buf); + if (r == -1) { + break; + } + to.write(buf, 0, r); + total += r; + } + return total; + } } |