Skip to content

Commit 8886d47

Browse files
committed
Clean usage of commons-io where possible
Signed-off-by: Maxim Nesen <[email protected]>
1 parent ae07260 commit 8886d47

File tree

14 files changed

+71
-80
lines changed

14 files changed

+71
-80
lines changed

containers/jdk-http/pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2010, 2025 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at
@@ -33,12 +33,6 @@
3333
<description>JDK Http Container</description>
3434

3535
<dependencies>
36-
<dependency>
37-
<groupId>commons-io</groupId>
38-
<artifactId>commons-io</artifactId>
39-
<scope>test</scope>
40-
<version>${commons.io.version}</version>
41-
</dependency>
4236
<dependency>
4337
<groupId>org.hamcrest</groupId>
4438
<artifactId>hamcrest</artifactId>

containers/jdk-http/src/test/java/org/glassfish/jersey/jdkhttp/JdkHttpsServerTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -30,9 +30,9 @@
3030
import javax.net.ssl.SSLContext;
3131
import javax.net.ssl.SSLHandshakeException;
3232

33-
import org.apache.commons.io.IOUtils;
3433
import org.glassfish.jersey.SslConfigurator;
3534
import org.glassfish.jersey.internal.util.JdkVersion;
35+
import org.glassfish.jersey.message.internal.ReaderWriter;
3636
import org.glassfish.jersey.server.ResourceConfig;
3737

