From 9d96068c8c7f020fa4742e540649b38d986f9f1a Mon Sep 17 00:00:00 2001 From: jansupol Date: Thu, 17 Aug 2023 17:17:16 +0200 Subject: [PATCH] Fix nio failures on Windows Signed-off-by: jansupol --- .../src/main/java/org/glassfish/jersey/SslConfigurator.java | 6 +++--- .../scanning/JarZipSchemeResourceFinderFactory.java | 4 ++-- .../src/test/java/org/glassfish/jersey/server/JarUtils.java | 3 +-- .../jersey/server/mvc/spi/AbstractTemplateProcessor.java | 4 ++-- .../java/org/glassfish/jersey/wadl/doclet/DocletUtils.java | 4 ++-- .../jersey/tools/plugins/GenerateJerseyModuleListMojo.java | 4 ++-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/SslConfigurator.java b/core-common/src/main/java/org/glassfish/jersey/SslConfigurator.java index 813da91d65..b3befea473 100644 --- a/core-common/src/main/java/org/glassfish/jersey/SslConfigurator.java +++ b/core-common/src/main/java/org/glassfish/jersey/SslConfigurator.java @@ -17,11 +17,11 @@ package org.glassfish.jersey; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; -import java.nio.file.Paths; import java.security.AccessController; import java.security.KeyManagementException; import java.security.KeyStore; @@ -636,7 +636,7 @@ public SSLContext createSSLContext() { if (keyStoreBytes != null) { keyStoreInputStream = new ByteArrayInputStream(keyStoreBytes); } else if (!keyStoreFile.equals("NONE")) { - keyStoreInputStream = Files.newInputStream(Paths.get(keyStoreFile)); + keyStoreInputStream = Files.newInputStream(new File(keyStoreFile).toPath()); } _keyStore.load(keyStoreInputStream, keyStorePass); } finally { @@ -711,7 +711,7 @@ public SSLContext createSSLContext() { if (trustStoreBytes != null) { trustStoreInputStream = new ByteArrayInputStream(trustStoreBytes); } else if (!trustStoreFile.equals("NONE")) { - trustStoreInputStream = Files.newInputStream(Paths.get(trustStoreFile)); + trustStoreInputStream = Files.newInputStream(new File(trustStoreFile).toPath()); } _trustStore.load(trustStoreInputStream, trustStorePass); } finally { diff --git a/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/JarZipSchemeResourceFinderFactory.java b/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/JarZipSchemeResourceFinderFactory.java index 0c5ee713eb..aa2874eb5d 100644 --- a/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/JarZipSchemeResourceFinderFactory.java +++ b/core-server/src/main/java/org/glassfish/jersey/server/internal/scanning/JarZipSchemeResourceFinderFactory.java @@ -16,13 +16,13 @@ package org.glassfish.jersey.server.internal.scanning; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -155,7 +155,7 @@ private InputStream getInputStream(final String jarUrlString) throws IOException return new URL(jarUrlString).openStream(); } catch (final MalformedURLException e) { return Files.newInputStream( - Paths.get(UriComponent.decode(jarUrlString, UriComponent.Type.PATH))); + new File(UriComponent.decode(jarUrlString, UriComponent.Type.PATH)).toPath()); } } } diff --git a/core-server/src/test/java/org/glassfish/jersey/server/JarUtils.java b/core-server/src/test/java/org/glassfish/jersey/server/JarUtils.java index 82d60ce2b0..50a5402404 100644 --- a/core-server/src/test/java/org/glassfish/jersey/server/JarUtils.java +++ b/core-server/src/test/java/org/glassfish/jersey/server/JarUtils.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -90,7 +89,7 @@ public static File createJarFile(final String name, final Suffix s, final String jos.putNextEntry(e); final InputStream f = new BufferedInputStream( - Files.newInputStream(Paths.get(base + entry.getKey()))); + Files.newInputStream(new File(base, entry.getKey()).toPath())); final byte[] buf = new byte[1024]; int read = 1024; while ((read = f.read(buf, 0, read)) != -1) { diff --git a/ext/mvc/src/main/java/org/glassfish/jersey/server/mvc/spi/AbstractTemplateProcessor.java b/ext/mvc/src/main/java/org/glassfish/jersey/server/mvc/spi/AbstractTemplateProcessor.java index 0fe313092e..f843ae82a1 100644 --- a/ext/mvc/src/main/java/org/glassfish/jersey/server/mvc/spi/AbstractTemplateProcessor.java +++ b/ext/mvc/src/main/java/org/glassfish/jersey/server/mvc/spi/AbstractTemplateProcessor.java @@ -16,13 +16,13 @@ package org.glassfish.jersey.server.mvc.spi; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -182,7 +182,7 @@ private T resolve(final String name) { // File-system path. if (reader == null) { try { - reader = new InputStreamReader(Files.newInputStream(Paths.get(template)), encoding); + reader = new InputStreamReader(Files.newInputStream(new File(template).toPath()), encoding); } catch (final IOException ioe) { // NOOP. } diff --git a/ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java b/ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java index 431a0cb231..47b2e84125 100644 --- a/ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java +++ b/ext/wadl-doclet/src/main/java/org/glassfish/jersey/wadl/doclet/DocletUtils.java @@ -18,12 +18,12 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; +import java.io.File; import java.io.OutputStream; import java.io.StringWriter; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; @@ -97,7 +97,7 @@ static boolean createOutputFile(String filePath, DocProcessor docProcessor, Reso Class[] classes = getJAXBContextClasses(result, docProcessor); LOG.info("cdataElements " + Arrays.asList(cdataElements)); LOG.info("classes " + Arrays.asList(classes)); - try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(Paths.get(filePath)))) { + try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(new File(filePath).toPath()))) { JAXBContext c = JAXBContext.newInstance(classes); Marshaller m = c.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); diff --git a/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/GenerateJerseyModuleListMojo.java b/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/GenerateJerseyModuleListMojo.java index fe8b9088d8..d81fce3ca0 100644 --- a/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/GenerateJerseyModuleListMojo.java +++ b/tools/jersey-doc-modulelist-maven-plugin/src/main/java/org/glassfish/jersey/tools/plugins/GenerateJerseyModuleListMojo.java @@ -28,11 +28,11 @@ import org.apache.maven.project.MavenProject; import java.io.BufferedReader; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Files; -import java.nio.file.Paths; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -315,7 +315,7 @@ public void setLog(org.apache.maven.plugin.logging.Log log) { } public String readFile(String fileName) throws IOException { - BufferedReader reader = Files.newBufferedReader(Paths.get(fileName)); + BufferedReader reader = Files.newBufferedReader(new File(fileName).toPath()); String s; StringBuilder sb = new StringBuilder(); while ((s = reader.readLine()) != null) {