summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Dochez <jedo@google.com>2018-01-25 23:05:26 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-01-25 23:05:26 +0000
commitf007d1a28240d55c2dd2fdb2891f0302c646b60c (patch)
treeb61cf9789bd2990b23485a4b75510ff8468bf6af
parenta9401044040cbc71b0e41ba697ce4d8681afb9dc (diff)
parent86c2d9d3a8f50ac21eb24bda58a4728994d2b196 (diff)
downloadapkzlib-f007d1a28240d55c2dd2fdb2891f0302c646b60c.tar.gz
move dexing to WorkerExecutor. am: 4819383ef2
am: 86c2d9d3a8 Change-Id: I0d196ab60106ce5fe98499ec09a50c11fd6798c9
-rw-r--r--src/main/java/com/android/apkzlib/zip/StoredEntry.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main/java/com/android/apkzlib/zip/StoredEntry.java b/src/main/java/com/android/apkzlib/zip/StoredEntry.java
index 664734e..5693fce 100644
--- a/src/main/java/com/android/apkzlib/zip/StoredEntry.java
+++ b/src/main/java/com/android/apkzlib/zip/StoredEntry.java
@@ -24,6 +24,7 @@ import com.google.common.base.Verify;
import com.google.common.io.ByteSource;
import com.google.common.io.ByteStreams;
import com.google.common.primitives.Ints;
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -347,6 +348,23 @@ public class StoredEntry {
}
/**
+ * Obtains the contents of the file in an existing buffer.
+ *
+ * @param bytes buffer to read the file contents in.
+ * @return the number of bytes read
+ * @throws IOException failed to read the file.
+ */
+ public int read(byte[] bytes) throws IOException {
+ if (bytes.length < getCentralDirectoryHeader().getUncompressedSize()) {
+ throw new RuntimeException(
+ "Buffer to small while reading {}" + getCentralDirectoryHeader().getName());
+ }
+ try (InputStream is = new BufferedInputStream(open())) {
+ return ByteStreams.read(is, bytes, 0, bytes.length);
+ }
+ }
+
+ /**
* Obtains the type of entry.
*
* @return the type of entry