3838
import org.junit.jupiter.api.AfterEach;
@@ -195,9 +195,9 @@ private SSLContext getClientSslContext() throws IOException {
195195

196196

197197
final SslConfigurator sslConfigClient = SslConfigurator.newInstance()
198-
.trustStoreBytes(IOUtils.toByteArray(trustStore))
198+
.trustStoreBytes(ReaderWriter.readFromAsBytes(trustStore))
199199
.trustStorePassword(TRUSTSTORE_CLIENT_PWD)
200-
.keyStoreBytes(IOUtils.toByteArray(keyStore))
200+
.keyStoreBytes(ReaderWriter.readFromAsBytes(keyStore))
201201
.keyPassword(KEYSTORE_CLIENT_PWD);
202202

203203
return sslConfigClient.createSSLContext();
@@ -208,9 +208,9 @@ private SSLContext getServerSslContext() throws IOException {
208208
final InputStream keyStore = JdkHttpsServerTest.class.getResourceAsStream(KEYSTORE_SERVER_FILE);
209209

210210
final SslConfigurator sslConfigServer = SslConfigurator.newInstance()
211-
.keyStoreBytes(IOUtils.toByteArray(keyStore))
211+
.keyStoreBytes(ReaderWriter.readFromAsBytes(keyStore))
212212
.keyPassword(KEYSTORE_SERVER_PWD)
213-
.trustStoreBytes(IOUtils.toByteArray(trustStore))
213+
.trustStoreBytes(ReaderWriter.readFromAsBytes(trustStore))
214214
.trustStorePassword(TRUSTSTORE_SERVER_PWD);
215215

216216
return sslConfigServer.createSSLContext();

core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderWriter.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -160,11 +160,23 @@ public static String readFromAsString(Reader reader) throws IOException {
160160
}
161161
return sb.toString();
162162
}
163+
164+
/**
165+
* Read/convert stream to the byte array.
166+
*
167+
* @param in stream to be converted to the byte array
168+
* @return the byte array
169+
* @throws IOException if there is an error reading from the stream
170+
* @since 2.47
171+
*/
172+
public static byte[] readFromAsBytes(InputStream in) throws IOException {
173+
return readAllBytes(in);
174+
}
163175
/**
164-
* The maximum size of array to allocate.
176+
* The maximum size of an array to allocate.
165177
* Some VMs reserve some header words in an array.
166178
* Attempts to allocate larger arrays may result in
167-
* OutOfMemoryError: Requested array size exceeds VM limit
179+
* OutOfMemoryError: Requested array size exceeds the VM limit
168180
*/
169181
private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8;
170182

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,6 @@
22192219
<!--required for spring (ext) modules integration -->
22202220
<aspectj.weaver.version>1.9.22.1</aspectj.weaver.version>
22212221
<!-- <bnd.plugin.version>2.3.6</bnd.plugin.version>-->
2222-
<commons.io.version>2.19.0</commons.io.version>
22232222
<!-- <commons-lang3.version>3.3.2</commons-lang3.version>-->
22242223
<commons.logging.version>1.3.5</commons.logging.version>
22252224
<fasterxml.classmate.version>1.7.0</fasterxml.classmate.version>

test-framework/maven/container-runner-maven-plugin/pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2015, 2025 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at
@@ -134,10 +134,6 @@
134134
<groupId>org.codehaus.plexus</groupId>
135135
<artifactId>plexus-interpolation</artifactId>
136136
</exclusion>
137-
<exclusion>
138-
<groupId>commons-io</groupId>
139-
<artifactId>commons-io</artifactId>
140-
</exclusion>
141137
<exclusion>
142138
<groupId>org.apache.maven</groupId>
143139
<artifactId>maven-model</artifactId>

test-framework/maven/custom-enforcer-rules/pom.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2015, 2025 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at
@@ -48,10 +48,6 @@
4848
<groupId>org.codehaus.plexus</groupId>
4949
<artifactId>plexus-utils</artifactId>
5050
</exclusion>
51-
<exclusion>
52-
<groupId>commons-io</groupId>
53-
<artifactId>commons-io</artifactId>
54-
</exclusion>
5551
<exclusion>
5652
<groupId>org.apache.maven</groupId>
5753
<artifactId>maven-core</artifactId>
@@ -63,12 +59,6 @@
6359
</exclusions>
6460
</dependency>
6561

66-
<dependency>
67-
<groupId>commons-io</groupId>
68-
<artifactId>commons-io</artifactId>
69-
<version>${commons.io.version}</version>
70-
</dependency>
71-
7262
<dependency>
7363
<groupId>org.junit.jupiter</groupId>
7464
<artifactId>junit-jupiter</artifactId>

test-framework/maven/custom-enforcer-rules/src/main/java/org/glassfish/jersey/test/maven/rule/FilePatternDoesNotExistRule.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,17 +17,19 @@
1717
package org.glassfish.jersey.test.maven.rule;
1818

1919
import java.io.File;
20-
import java.io.FileFilter;
20+
import java.io.IOException;
21+
import java.nio.file.DirectoryStream;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
2124
import java.util.Arrays;
2225
import java.util.Set;
2326
import java.util.TreeSet;
2427

25-
import org.apache.commons.io.filefilter.WildcardFileFilter;
2628
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
2729
import org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule;
2830

2931
/**
30-
* Maven enforcer rule to enforce that given set of files does not exist.<br/>
32+
* Maven enforcer rule to enforce that a given set of files does not exist.<br/>
3133
* This rule is similar to apache {@code requireFilesDontExist} with a support for wildcards.
3234
*
3335
* @author Stepan Vavra
@@ -55,8 +57,13 @@ public void execute()
5557
}
5658

5759
final Set<File> matchedFiles = new TreeSet<>();
58-
for (File matchedFile : dir.listFiles((FileFilter) new WildcardFileFilter(fileItselfPattern))) {
59-
matchedFiles.add(matchedFile);
60+
try {
61+
final DirectoryStream<Path> directoryStream
62+
= Files.newDirectoryStream(dir.toPath(), fileItselfPattern);
63+
directoryStream.forEach(path -> matchedFiles.add(path.toFile()));
64+
directoryStream.close();
65+
} catch (IOException e) {
66+
throw new EnforcerRuleException(e);
6067
}
6168

6269
if (!matchedFiles.isEmpty()) {

tests/e2e-client/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved.
4+
Copyright (c) 2017, 2025 Oracle and/or its affiliates. All rights reserved.
55
66
This program and the accompanying materials are made available under the
77
terms of the Eclipse Public License v. 2.0, which is available at
@@ -225,11 +225,6 @@
225225
<scope>test</scope>
226226
</dependency>
227227

228-
<dependency>
229-
<groupId>commons-io</groupId>
230-
<artifactId>commons-io</artifactId>
231-
<version>${commons.io.version}</version>
232-
</dependency>
233228
</dependencies>
234229

235230
<profiles>

tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/connector/ssl/AbstractConnectorServerTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -18,7 +18,6 @@
1818

1919
import java.io.IOException;
2020
import java.io.InputStream;
21-
import java.util.Arrays;
2221
import java.util.stream.Stream;
2322

2423
import javax.net.ssl.SSLContext;
@@ -31,11 +30,10 @@
3130
import org.glassfish.jersey.grizzly.connector.GrizzlyConnectorProvider;
3231
import org.glassfish.jersey.jetty.connector.JettyConnectorProvider;
3332

33+
import org.glassfish.jersey.message.internal.ReaderWriter;
3434
import org.junit.jupiter.api.AfterEach;
3535
import org.junit.jupiter.api.BeforeEach;
3636

37-
import org.apache.commons.io.IOUtils;
38-
3937
/**
4038
* SSL connector hostname verification tests.
4139
*
@@ -92,9 +90,9 @@ protected SSLContext getSslContext() throws IOException {
9290
final InputStream trustStore = SslConnectorConfigurationTest.class.getResourceAsStream(clientTrustStore());
9391
final InputStream keyStore = SslConnectorConfigurationTest.class.getResourceAsStream(CLIENT_KEY_STORE);
9492
return SslConfigurator.newInstance()
95-
.trustStoreBytes(IOUtils.toByteArray(trustStore))
93+
.trustStoreBytes(ReaderWriter.readFromAsBytes(trustStore))
9694
.trustStorePassword("asdfgh")
97-
.keyStoreBytes(IOUtils.toByteArray(keyStore))
95+
.keyStoreBytes(ReaderWriter.readFromAsBytes(keyStore))
9896
.keyPassword("asdfgh")
9997
.createSSLContext();
10098
}

tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/connector/ssl/Server.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,9 +23,9 @@
2323

2424
import javax.ws.rs.core.UriBuilder;
2525

26-
import org.apache.commons.io.IOUtils;
2726
import org.glassfish.jersey.logging.LoggingFeature;
2827
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
28+
import org.glassfish.jersey.message.internal.ReaderWriter;
2929
import org.glassfish.jersey.server.ResourceConfig;
3030

3131
import org.glassfish.grizzly.http.server.HttpServer;
@@ -86,9 +86,9 @@ public static Server start(String keystore) throws IOException {
8686
SSLContextConfigurator sslContext = new SSLContextConfigurator();
8787

8888
// set up security context
89-
sslContext.setKeyStoreBytes(IOUtils.toByteArray(keyStore)); // contains server key pair
89+
sslContext.setKeyStoreBytes(ReaderWriter.readFromAsBytes(keyStore)); // contains server key pair
9090
sslContext.setKeyStorePass("asdfgh");
91-
sslContext.setTrustStoreBytes(IOUtils.toByteArray(trustStore)); // contains client certificate
91+
sslContext.setTrustStoreBytes(ReaderWriter.readFromAsBytes(trustStore)); // contains client certificate
9292
sslContext.setTrustStorePass("asdfgh");
9393

9494
ResourceConfig rc = new ResourceConfig();

0 commit comments

Comments
 (0)