summaryrefslogtreecommitdiff
path: root/src/main/java/com/android/apkzlib/zip/StoredEntry.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/android/apkzlib/zip/StoredEntry.java')
-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