Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RESTEASY-3286] Use the new NIO file utilities to create temporary files #3409

Merged
merged 2 commits into from Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev
[RESTEASY-3286] Use the new file utilities to create temporary files …
…in tests.

https://issues.redhat.com/browse/RESTEASY-3286
Signed-off-by: James R. Perkins <jperkins@redhat.com>
  • Loading branch information
jamezp committed Feb 2, 2023
commit 807d7456f2137cde8ef7c316707211bf4e542d56
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.nio.file.Files;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
Expand Down Expand Up @@ -46,7 +47,7 @@ public Response io(@PathParam("size") long size) {
@Path("io/file-range/{size}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response fileRange(@PathParam("size") long size) throws IOException {
File file = File.createTempFile("empty-file", "");
File file = Files.createTempFile("empty-file", "").toFile();
file.deleteOnExit();
RandomAccessFile rFile = new RandomAccessFile(file, "rw");
rFile.setLength(size);
Expand Down
Expand Up @@ -5,6 +5,7 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -95,7 +96,7 @@ public void testDeploymentInfo() throws Exception {

@Test
public void testAddResourcePrefixPath() throws Exception {
File staticFile = File.createTempFile("tmp", "index.html");
File staticFile = Files.createTempFile("tmp", "index.html").toFile();
staticFile.deleteOnExit();
BufferedWriter writer = new BufferedWriter(new FileWriter(staticFile));
final String staticFileContent = "Hello static world!";
Expand Down
Expand Up @@ -4,6 +4,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.nio.file.Files;

import jakarta.activation.DataHandler;
import jakarta.activation.FileDataSource;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void testXOPGet() throws Exception {
*/
@Test
public void testXOPSend() throws Exception {
File tmpFile = File.createTempFile("pre", ".tmp");
File tmpFile = Files.createTempFile("pre", ".tmp").toFile();
tmpFile.deleteOnExit();
Writer writer = new FileWriter(tmpFile);
writer.write("testXOPSend");
Expand Down
Expand Up @@ -4,6 +4,7 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;

import jakarta.activation.DataHandler;
import jakarta.activation.DataSource;
Expand All @@ -28,7 +29,7 @@ public Response putFile(XOPMultipartProxyPutFileRequest putFileRequest) throws I

private XOPMultipartProxyGetFileResponse getResponse(String content) throws Exception {
XOPMultipartProxyGetFileResponse response = new XOPMultipartProxyGetFileResponse();
File out = File.createTempFile("tmp", ".txt");
File out = Files.createTempFile("tmp", ".txt").toFile();
out.deleteOnExit();
try (FileWriter writer = new FileWriter(out)) {
writer.write(content);
Expand Down
@@ -1,8 +1,9 @@
package org.jboss.resteasy.test.response.resource;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
Expand Down Expand Up @@ -50,34 +51,32 @@ public void deleteSmallFile() throws Exception {
}

private static File createFile() {
File file = null;
java.nio.file.Path file = null;
try {
file = File.createTempFile("tmp", "tmp");
FileOutputStream fos = new FileOutputStream(file);
for (int i = 0; i < 1000; i++) {
fos.write("hello".getBytes());
file = Files.createTempFile("tmp", "tmp");
try (BufferedWriter writer = Files.newBufferedWriter(file)) {
for (int i = 0; i < 1000; i++) {
writer.write("hello");
}
writer.write("1234");
}
fos.write("1234".getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
return file;
return file.toFile();
}

private static File createSmallFile() {
File smallfile = null;
java.nio.file.Path smallfile = null;
try {
smallfile = File.createTempFile("smalltmp", "tmp");
FileOutputStream fos = new FileOutputStream(smallfile);
fos.write("123456789".getBytes());
fos.flush();
fos.close();
smallfile = Files.createTempFile("smalltmp", "tmp");
try (BufferedWriter writer = Files.newBufferedWriter(smallfile)) {
writer.write("123456789");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return smallfile;
return smallfile.toFile();
}

}