From 1b2845d74ba1619d3d72862a4ad490a531e88513 Mon Sep 17 00:00:00 2001 From: Google Date: Mon, 8 Feb 2021 10:42:11 -0800 Subject: [PATCH] Internal change PiperOrigin-RevId: 356300454 --- .../google/archivepatcher/applier/FileByFileDeltaApplier.java | 3 ++- .../java/com/google/archivepatcher/generator/TempBlob.java | 3 ++- .../archivepatcher/generator/bsdiff/RandomAccessObject.java | 3 ++- .../generator/bsdiff/RandomAccessObjectFactory.java | 4 ++-- .../java/com/google/archivepatcher/tools/FileByFileTool.java | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/applier/src/main/java/com/google/archivepatcher/applier/FileByFileDeltaApplier.java b/applier/src/main/java/com/google/archivepatcher/applier/FileByFileDeltaApplier.java index 77b91652..2568d32d 100644 --- a/applier/src/main/java/com/google/archivepatcher/applier/FileByFileDeltaApplier.java +++ b/applier/src/main/java/com/google/archivepatcher/applier/FileByFileDeltaApplier.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Files; /** Applies patches. */ public class FileByFileDeltaApplier extends DeltaApplier { @@ -68,7 +69,7 @@ public void applyDelta(ByteSource oldBlob, InputStream deltaIn, OutputStream new // will fail when it tries to create the file in a few more lines anyways. tempDir.mkdirs(); } - File tempFile = File.createTempFile("gfbfv1", "old", tempDir); + File tempFile = Files.createTempFile(tempDir.toPath(), "gfbfv1", "old").toFile(); try { applyDeltaInternal(oldBlob, tempFile, deltaIn, newBlobOut); } finally { diff --git a/generator/src/main/java/com/google/archivepatcher/generator/TempBlob.java b/generator/src/main/java/com/google/archivepatcher/generator/TempBlob.java index cf93f23e..dfd0ce0d 100644 --- a/generator/src/main/java/com/google/archivepatcher/generator/TempBlob.java +++ b/generator/src/main/java/com/google/archivepatcher/generator/TempBlob.java @@ -22,6 +22,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.file.Files; /** * A closeable container for a temp blob that deletes itself on {@link #close()}. This is convenient @@ -157,7 +158,7 @@ protected void finalize() { } private void createNewFile() throws IOException { - file = File.createTempFile("archive_patcher", "tmp"); + file = Files.createTempFile("archive_patcher", "tmp").toFile(); file.deleteOnExit(); } diff --git a/generator/src/main/java/com/google/archivepatcher/generator/bsdiff/RandomAccessObject.java b/generator/src/main/java/com/google/archivepatcher/generator/bsdiff/RandomAccessObject.java index d71998f3..658763a7 100644 --- a/generator/src/main/java/com/google/archivepatcher/generator/bsdiff/RandomAccessObject.java +++ b/generator/src/main/java/com/google/archivepatcher/generator/bsdiff/RandomAccessObject.java @@ -22,6 +22,7 @@ import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; +import java.nio.file.Files; // TODO: clean up the implementations, we only really need two and they can be in // separate files. @@ -389,7 +390,7 @@ public RandomAccessMmapObject(final String tempFileName, final String mode, long "RandomAccessMmapObject only supports file sizes up to " + "Integer.MAX_VALUE."); } - mFile = File.createTempFile(tempFileName, "temp"); + mFile = Files.createTempFile(tempFileName, "temp").toFile(); mFile.deleteOnExit(); mShouldDeleteFileOnRelease = true; diff --git a/generator/src/main/java/com/google/archivepatcher/generator/bsdiff/RandomAccessObjectFactory.java b/generator/src/main/java/com/google/archivepatcher/generator/bsdiff/RandomAccessObjectFactory.java index 738c1003..b97e76dc 100644 --- a/generator/src/main/java/com/google/archivepatcher/generator/bsdiff/RandomAccessObjectFactory.java +++ b/generator/src/main/java/com/google/archivepatcher/generator/bsdiff/RandomAccessObjectFactory.java @@ -17,9 +17,9 @@ import com.google.archivepatcher.generator.bsdiff.RandomAccessObject.RandomAccessByteArrayObject; import com.google.archivepatcher.generator.bsdiff.RandomAccessObject.RandomAccessFileObject; import com.google.archivepatcher.generator.bsdiff.RandomAccessObject.RandomAccessMmapObject; -import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import java.nio.file.Files; /** * A factory for creating instances of {@link RandomAccessObject}. BsDiff needs to store some @@ -59,7 +59,7 @@ public RandomAccessFileObjectFactory(String mode) { @Override public RandomAccessObject create(int size) throws IOException { return new RandomAccessObject.RandomAccessFileObject( - File.createTempFile(FILE_NAME_PREFIX, "temp"), mMode, true); + Files.createTempFile(FILE_NAME_PREFIX, "temp").toFile(), mMode, true); } } diff --git a/tools/src/main/java/com/google/archivepatcher/tools/FileByFileTool.java b/tools/src/main/java/com/google/archivepatcher/tools/FileByFileTool.java index 914d9faf..6086d5a3 100644 --- a/tools/src/main/java/com/google/archivepatcher/tools/FileByFileTool.java +++ b/tools/src/main/java/com/google/archivepatcher/tools/FileByFileTool.java @@ -26,6 +26,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -225,7 +226,7 @@ public static void generatePatch( */ public static void applyPatch(File oldFile, File patchFile, File newFile) throws IOException { // Figure out temp directory - File tempFile = File.createTempFile("fbftool", "tmp"); + File tempFile = Files.createTempFile("fbftool", "tmp").toFile(); File tempDir = tempFile.getParentFile(); tempFile.delete(); FileByFileDeltaApplier applier = new FileByFileDeltaApplier(tempDir);