aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorBen Gruver <bgruv@google.com>2013-09-08 15:30:58 -0700
committerBen Gruver <bgruv@google.com>2013-09-08 15:30:58 -0700
commit99b46173c5294d186ccf2e647b86346a22b247c8 (patch)
tree4982034a593c832ebfd569cd5029db8a468cf5b9 /util
parent160449b83a0a19244ae27d0c9acf539c0c730be5 (diff)
downloadsmali-99b46173c5294d186ccf2e647b86346a22b247c8.tar.gz
Generify the IO requirements for writing a dex file
The DexWriter implementations now write to a generic "DexDataStore", instead of writing directly to a file. Also, writing of the DebugItems and CodeItems are linked, with the code items being written to a temporary location, and then the entire code item section is written as a batch after the debug item section.
Diffstat (limited to 'util')
-rw-r--r--util/src/main/java/org/jf/util/RandomAccessFileInputStream.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/util/src/main/java/org/jf/util/RandomAccessFileInputStream.java b/util/src/main/java/org/jf/util/RandomAccessFileInputStream.java
new file mode 100644
index 00000000..4c62aed7
--- /dev/null
+++ b/util/src/main/java/org/jf/util/RandomAccessFileInputStream.java
@@ -0,0 +1,50 @@
+package org.jf.util;
+
+import javax.annotation.Nonnull;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+
+public class RandomAccessFileInputStream extends InputStream {
+ private int filePosition;
+ @Nonnull private final RandomAccessFile raf;
+
+ public RandomAccessFileInputStream(@Nonnull RandomAccessFile raf, int filePosition) {
+ this.filePosition = filePosition;
+ this.raf = raf;
+ }
+
+ @Override public int read() throws IOException {
+ raf.seek(filePosition);
+ filePosition++;
+ return raf.read();
+ }
+
+ @Override public int read(byte[] bytes) throws IOException {
+ raf.seek(filePosition);
+ int bytesRead = raf.read(bytes);
+ filePosition += bytesRead;
+ return bytesRead;
+ }
+
+ @Override public int read(byte[] bytes, int offset, int length) throws IOException {
+ raf.seek(filePosition);
+ int bytesRead = raf.read(bytes, offset, length);
+ filePosition += bytesRead;
+ return bytesRead;
+ }
+
+ @Override public long skip(long l) throws IOException {
+ int skipBytes = Math.min((int)l, available());
+ filePosition += skipBytes;
+ return skipBytes;
+ }
+
+ @Override public int available() throws IOException {
+ return (int)raf.length() - filePosition;
+ }
+
+ @Override public boolean markSupported() {
+ return false;
+ }
+}