Skip to content

Commit

Permalink
Replace File.createTempFile with java.nio.file.Files.createTempFile
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Nioche <julien@digitalpebble.com>
  • Loading branch information
jnioche committed Sep 19, 2023
1 parent a837e6a commit b778125
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -131,7 +132,7 @@ private void setDefaults() {

private File loadExample(File file, String example) {
try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(example)) {
file = File.createTempFile("pmml-example", ".tmp");
file = Files.createTempFile("pmml-example", ".tmp").toFile();
IOUtils.copy(stream, new FileOutputStream(file));
} catch (IOException e) {
throw new RuntimeException("Error loading example " + example, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void uploadArtifacts() throws Exception {
}

private File createTemporaryDummyFile() throws IOException {
File tempFile = File.createTempFile("tempfile", ".tmp");
File tempFile = java.nio.file.Files.createTempFile("tempfile", ".tmp").toFile();

BufferedWriter bw = new BufferedWriter(new FileWriter(tempFile));
bw.write("This is the temporary file content");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void testgetSSLFilesFromConfMultipleComma() {

@Test
public void testpopulateCredentials() throws Exception {
File temp = File.createTempFile("tmp-autossl-test", ".txt");
File temp = Files.createTempFile("tmp-autossl-test", ".txt").toFile();
temp.deleteOnExit();
List<String> lines = Arrays.asList("The first line", "The second line");
Files.write(temp.toPath(), lines, StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import org.apache.storm.Config;
Expand Down Expand Up @@ -175,7 +176,7 @@ private boolean isPermitted(IAuthorizer authorizer, ReqContext context, String o
public void test_read_acl_no_values() throws IOException {
DRPCSimpleACLAuthorizer authorizer = new DRPCSimpleACLAuthorizer();

File tempFile = File.createTempFile("drpcacl", ".yaml");
File tempFile = Files.createTempFile("drpcacl", ".yaml").toFile();
tempFile.deleteOnExit();
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
writer.write("drpc.authorizer.acl:");
Expand All @@ -197,7 +198,7 @@ public void test_read_acl_no_values() throws IOException {
public void test_read_acl_empty_file() throws IOException {
DRPCSimpleACLAuthorizer authorizer = new DRPCSimpleACLAuthorizer();

File tempFile = File.createTempFile("drpcacl", ".yaml");
File tempFile = Files.createTempFile("drpcacl", ".yaml").toFile();
tempFile.deleteOnExit();

authorizer.prepare(ImmutableMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -96,7 +97,7 @@ private static File createExtraPropertiesFile(Map<String, Object> jsonConf) {
}
if (!extraProperties.isEmpty()) {
try {
file = File.createTempFile("kafka-consumer-extra", "props");
file = Files.createTempFile("kafka-consumer-extra", "props").toFile();
file.deleteOnExit();
Properties properties = new Properties();
properties.putAll(extraProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import org.apache.storm.Config;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void testInvalidConfig() {
@Test
public void testMalformedYaml() throws Exception {

File temp = File.createTempFile("FileLoader", ".yaml");
File temp = Files.createTempFile("FileLoader", ".yaml").toFile();
temp.deleteOnExit();

FileWriter fw = new FileWriter(temp);
Expand All @@ -69,7 +70,7 @@ public void testMalformedYaml() throws Exception {
@Test
public void testValidFile() throws Exception {

File temp = File.createTempFile("FileLoader", ".yaml");
File temp = Files.createTempFile("FileLoader", ".yaml").toFile();
temp.deleteOnExit();

Map<String, Integer> testMap = new HashMap<>();
Expand Down

0 comments on commit b778125

Please sign in to comment.