diff --git a/src/test/java/com/aliyun/oss/common/utils/AuthUtilTest.java b/src/test/java/com/aliyun/oss/common/utils/AuthUtilTest.java index ea32014c..72dda518 100644 --- a/src/test/java/com/aliyun/oss/common/utils/AuthUtilTest.java +++ b/src/test/java/com/aliyun/oss/common/utils/AuthUtilTest.java @@ -27,6 +27,7 @@ import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.file.Files; import static com.aliyun.oss.common.utils.AuthUtils.loadPrivateKeyFromFile; import static com.aliyun.oss.common.utils.AuthUtils.loadPublicKeyFromFile; @@ -78,7 +79,7 @@ public void testLoadPrivateKeyFromFile() { public void testLoadNonRsaPrivateKeyFromFile() { File file = null; try { - file = File.createTempFile("test-private-key", ".pem"); + file = Files.createTempFile("test-private-key", ".pem").toFile(); file.deleteOnExit(); String privateKeyContent = "-----BEGIN PRIVATE KEY-----\n" + "abc\n" + diff --git a/src/test/java/com/aliyun/oss/common/utils/IniEditorTest.java b/src/test/java/com/aliyun/oss/common/utils/IniEditorTest.java index 8066ece0..64ab3b6a 100644 --- a/src/test/java/com/aliyun/oss/common/utils/IniEditorTest.java +++ b/src/test/java/com/aliyun/oss/common/utils/IniEditorTest.java @@ -21,6 +21,7 @@ import junit.framework.*; import java.io.*; +import java.nio.file.Files; import java.util.*; public class IniEditorTest extends TestCase { @@ -307,7 +308,7 @@ public void testSave() throws IOException { i.set("test", "hallo", "velo"); i.addComment("test", "english"); i.set("test", "hello", "bike"); - File f = File.createTempFile("test", null); + File f = Files.createTempFile("test", null).toFile(); // with output stream i.save(new FileOutputStream(f)); Object[] saved = fileToStrings(f); @@ -331,7 +332,7 @@ public void testSaveLoadCharset() throws IOException { IniEditor i = new IniEditor("cšmmšn"); i.addSection("tŽst"); i.set("tŽst", "h‰llo", "vel›"); - File f = File.createTempFile("test", null); + File f = Files.createTempFile("test", null).toFile(); i.save(new OutputStreamWriter(new FileOutputStream(f), charsetName)); i = new IniEditor("cšmmšn"); i.load(new InputStreamReader(new FileInputStream(f), charsetName)); @@ -345,7 +346,7 @@ public void testLoadClosingStream() throws IOException { IniEditor i = new IniEditor(); i.addSection("test"); i.set("test", "hallo", "velo"); - File f = File.createTempFile("test", null); + File f = Files.createTempFile("test", null).toFile(); i.save(f.toString()); i = new IniEditor(); i.load(f); @@ -384,7 +385,7 @@ public void testSetOptionFormat() throws IOException { i.setOptionFormatString("%s%s%s"); i.addSection("test"); i.set("test", "hallo", "velo"); - File f = File.createTempFile("test", null); + File f = Files.createTempFile("test", null).toFile(); i.save(new FileOutputStream(f)); Object[] saved = fileToStrings(f); assertEquals("hallo=velo", saved[1]); diff --git a/src/test/java/com/aliyun/oss/common/utils/IniSectionTest.java b/src/test/java/com/aliyun/oss/common/utils/IniSectionTest.java index 823a284d..bba8dc55 100644 --- a/src/test/java/com/aliyun/oss/common/utils/IniSectionTest.java +++ b/src/test/java/com/aliyun/oss/common/utils/IniSectionTest.java @@ -21,6 +21,7 @@ import junit.framework.*; import java.io.*; +import java.nio.file.Files; import java.util.*; public class IniSectionTest extends TestCase { @@ -150,7 +151,7 @@ public void testSave() throws IOException { s.set("hallo", "velo"); s.addComment("english"); s.set("hello", "bike"); - File f = File.createTempFile("test", null); + File f = Files.createTempFile("test", null).toFile(); s.save(new PrintWriter(new FileOutputStream(f))); Object[] saved = fileToStrings(f); assertTrue(Arrays.equals(expected, saved)); @@ -202,7 +203,7 @@ public void testSetOptionFormat() throws IOException { IniEditor.Section s = new IniEditor.Section("test"); s.setOptionFormatString(formats[i]); s.set("hallo", "velo"); - File f = File.createTempFile("test", null); + File f = Files.createTempFile("test", null).toFile(); s.save(new PrintWriter(new FileOutputStream(f))); Object[] saved = fileToStrings(f); assertEquals(expected[i], saved[0]); @@ -231,7 +232,7 @@ private static Object[] fileToStrings(File f) throws IOException { } private static File toTempFile(String text) throws IOException { - File temp = File.createTempFile("inieditortest", null); + File temp = Files.createTempFile("inieditortest", null).toFile(); FileWriter fw = new FileWriter(temp); fw.write(text); fw.close(); diff --git a/src/test/java/com/aliyun/oss/integrationtests/TestBase.java b/src/test/java/com/aliyun/oss/integrationtests/TestBase.java index fa1e1a86..aaacced1 100644 --- a/src/test/java/com/aliyun/oss/integrationtests/TestBase.java +++ b/src/test/java/com/aliyun/oss/integrationtests/TestBase.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -395,7 +396,7 @@ public static boolean compareFileWithRange(String fileNameLeft, long start, long } public static File createSampleFile(String fileName, long size) throws IOException { - File file = File.createTempFile(fileName, ".txt"); + File file = Files.createTempFile(fileName, ".txt").toFile(); file.deleteOnExit(); String context = "abcdefghijklmnopqrstuvwxyz0123456789011234567890\n"; diff --git a/src/test/java/com/aliyun/oss/integrationtests/UploadPartFromFileTest.java b/src/test/java/com/aliyun/oss/integrationtests/UploadPartFromFileTest.java index 4d4e3826..713cf577 100644 --- a/src/test/java/com/aliyun/oss/integrationtests/UploadPartFromFileTest.java +++ b/src/test/java/com/aliyun/oss/integrationtests/UploadPartFromFileTest.java @@ -26,6 +26,7 @@ import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; @@ -138,7 +139,7 @@ public void run() { } private File createSampleFile(String fileName, long size) throws IOException { - File file = File.createTempFile(fileName, ".txt"); + File file = Files.createTempFile(fileName, ".txt").toFile(); file.deleteOnExit(); String context = "abcdefghijklmnopqrstuvwxyz0123456789011234567890\n";