Skip to content

Commit

Permalink
Buffer the file output stream
Browse files Browse the repository at this point in the history
Also, removed the file locking which had no effect.

Bug: 11895788
Change-Id: I8b520fff9496f289eba88690b3b583f9c43b932c
  • Loading branch information
Maurice Chu committed Nov 28, 2013
1 parent a0c1a85 commit a159fd5
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions library/src/android/support/multidex/MultiDexExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import android.content.pm.ApplicationInfo;
import android.util.Log;

import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.FileLock;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
Expand All @@ -52,7 +52,6 @@ final class MultiDexExtractor {
private static final String EXTRACTED_NAME_EXT = ".classes";
private static final String EXTRACTED_SUFFIX = ".zip";
private static final int MAX_EXTRACT_ATTEMPTS = 3;
private static final String LOCK_FILENAME = "renamelock";

private static final int BUFFER_SIZE = 0x4000;

Expand Down Expand Up @@ -168,7 +167,7 @@ private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo,
extractTo.getParentFile());
Log.i(TAG, "Extracting " + tmp.getPath());
try {
out = new ZipOutputStream(new FileOutputStream(tmp));
out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tmp)));
try {
ZipEntry classesDex = new ZipEntry("classes.dex");
// keep zip entry time since it is the criteria used by Dalvik
Expand All @@ -181,6 +180,7 @@ private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo,
out.write(buffer, 0, length);
length = in.read(buffer);
}
out.closeEntry();
} finally {
out.close();
}
Expand All @@ -189,21 +189,9 @@ private static void extract(ZipFile apk, ZipEntry dexFile, File extractTo,
" This may cause problems with later updates of the apk.");
}
Log.i(TAG, "Renaming to " + extractTo.getPath());
File lockFile = new File(extractTo.getParentFile(), LOCK_FILENAME);
// Grab the file lock.
FileOutputStream lockFileOutputStream = new FileOutputStream(lockFile);
FileLock lockFileLock = lockFileOutputStream.getChannel().lock();
try {
if (!extractTo.exists()) {
if (!tmp.renameTo(extractTo)) {
throw new IOException("Failed to rename \"" + tmp.getAbsolutePath() +
"\" to \"" + extractTo.getAbsolutePath() + "\"");
}
}
} finally {
// Release the lock file.
lockFileLock.release();
lockFileOutputStream.close();
if (!tmp.renameTo(extractTo)) {
throw new IOException("Failed to rename \"" + tmp.getAbsolutePath() +
"\" to \"" + extractTo.getAbsolutePath() + "\"");
}
} finally {
closeQuietly(in);
Expand Down

0 comments on commit a159fd5

Please sign in to comment.