Skip to content

Commit

Permalink
Resolved Commons IO deprecation warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
essiembre committed Aug 19, 2023
1 parent e3296c9 commit 573d513
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/norconex/commons/lang/url/URLStreamer.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static InputStream stream(
LOG.debug("Streaming with proxy: {}:{}",
proxy.getHostName(), proxy.getPort());
}
Proxy p = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
var p = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
proxy.getHostName(), proxy.getPort()));
//Authenticator.
conn = new URL(url).openConnection(p);
Expand Down Expand Up @@ -398,10 +398,12 @@ public static String streamToString(HttpURL url) {
private static InputStream responseInputStream(
URLConnection conn) throws IOException {
conn.connect();
return new AutoCloseInputStream(conn.getInputStream());
return AutoCloseInputStream.builder()
.setInputStream(conn.getInputStream())
.get();
}
private static String base64BasicAuth(String username, String password) {
String userpass = username + ':' + password;
var userpass = username + ':' + password;
return "Basic "
+ DatatypeConverter.printBase64Binary(userpass.getBytes());
}
Expand Down
35 changes: 19 additions & 16 deletions src/test/java/com/norconex/commons/lang/exec/ExecUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class ExecUtilTest {

@Test
void testWatchProcessProcess() throws IOException {
Process process = Runtime.getRuntime().exec("java --help");
var process = Runtime.getRuntime().exec("java --help");
assertThat(ExecUtil.watchProcess(process)).isZero();
}

@Test
void testWatchProcessProcessInputStreamListener() throws IOException {
StringBuilder stdout = new StringBuilder();
Process process = Runtime.getRuntime().exec("java -help");
var stdout = new StringBuilder();
var process = Runtime.getRuntime().exec("java -help");
assertThat(ExecUtil.watchProcess(process,
(t, b, l) -> stdout.append(new String(b)))).isZero();
assertThat(stdout)
Expand All @@ -46,9 +46,9 @@ void testWatchProcessProcessInputStreamListener() throws IOException {

@Test
void testWatchProcessProcessInputStreamListenerArray() throws IOException {
StringBuilder stdout1 = new StringBuilder();
StringBuilder stdout2 = new StringBuilder();
Process process = Runtime.getRuntime().exec("java -help");
var stdout1 = new StringBuilder();
var stdout2 = new StringBuilder();
var process = Runtime.getRuntime().exec("java -help");
assertThat(ExecUtil.watchProcess(
process,
new InputStreamListener[] {
Expand All @@ -65,9 +65,9 @@ void testWatchProcessProcessInputStreamListenerArray() throws IOException {
@Test
void testWatchProcessProcessInputStreamListenerInputStreamListener()
throws IOException {
StringBuilder stdout = new StringBuilder();
StringBuilder stderr = new StringBuilder();
Process process = Runtime.getRuntime().exec("java --help");
var stdout = new StringBuilder();
var stderr = new StringBuilder();
var process = Runtime.getRuntime().exec("java --help");
assertThat(ExecUtil.watchProcess(
process,
(t, b, l) -> stdout.append(new String(b)),
Expand All @@ -92,9 +92,9 @@ void testWatchProcessProcessInputStreamListenerInputStreamListener()
@Test
void testWatchProcessAsyncProcessInputStreamListenerInputStreamListener()
throws IOException {
StringBuilder stdout = new StringBuilder();
StringBuilder stderr = new StringBuilder();
Process process = Runtime.getRuntime().exec("java --help");
var stdout = new StringBuilder();
var stderr = new StringBuilder();
var process = Runtime.getRuntime().exec("java --help");
assertDoesNotThrow(() -> ExecUtil.watchProcessAsync(
process,
(t, b, l) -> stdout.append(new String(b)),
Expand All @@ -108,12 +108,15 @@ void testWatchProcessAsyncProcessInputStreamListenerInputStreamListener()
//
@Test
void testWatchProcessAsyncProcessInputStream() throws IOException {
StringBuilder stdout = new StringBuilder();
StringBuilder stderr = new StringBuilder();
Process process = Runtime.getRuntime().exec("java --help");
var stdout = new StringBuilder();
var stderr = new StringBuilder();
var process = Runtime.getRuntime().exec("java --help");
assertDoesNotThrow(() -> ExecUtil.watchProcessAsync(
process,
new CharSequenceInputStream("java -h\n", UTF_8),
CharSequenceInputStream.builder()
.setCharSequence("java -h\n")
.setCharset(UTF_8)
.get(),
new InputStreamListener[] {
(t, b, l) -> stdout.append(new String(b))
},
Expand Down

0 comments on commit 573d513

Please sign in to comment.