Skip to content

Commit

Permalink
Remove unnecessary InputDsoStream abstraction
Browse files Browse the repository at this point in the history
Summary: As in the title, there's no need for the abstraction.

Reviewed By: danjin250

Differential Revision: D48096527

fbshipit-source-id: 348b9686e2b333067bd3e7a805afd915569c4a84
  • Loading branch information
adicatana authored and facebook-github-bot committed Aug 9, 2023
1 parent 7c95b02 commit 4ee5313
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 40 deletions.
2 changes: 1 addition & 1 deletion java/com/facebook/soloader/ExoSoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion java/com/facebook/soloader/ExtractFromZipSoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions java/com/facebook/soloader/SysUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 4 additions & 36 deletions java/com/facebook/soloader/UnpackingSoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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: "
Expand All @@ -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);
Expand Down

0 comments on commit 4ee5313

Please sign in to comment.