diff --git a/java/com/facebook/soloader/ExoSoSource.java b/java/com/facebook/soloader/ExoSoSource.java index 04fe0f5..be0ac63 100644 --- a/java/com/facebook/soloader/ExoSoSource.java +++ b/java/com/facebook/soloader/ExoSoSource.java @@ -137,7 +137,7 @@ public InputDso next() throws IOException { FileDso fileDso = mDsos[mCurrentDso++]; FileInputStream dsoFile = new FileInputStream(fileDso.backingFile); try { - InputDso ret = new InputDsoStream(fileDso, dsoFile); + InputDso ret = new InputDso(fileDso, dsoFile); dsoFile = null; // Ownership transferred return ret; } finally { diff --git a/java/com/facebook/soloader/ExtractFromZipSoSource.java b/java/com/facebook/soloader/ExtractFromZipSoSource.java index f421c1a..93682f4 100644 --- a/java/com/facebook/soloader/ExtractFromZipSoSource.java +++ b/java/com/facebook/soloader/ExtractFromZipSoSource.java @@ -171,7 +171,7 @@ public InputDso next() throws IOException { ZipDso zipDso = mDsos[mCurrentDso++]; InputStream is = mZipFile.getInputStream(zipDso.backingEntry); try { - InputDso ret = new InputDsoStream(zipDso, is); + InputDso ret = new InputDso(zipDso, is); is = null; // Transfer ownership return ret; } finally { diff --git a/java/com/facebook/soloader/SysUtil.java b/java/com/facebook/soloader/SysUtil.java index 5fd1672..f755ae9 100644 --- a/java/com/facebook/soloader/SysUtil.java +++ b/java/com/facebook/soloader/SysUtil.java @@ -29,7 +29,6 @@ import android.system.OsConstants; import android.text.TextUtils; import dalvik.system.BaseDexClassLoader; -import java.io.DataOutput; import java.io.File; import java.io.FileDescriptor; import java.io.FileNotFoundException; @@ -303,7 +302,7 @@ public static void mkdirOrThrow(File dir) throws IOException { * @param buffer IO buffer to use * @return Number of bytes actually copied */ - static int copyBytes(DataOutput os, InputStream is, int byteLimit, byte[] buffer) + static int copyBytes(RandomAccessFile os, InputStream is, int byteLimit, byte[] buffer) throws IOException { // Yes, this method is exactly the same as the above, just with a different type for `os'. int bytesCopied = 0; diff --git a/java/com/facebook/soloader/UnpackingSoSource.java b/java/com/facebook/soloader/UnpackingSoSource.java index fbfdf1f..3c37bf0 100644 --- a/java/com/facebook/soloader/UnpackingSoSource.java +++ b/java/com/facebook/soloader/UnpackingSoSource.java @@ -19,7 +19,6 @@ import android.content.Context; import android.os.Parcel; import java.io.Closeable; -import java.io.DataOutput; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -100,53 +99,23 @@ public Dso(String name, String hash) { } } - protected static interface InputDso extends Closeable { - - public void write(DataOutput out, byte[] ioBuffer) throws IOException; - - public Dso getDso(); - - public String getFileName(); - - public int available() throws IOException; - - public InputStream getStream(); - }; - - public static class InputDsoStream implements InputDso { + protected static final class InputDso implements Closeable { private final Dso dso; private final InputStream content; - public InputDsoStream(Dso dso, InputStream content) { + public InputDso(Dso dso, InputStream content) { this.dso = dso; this.content = content; } - @Override - public void write(DataOutput out, byte[] ioBuffer) throws IOException { - SysUtil.copyBytes(out, content, Integer.MAX_VALUE, ioBuffer); - } - - @Override public Dso getDso() { return dso; } - @Override - public String getFileName() { - return dso.name; - } - - @Override public int available() throws IOException { return content.available(); } - @Override - public InputStream getStream() { - return content; - } - @Override public void close() throws IOException { content.close(); @@ -220,8 +189,7 @@ private void deleteUnmentionedFiles(Dso[] dsos) throws IOException { private void extractDso(InputDso iDso, byte[] ioBuffer) throws IOException { LogUtil.i(TAG, "extracting DSO " + iDso.getDso().name); - File dsoFileName = new File(soDirectory, iDso.getFileName()); - + File dsoFileName = new File(soDirectory, iDso.getDso().name); if (dsoFileName.exists() && !dsoFileName.setWritable(true)) { throw new IOException( "error adding write permission to: " @@ -247,7 +215,7 @@ private void extractDso(InputDso iDso, byte[] ioBuffer) throws IOException { if (sizeHint > 1) { SysUtil.fallocateIfSupported(dsoFile.getFD(), sizeHint); } - iDso.write(dsoFile, ioBuffer); + SysUtil.copyBytes(dsoFile, iDso.content, Integer.MAX_VALUE, ioBuffer); dsoFile.setLength(dsoFile.getFilePointer()); // In case we shortened file if (!dsoFileName.setExecutable(true /* allow exec... */, false /* ...for everyone */)) { throw new IOException("cannot make file executable: " + dsoFileName);