Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright 2010 Ning, Inc.
*
Expand Down Expand Up @@ -35,6 +36,7 @@
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
import java.security.SecureRandom;
import java.util.List;
import java.util.Random;
import java.util.Set;
Expand Down Expand Up @@ -95,7 +97,7 @@ public static MultipartBody newMultipartBody(List<Part> parts, FluentCaseInsensi
}

private static byte[] generateMultipartBoundary() {
Random rand = new Random();
Random rand = new SecureRandom();
byte[] bytes = new byte[rand.nextInt(11) + 30]; // a random size from 30 to 40
for (int i = 0; i < bytes.length; i++) {
bytes[i] = MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
*
Expand Down Expand Up @@ -252,6 +253,13 @@ public String getProtocolText() {

private Document readXMLResponse(InputStream stream) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
final String FEATURE = "http://apache.org/xml/features/disallow-doctype-decl";
try {
factory.setFeature(FEATURE, true);
} catch (ParserConfigurationException e) {
throw new IllegalStateException("ParserConfigurationException was thrown. The feature '" + FEATURE +
"' is not supported by your XML processor.", e);
}
Document document = null;
try {
document = factory.newDocumentBuilder().parse(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -119,7 +120,7 @@ public String getTargetUrl() {
public static File createTempFile(byte[] pattern, int repeat) throws IOException {
TMP.mkdirs();
TMP.deleteOnExit();
File tmpFile = File.createTempFile("tmpfile-", ".data", TMP);
final File tmpFile = Files.createTempFile(TMP.toPath(), "tmpfile-", ".data").toFile();
write(pattern, repeat, tmpFile);

return tmpFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.util.UUID;

public abstract class FilePartLargeFileTest extends AbstractBasicTest {
Expand Down Expand Up @@ -126,7 +127,7 @@ public boolean handle(Request request, org.eclipse.jetty.server.Response respons
public static File createTempFile(byte[] pattern, int repeat) throws IOException {
TMP.mkdirs();
TMP.deleteOnExit();
File tmpFile = File.createTempFile("tmpfile-", ".data", TMP);
final File tmpFile = Files.createTempFile(TMP.toPath(), "tmpfile-", ".data").toFile();
tmpFile.deleteOnExit();
write(pattern, repeat, tmpFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -185,7 +186,7 @@ public void testSendingSmallFilesAndByteArray() throws IOException, InterruptedE
gzipped.add(false);

boolean tmpFileCreated = false;
File tmpFile = File.createTempFile("textbytearray", ".txt");
final File tmpFile = Files.createTempFile("textbytearray", ".txt").toFile();
try (FileOutputStream os = new FileOutputStream(tmpFile)) {
IOUtils.write(expectedContents.getBytes("UTF-8"), os);
tmpFileCreated = true;
Expand Down Expand Up @@ -417,7 +418,9 @@ public void service(HttpServletRequest request, HttpServletResponse response) th
// Process the input stream
OutputStream os = null;
try {
File tmpFile = File.createTempFile(UUID.randomUUID().toString() + "_MockUploadServlet", ".tmp");
final File tmpFile =
Files.createTempFile(UUID.randomUUID().toString() + "_MockUploadServlet",
".tmp").toFile();
tmpFile.deleteOnExit();
os = new FileOutputStream(tmpFile);
byte[] buffer = new byte[4096];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.UUID;

/**
Expand Down Expand Up @@ -115,7 +116,7 @@ public boolean handle(Request request, org.eclipse.jetty.server.Response respons
public static File createTempFile(byte[] pattern, int repeat) throws IOException {
TMP.mkdirs();
TMP.deleteOnExit();
File tmpFile = File.createTempFile("tmpfile-", ".data", TMP);
final File tmpFile = Files.createTempFile(TMP.toPath(), "tmpfile-", ".data").toFile();
tmpFile.deleteOnExit();
write(pattern, repeat, tmpFile);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved.
*
Expand Down Expand Up @@ -34,6 +35,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

Expand Down Expand Up @@ -118,7 +120,7 @@ public void testPutZeroBytesFileTest() throws Throwable {
SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setPooledConnectionIdleTimeout(100).setMaximumConnectionsTotal(50).setRequestTimeout(5 * 1000).setUrl(getTargetUrl() + "/testPutZeroBytesFileTest.txt").setHeader("Content-Type", "text/plain")
.build();
try {
File tmpfile = File.createTempFile("testPutZeroBytesFile", ".tmp");
final File tmpfile = Files.createTempFile("testPutZeroBytesFile", ".tmp").toFile();
tmpfile.deleteOnExit();

Future<Response> future = client.put(new FileBodyGenerator(tmpfile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -253,7 +254,7 @@ public String getTargetUrl() {
public static File createTempFile(byte[] pattern, int repeat) throws IOException {
TMP.mkdirs();
TMP.deleteOnExit();
File tmpFile = File.createTempFile("tmpfile-", ".data", TMP);
final File tmpFile = Files.createTempFile(TMP.toPath(), "tmpfile-", ".data").toFile();
write(pattern, repeat, tmpFile);

return tmpFile;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013-2014 Sonatype, Inc. All rights reserved.
*
Expand Down Expand Up @@ -27,6 +28,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -356,7 +358,7 @@ private static SSLEngineConfigurator createSSLConfig()


private void generateTempFile() throws IOException {
tempFile = File.createTempFile("feedable", null);
tempFile = Files.createTempFile("feedable", null).toFile();
int total = 0;
byte[] chunk = new byte[1024];
Random r = new Random(System.currentTimeMillis());
Expand Down