diff --git a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/DebugHandlerTest.java b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/DebugHandlerTest.java index f34fd95aa42..141656a1129 100644 --- a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/DebugHandlerTest.java +++ b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/handler/DebugHandlerTest.java @@ -103,7 +103,7 @@ public class DebugHandlerTest secureServerURI = URI.create(String.format("https://%s:%d/", host, sslConnector.getLocalPort())); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); - try (InputStream stream = sslContextFactory.getKeyStoreResource().getInputStream()) + try (InputStream stream = sslContextFactory.getKeyStoreResource().newInputStream()) { keystore.load(stream, "storepwd".toCharArray()); } diff --git a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/resource/RangeWriterTest.java b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/resource/RangeWriterTest.java index c9db76fa2ba..fee42afc1db 100644 --- a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/resource/RangeWriterTest.java +++ b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/resource/RangeWriterTest.java @@ -31,7 +31,6 @@ import java.util.stream.Stream; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.Resource; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Disabled; @@ -101,13 +100,15 @@ public class RangeWriterTest return Stream.of( Arguments.of("Traditional / Direct Buffer", new ByteBufferRangeWriter(BufferUtil.toBuffer(realFileSystemResource, true))), Arguments.of("Traditional / Indirect Buffer", new ByteBufferRangeWriter(BufferUtil.toBuffer(realFileSystemResource, false))), - Arguments.of("Traditional / SeekableByteChannel", new SeekableByteChannelRangeWriter(() -> (SeekableByteChannel)realFileSystemResource.getReadableByteChannel())), - Arguments.of("Traditional / InputStream", new InputStreamRangeWriter(() -> realFileSystemResource.getInputStream())), + // TODO the cast to SeekableByteChannel is questionable + Arguments.of("Traditional / SeekableByteChannel", new SeekableByteChannelRangeWriter(() -> (SeekableByteChannel)realFileSystemResource.newReadableByteChannel())), + Arguments.of("Traditional / InputStream", new InputStreamRangeWriter(() -> realFileSystemResource.newInputStream())), Arguments.of("Non-Default FS / Direct Buffer", new ByteBufferRangeWriter(BufferUtil.toBuffer(nonDefaultFileSystemResource, true))), Arguments.of("Non-Default FS / Indirect Buffer", new ByteBufferRangeWriter(BufferUtil.toBuffer(nonDefaultFileSystemResource, false))), - Arguments.of("Non-Default FS / SeekableByteChannel", new SeekableByteChannelRangeWriter(() -> (SeekableByteChannel)nonDefaultFileSystemResource.getReadableByteChannel())), - Arguments.of("Non-Default FS / InputStream", new InputStreamRangeWriter(() -> nonDefaultFileSystemResource.getInputStream())) + // TODO the cast to SeekableByteChannel is questionable + Arguments.of("Non-Default FS / SeekableByteChannel", new SeekableByteChannelRangeWriter(() -> (SeekableByteChannel)nonDefaultFileSystemResource.newReadableByteChannel())), + Arguments.of("Non-Default FS / InputStream", new InputStreamRangeWriter(() -> nonDefaultFileSystemResource.newInputStream())) ); } diff --git a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/ServerConnectorSslServerTest.java b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/ServerConnectorSslServerTest.java index cbcd1fde7ac..a6ec8604298 100644 --- a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/ServerConnectorSslServerTest.java +++ b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/ServerConnectorSslServerTest.java @@ -85,7 +85,7 @@ public class ServerConnectorSslServerTest extends HttpServerTestBase initServer(connector); KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); - try (InputStream stream = sslContextFactory.getKeyStoreResource().getInputStream()) + try (InputStream stream = sslContextFactory.getKeyStoreResource().newInputStream()) { keystore.load(stream, "storepwd".toCharArray()); } diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java index e18bc065cf1..4d549131e64 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/EmptyResource.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; +import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; import java.nio.file.Path; import java.util.List; @@ -30,6 +31,35 @@ public class EmptyResource extends Resource { public static final Resource INSTANCE = new EmptyResource(); + private static final ReadableByteChannel EOF_READABLE_BYTE_CHANNEL = new ReadableByteChannel() + { + @Override + public int read(ByteBuffer dst) + { + return -1; + } + + @Override + public boolean isOpen() + { + return false; + } + + @Override + public void close() + { + } + }; + + private static final InputStream EOF_INPUT_STREAM = new InputStream() + { + @Override + public int read() + { + return -1; + } + }; + private EmptyResource() { } @@ -83,15 +113,15 @@ public class EmptyResource extends Resource } @Override - public InputStream getInputStream() throws IOException + public InputStream newInputStream() throws IOException { - return null; + return EOF_INPUT_STREAM; } @Override - public ReadableByteChannel getReadableByteChannel() throws IOException + public ReadableByteChannel newReadableByteChannel() throws IOException { - return null; + return EOF_READABLE_BYTE_CHANNEL; } @Override diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java index 93bbc75ab6d..64baad7940f 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java @@ -481,14 +481,12 @@ public abstract class Resource implements ResourceFactory public abstract String getName(); /** - * Input stream to the resource + * Creates a new input stream to the resource. * * @return an input stream to the resource * @throws IOException if unable to open the input stream - * @deprecated Replace with {@link #getPath()} and {@link Files#newInputStream(Path, OpenOption...)}. */ - @Deprecated(forRemoval = true) - public InputStream getInputStream() throws IOException + public InputStream newInputStream() throws IOException { return Files.newInputStream(getPath(), StandardOpenOption.READ); } @@ -498,10 +496,8 @@ public abstract class Resource implements ResourceFactory * * @return an readable bytechannel to the resource or null if one is not available. * @throws IOException if unable to open the readable bytechannel for the resource. - * @deprecated Replace with {@link #getPath()} and {@link Files#newByteChannel(Path, OpenOption...)}. */ - @Deprecated(forRemoval = true) - public ReadableByteChannel getReadableByteChannel() throws IOException + public ReadableByteChannel newReadableByteChannel() throws IOException { return Files.newByteChannel(getPath(), StandardOpenOption.READ); } @@ -1047,7 +1043,7 @@ public abstract class Resource implements ResourceFactory } // use old school stream based copy - try (InputStream in = getInputStream(); + try (InputStream in = newInputStream(); OutputStream out = Files.newOutputStream(destination)) { IO.copy(in, out); diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java index f1b64f010d2..fd718a80c81 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/ResourceCollection.java @@ -27,7 +27,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; -import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; @@ -313,7 +312,7 @@ public class ResourceCollection extends Resource } @Override - public InputStream getInputStream() throws IOException + public InputStream newInputStream() throws IOException { assertResourcesSet(); @@ -324,7 +323,7 @@ public class ResourceCollection extends Resource // Skip, cannot open anyway continue; } - InputStream is = r.getInputStream(); + InputStream is = r.newInputStream(); if (is != null) { return is; @@ -335,13 +334,13 @@ public class ResourceCollection extends Resource } @Override - public ReadableByteChannel getReadableByteChannel() throws IOException + public ReadableByteChannel newReadableByteChannel() throws IOException { assertResourcesSet(); for (Resource r : _resources) { - ReadableByteChannel channel = r.getReadableByteChannel(); + ReadableByteChannel channel = r.newReadableByteChannel(); if (channel != null) { return channel; diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/security/CertificateUtils.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/security/CertificateUtils.java index 35ff4503c07..f1e953f3107 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/security/CertificateUtils.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/security/CertificateUtils.java @@ -44,7 +44,7 @@ public class CertificateUtils if (!store.exists()) throw new IllegalStateException(store.getName() + " is not a valid keystore"); - try (InputStream inStream = store.getInputStream()) + try (InputStream inStream = store.newInputStream()) { keystore.load(inStream, storePassword == null ? null : storePassword.toCharArray()); } @@ -59,19 +59,10 @@ public class CertificateUtils if (crlPath != null) { - InputStream in = null; - try + try (InputStream in = Resource.newResource(crlPath).newInputStream()) { - in = Resource.newResource(crlPath).getInputStream(); crlList = CertificateFactory.getInstance("X.509").generateCRLs(in); } - finally - { - if (in != null) - { - in.close(); - } - } } return crlList; diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java index 63ac25e80c5..46c6de1b50e 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java @@ -432,7 +432,7 @@ public class FileSystemResourceTest Resource base = Resource.newResource(dir); Resource foo = base.resolve("foo"); - try (InputStream stream = foo.getInputStream(); + try (InputStream stream = foo.newInputStream(); InputStreamReader reader = new InputStreamReader(stream); StringWriter writer = new StringWriter()) { @@ -458,7 +458,7 @@ public class FileSystemResourceTest Resource base = Resource.newResource(dir); Resource foo = base.resolve("foo"); - try (ReadableByteChannel channel = foo.getReadableByteChannel()) + try (ReadableByteChannel channel = foo.newReadableByteChannel()) { ByteBuffer buf = ByteBuffer.allocate(256); channel.read(buf); @@ -1290,7 +1290,7 @@ public class FileSystemResourceTest private String toString(Resource resource) throws IOException { - try (InputStream inputStream = resource.getInputStream(); + try (InputStream inputStream = resource.newInputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { IO.copy(inputStream, outputStream); diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java index 94e87aa05ee..b2f1853c004 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java @@ -54,7 +54,7 @@ public class PathResourceTest PathResource resource = (PathResource)Resource.newResource(manifestPath); - try (InputStream inputStream = resource.getInputStream()) + try (InputStream inputStream = resource.newInputStream()) { assertThat("InputStream", inputStream, is(not(nullValue()))); } @@ -78,7 +78,7 @@ public class PathResourceTest PathResource resource = (PathResource)Resource.newResource(manifestPath); - try (ReadableByteChannel channel = resource.getReadableByteChannel()) + try (ReadableByteChannel channel = resource.newReadableByteChannel()) { assertThat("ReadableByteChannel", channel, is(not(nullValue()))); } diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java index 6c3b276a17f..c873d3f3761 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceCollectionTest.java @@ -18,7 +18,6 @@ import java.io.File; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.file.Path; -import java.util.Arrays; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; @@ -158,8 +157,8 @@ public class ResourceCollectionTest assertThrows(IllegalStateException.class, () -> coll.resolve("foo")); assertThrows(IllegalStateException.class, coll::exists); assertThrows(IllegalStateException.class, coll::getPath); - assertThrows(IllegalStateException.class, coll::getInputStream); - assertThrows(IllegalStateException.class, coll::getReadableByteChannel); + assertThrows(IllegalStateException.class, coll::newInputStream); + assertThrows(IllegalStateException.class, coll::newReadableByteChannel); assertThrows(IllegalStateException.class, coll::getURI); assertThrows(IllegalStateException.class, coll::getName); assertThrows(IllegalStateException.class, coll::isDirectory); @@ -253,7 +252,7 @@ public class ResourceCollectionTest { Resource resource = r.resolve(path); StringBuilder buffer = new StringBuilder(); - try (InputStream in = resource.getInputStream(); + try (InputStream in = resource.newInputStream(); InputStreamReader reader = new InputStreamReader(in); BufferedReader br = new BufferedReader(reader)) { diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java index 8fa6970564e..fb615a01478 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java @@ -291,7 +291,7 @@ public class ResourceTest { Assumptions.assumeTrue(data.content != null); - InputStream in = data.resource.getInputStream(); + InputStream in = data.resource.newInputStream(); String c = IO.toString(in); assertThat("Content: " + data.test, c, startsWith(data.content)); } diff --git a/jetty-ee10/jetty-ee10-annotations/src/main/java/org/eclipse/jetty/ee10/annotations/AnnotationParser.java b/jetty-ee10/jetty-ee10-annotations/src/main/java/org/eclipse/jetty/ee10/annotations/AnnotationParser.java index 67f7cf61d3c..8a9ec5785de 100644 --- a/jetty-ee10/jetty-ee10-annotations/src/main/java/org/eclipse/jetty/ee10/annotations/AnnotationParser.java +++ b/jetty-ee10/jetty-ee10-annotations/src/main/java/org/eclipse/jetty/ee10/annotations/AnnotationParser.java @@ -581,7 +581,7 @@ public class AnnotationParser { Resource r = Resource.newResource(resource); addParsedClass(className, r.toString()); - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, null, is); } @@ -607,7 +607,7 @@ public class AnnotationParser { Resource r = Resource.newResource(resource); addParsedClass(clazz.getName(), r.toString()); - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, null, is); } @@ -656,7 +656,7 @@ public class AnnotationParser { Resource r = Resource.newResource(resource); addParsedClass(className, r.toString()); - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, null, is); } @@ -740,7 +740,7 @@ public class AnnotationParser if (fullname.endsWith(".class")) { - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, null, is); return; @@ -790,7 +790,7 @@ public class AnnotationParser if (LOG.isDebugEnabled()) LOG.debug("Scanning class {}", r); addParsedClass(str, r.toString()); - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, Resource.newResource(path.getParent()), is); } diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextHandler.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextHandler.java index 1a6606fae04..3111a29b6b6 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextHandler.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/ServletContextHandler.java @@ -3119,7 +3119,7 @@ public class ServletContextHandler extends ContextHandler implements Graceful // Cannot serve directories as an InputStream if (r.isDirectory()) return null; - return r.getInputStream(); + return r.newInputStream(); } catch (Exception e) { diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/security/JDBCLoginService.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/security/JDBCLoginService.java index b93ef1c9ff2..5b1b377dcab 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/security/JDBCLoginService.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/security/JDBCLoginService.java @@ -98,7 +98,7 @@ public class JDBCLoginService extends AbstractLoginService { Properties properties = new Properties(); Resource resource = Resource.newResource(_config); - try (InputStream in = resource.getInputStream()) + try (InputStream in = resource.newInputStream()) { properties.load(in); } diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/security/PropertyUserStore.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/security/PropertyUserStore.java index ab7ee7b5c34..d00c7a40a6f 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/security/PropertyUserStore.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/security/PropertyUserStore.java @@ -225,7 +225,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener throw new IllegalStateException("Config does not exist: " + config); Properties properties = new Properties(); - try (InputStream inputStream = config.getInputStream()) + try (InputStream inputStream = config.newInputStream()) { properties.load(inputStream); } diff --git a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/OrderingTest.java b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/OrderingTest.java index 409b8a1187f..f3f81796ea4 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/OrderingTest.java +++ b/jetty-ee10/jetty-ee10-webapp/src/test/java/org/eclipse/jetty/ee10/webapp/OrderingTest.java @@ -71,13 +71,13 @@ public class OrderingTest } @Override - public InputStream getInputStream() throws IOException + public InputStream newInputStream() throws IOException { return null; } @Override - public ReadableByteChannel getReadableByteChannel() throws IOException + public ReadableByteChannel newReadableByteChannel() throws IOException { return null; } diff --git a/jetty-ee10/test-ee10-sessions/test-ee10-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractWebAppObjectInSessionTest.java b/jetty-ee10/test-ee10-sessions/test-ee10-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractWebAppObjectInSessionTest.java index c18753697c3..d96c0f628e4 100644 --- a/jetty-ee10/test-ee10-sessions/test-ee10-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractWebAppObjectInSessionTest.java +++ b/jetty-ee10/test-ee10-sessions/test-ee10-sessions-common/src/main/java/org/eclipse/jetty/ee10/session/AbstractWebAppObjectInSessionTest.java @@ -83,14 +83,14 @@ public abstract class AbstractWebAppObjectInSessionTest extends AbstractSessionT //File sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI()); File targetFile = new File(packageDirs, resourceName); //copy(sourceFile, targetFile); - IO.copy(resource.getInputStream(), new FileOutputStream(targetFile)); + IO.copy(resource.newInputStream(), new FileOutputStream(targetFile)); resourceName = WebAppObjectInSessionServlet.class.getSimpleName() + "$" + WebAppObjectInSessionServlet.TestSharedStatic.class.getSimpleName() + ".class"; resource = Resource.newResource(getClass().getResource(resourceName)); //sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI()); targetFile = new File(packageDirs, resourceName); //copy(sourceFile, targetFile); - IO.copy(resource.getInputStream(), new FileOutputStream(targetFile)); + IO.copy(resource.newInputStream(), new FileOutputStream(targetFile)); DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT); diff --git a/jetty-ee9/jetty-ee9-annotations/src/main/java/org/eclipse/jetty/ee9/annotations/AnnotationParser.java b/jetty-ee9/jetty-ee9-annotations/src/main/java/org/eclipse/jetty/ee9/annotations/AnnotationParser.java index 32857da1fe0..8bceff5947a 100644 --- a/jetty-ee9/jetty-ee9-annotations/src/main/java/org/eclipse/jetty/ee9/annotations/AnnotationParser.java +++ b/jetty-ee9/jetty-ee9-annotations/src/main/java/org/eclipse/jetty/ee9/annotations/AnnotationParser.java @@ -581,7 +581,7 @@ public class AnnotationParser { Resource r = Resource.newResource(resource); addParsedClass(className, r.toString()); - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, null, is); } @@ -607,7 +607,7 @@ public class AnnotationParser { Resource r = Resource.newResource(resource); addParsedClass(clazz.getName(), r.toString()); - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, null, is); } @@ -656,7 +656,7 @@ public class AnnotationParser { Resource r = Resource.newResource(resource); addParsedClass(className, r.toString()); - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, null, is); } @@ -740,7 +740,7 @@ public class AnnotationParser if (fullname.endsWith(".class")) { - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, null, is); return; @@ -790,7 +790,7 @@ public class AnnotationParser if (LOG.isDebugEnabled()) LOG.debug("Scanning class {}", r); addParsedClass(str, r.toString()); - try (InputStream is = r.getInputStream()) + try (InputStream is = r.newInputStream()) { scanClass(handlers, Resource.newResource(path.getParent()), is); } diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java index 536a3fdf71a..9f787c7f93c 100644 --- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java +++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ContextHandler.java @@ -1886,7 +1886,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu // Cannot serve directories as an InputStream if (r.isDirectory()) return null; - return r.getInputStream(); + return r.newInputStream(); } catch (Exception e) { diff --git a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ResourceService.java b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ResourceService.java index 1771e40661e..cee51bc21fa 100644 --- a/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ResourceService.java +++ b/jetty-ee9/jetty-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/ResourceService.java @@ -851,7 +851,7 @@ public class ResourceService return; } - try (InputStream input = content.getResource().getInputStream()) + try (InputStream input = content.getResource().newInputStream()) { IO.copy(input, out); return; diff --git a/jetty-ee9/jetty-ee9-nested/src/test/java/org/eclipse/jetty/ee9/nested/HttpOutputTest.java b/jetty-ee9/jetty-ee9-nested/src/test/java/org/eclipse/jetty/ee9/nested/HttpOutputTest.java index 615878e64e0..1126a6aca3e 100644 --- a/jetty-ee9/jetty-ee9-nested/src/test/java/org/eclipse/jetty/ee9/nested/HttpOutputTest.java +++ b/jetty-ee9/jetty-ee9-nested/src/test/java/org/eclipse/jetty/ee9/nested/HttpOutputTest.java @@ -39,6 +39,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.FuturePromise; +import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.resource.Resource; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterEach; @@ -91,6 +92,8 @@ public class HttpOutputTest @AfterEach public void destroy() throws Exception { + IO.close(_handler._contentInputStream); + IO.close(_handler._contentChannel); _server.stop(); _server.join(); } @@ -137,7 +140,7 @@ public class HttpOutputTest public void testSendInputStreamSimple() throws Exception { Resource simple = Resource.newClassPathResource("simple/simple.txt"); - _handler._contentInputStream = simple.getInputStream(); + _handler._contentInputStream = simple.newInputStream(); String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n"); assertThat(response, containsString("HTTP/1.1 200 OK")); assertThat(response, containsString("Content-Length: 11")); @@ -147,7 +150,7 @@ public class HttpOutputTest public void testSendInputStreamBig() throws Exception { Resource big = Resource.newClassPathResource("simple/big.txt"); - _handler._contentInputStream = big.getInputStream(); + _handler._contentInputStream = big.newInputStream(); String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n"); assertThat(response, containsString("HTTP/1.1 200 OK")); assertThat(response, Matchers.not(containsString("Content-Length"))); @@ -158,7 +161,7 @@ public class HttpOutputTest public void testSendInputStreamBigChunked() throws Exception { Resource big = Resource.newClassPathResource("simple/big.txt"); - _handler._contentInputStream = new FilterInputStream(big.getInputStream()) + _handler._contentInputStream = new FilterInputStream(big.newInputStream()) { @Override public int read(byte[] b, int off, int len) throws IOException @@ -189,7 +192,7 @@ public class HttpOutputTest public void testSendChannelSimple() throws Exception { Resource simple = Resource.newClassPathResource("simple/simple.txt"); - _handler._contentChannel = simple.getReadableByteChannel(); + _handler._contentChannel = simple.newReadableByteChannel(); String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n"); assertThat(response, containsString("HTTP/1.1 200 OK")); assertThat(response, containsString("Content-Length: 11")); @@ -199,7 +202,7 @@ public class HttpOutputTest public void testSendChannelBig() throws Exception { Resource big = Resource.newClassPathResource("simple/big.txt"); - _handler._contentChannel = big.getReadableByteChannel(); + _handler._contentChannel = big.newReadableByteChannel(); String response = _connector.getResponse("GET / HTTP/1.0\nHost: localhost:80\n\n"); assertThat(response, containsString("HTTP/1.1 200 OK")); assertThat(response, Matchers.not(containsString("Content-Length"))); @@ -232,7 +235,7 @@ public class HttpOutputTest public void testSendChannelBigChunked() throws Exception { Resource big = Resource.newClassPathResource("simple/big.txt"); - final ReadableByteChannel channel = big.getReadableByteChannel(); + final ReadableByteChannel channel = big.newReadableByteChannel(); _handler._contentChannel = new ReadableByteChannel() { @Override diff --git a/jetty-ee9/jetty-ee9-security/src/main/java/org/eclipse/jetty/ee9/security/JDBCLoginService.java b/jetty-ee9/jetty-ee9-security/src/main/java/org/eclipse/jetty/ee9/security/JDBCLoginService.java index 07f2ad3e5a0..077e855e3d0 100644 --- a/jetty-ee9/jetty-ee9-security/src/main/java/org/eclipse/jetty/ee9/security/JDBCLoginService.java +++ b/jetty-ee9/jetty-ee9-security/src/main/java/org/eclipse/jetty/ee9/security/JDBCLoginService.java @@ -98,7 +98,7 @@ public class JDBCLoginService extends AbstractLoginService { Properties properties = new Properties(); Resource resource = Resource.newResource(_config); - try (InputStream in = resource.getInputStream()) + try (InputStream in = resource.newInputStream()) { properties.load(in); } diff --git a/jetty-ee9/jetty-ee9-security/src/main/java/org/eclipse/jetty/ee9/security/PropertyUserStore.java b/jetty-ee9/jetty-ee9-security/src/main/java/org/eclipse/jetty/ee9/security/PropertyUserStore.java index ebd6104b2ca..ce403d5c320 100644 --- a/jetty-ee9/jetty-ee9-security/src/main/java/org/eclipse/jetty/ee9/security/PropertyUserStore.java +++ b/jetty-ee9/jetty-ee9-security/src/main/java/org/eclipse/jetty/ee9/security/PropertyUserStore.java @@ -225,7 +225,7 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener throw new IllegalStateException("Config does not exist: " + config); Properties properties = new Properties(); - try (InputStream inputStream = config.getInputStream()) + try (InputStream inputStream = config.newInputStream()) { properties.load(inputStream); } diff --git a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/OrderingTest.java b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/OrderingTest.java index 67f9a58b080..58cbb9a5178 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/OrderingTest.java +++ b/jetty-ee9/jetty-ee9-webapp/src/test/java/org/eclipse/jetty/ee9/webapp/OrderingTest.java @@ -71,13 +71,13 @@ public class OrderingTest } @Override - public InputStream getInputStream() throws IOException + public InputStream newInputStream() throws IOException { return null; } @Override - public ReadableByteChannel getReadableByteChannel() throws IOException + public ReadableByteChannel newReadableByteChannel() throws IOException { return null; } diff --git a/jetty-ee9/test-ee9-sessions/test-ee9-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractWebAppObjectInSessionTest.java b/jetty-ee9/test-ee9-sessions/test-ee9-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractWebAppObjectInSessionTest.java index 6b43ee2c07b..e0cb02401ee 100644 --- a/jetty-ee9/test-ee9-sessions/test-ee9-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractWebAppObjectInSessionTest.java +++ b/jetty-ee9/test-ee9-sessions/test-ee9-sessions-common/src/main/java/org/eclipse/jetty/ee9/session/AbstractWebAppObjectInSessionTest.java @@ -83,14 +83,14 @@ public abstract class AbstractWebAppObjectInSessionTest extends AbstractSessionT //File sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI()); File targetFile = new File(packageDirs, resourceName); //copy(sourceFile, targetFile); - IO.copy(resource.getInputStream(), new FileOutputStream(targetFile)); + IO.copy(resource.newInputStream(), new FileOutputStream(targetFile)); resourceName = WebAppObjectInSessionServlet.class.getSimpleName() + "$" + WebAppObjectInSessionServlet.TestSharedStatic.class.getSimpleName() + ".class"; resource = Resource.newResource(getClass().getResource(resourceName)); //sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI()); targetFile = new File(packageDirs, resourceName); //copy(sourceFile, targetFile); - IO.copy(resource.getInputStream(), new FileOutputStream(targetFile)); + IO.copy(resource.newInputStream(), new FileOutputStream(targetFile)); DefaultSessionCacheFactory cacheFactory = new DefaultSessionCacheFactory(); cacheFactory.setEvictionPolicy(SessionCache.NEVER_EVICT);