ResourceFactory is the source of new Resource instances.
Some Resource objects have an internal allocation / release model,
that the ResourceFactory is responsible for.
Once a ResourceFactory is stopped, the Resource
objects created from that ResourceFactory are released.
ResourceFactory.LifeCycle tied to a Jetty org.eclipse.jetty.util.component.Container
ResourceFactory.LifeCycle resourceFactory = ResourceFactory.of(container);
Resource resource = resourceFactory.newResource(ref);
The use of ResourceFactory#of(Container) results in a ResourceFactory. that is tied
to a specific Jetty org. such as a Server,
ServletContextHandler, or WebAppContext. This will free the Resource
instances created by the org. once
the container that manages it is stopped.
ResourceFactory.Closeable that exists within a try-with-resources call
try (ResourceFactory.Closeable resourceFactory = ResourceFactory.closeable()) {
Resource resource = resourceFactory.newResource(ref);
}
The use of ResourceFactory#closeable() results in a ResourceFactory that only exists for
the duration of the try-with-resources code block, once this try-with-resources is closed,
all Resource objects associated with that ResourceFactory are freed as well.
ResourceFactory that lives at the JVM level
ResourceFactory resourceFactory = ResourceFactory.root();
Resource resource = resourceFactory.newResource(ref);
The use of ResourceFactory#root() results in a ResourceFactory that exists for
the life of the JVM, and the resources allocated via this ResourceFactory will not
be freed until the JVM exits.
By default, the following schemes are supported by Jetty.
file:/path/to/dir/ syntaxjar:file:/path/to/file.jar!/ syntaxjrt:module-name syntax
Special Note: An effort is made to discover any new schemes that
might be present at JVM startup (eg: graalvm and resource: scheme).
At startup Jetty will access an internal Jetty resource (found in
the jetty-util jar) and seeing what scheme it is using to access
it, and will register it with a call to
ResourceFactory#registerResourceFactory(String, ResourceFactory).
You can register a new URI scheme to a ResourceFactory implementation
using the ResourceFactory#registerResourceFactory(String, ResourceFactory)
method, which will cause all new uses of ResourceFactory to use this newly
registered scheme.
URLResourceFactory urlResourceFactory = new URLResourceFactory();
urlResourceFactory.setConnectTimeout(1000);
ResourceFactory.registerResourceFactory("https", urlResourceFactory);
URI web = URI.create("https://eclipse.dev/jetty/");
Resource resource = ResourceFactory.root().newResource(web);
| Modifier and Type | Class and Description |
|---|---|
| public static interface | |
| public static interface |
| Modifier and Type | Method and Description |
|---|---|
| public static ResourceFactory. | Returns: a ResourceFactory that can be closed in a try-with-resources code blockA ResourceFactory that can close it's opened resources using the Java standard |
| public static Resource | Returns: ACombinedResource for multiple resources;
or a single Resource if only 1 is passed;
or null if none are passed.
The returned Resource will always return true from Resource#isDirectory()multiple directory resources)Resources to combine as a single resource. Order is significant.Make a directory Resource containing a collection of other directory |
| public static Resource | Returns: ACombinedResource for multiple resources;
or a single Resource if only 1 is passed;
or null if none are passed.
The returned Resource will always return true from Resource#isDirectory()multiple directory resources)Resources to combine as a single resource. Order is significant.Make a directory Resource containing a collection of directory |
| public static boolean | Returns: true if it is supportedthe string to test str)Test to see if provided string is supported. |
| public static boolean | Returns: true if it is supportedthe uri to test uri)Test to see if provided uri is supported. |
| public static ResourceFactory. | Returns: the ResourceFactory that implementsorg.A ResourceFactory that implements the Jetty LifeCycle. |
| public default Resource | Returns: The new Resource, or null if string points to a location that does not existthe resource name to find in a classloader resource, boolean true to search searchSystemClassLoader)ClassLoader#getSystemResource(String), false to skipConstruct a Resource from a search of ClassLoaders. |
| public default Resource | Returns: The new Resource, or null if string points to a location that does not existstring representation of resource to find in a classloader resource)Construct a Resource from a search of ClassLoaders. |
| public default Resource | Returns: Resource, or null if string points to a location that does not existthe relative name of the resource resource)
Deprecated
for removal since 12.0.2. use
newClassLoaderResource(String, boolean) instead, will be removed in Jetty 12.1.0
Construct a Resource from a search of ClassLoaders. |
| public default Resource | Returns: the Resource, mounted as ajava., or null if
the uri points to a location that does not exist.the URI uri)Construct a |
| public default Resource | Returns: Resource, or null if url points to a location that does not existthe URL to load into memory url)Load a URL into a memory resource. |
| public Resource | Returns: A Resource object, or null if uri points to a location that does not exist.A URI. uri)Construct a resource from a uri. |
| public default Resource | Returns: A Resource object, or null if the string points to a location that does not existA URL or filename. resource)Construct a resource from a string. |
| public default Resource | Returns: the Resource for the provided path, or null if the path does not existthe path path)Construct a Resource from provided path. |
| public default Resource | Returns: the Resource for the provided URIs, or null if all of the provided URIs do not existthe URIs uris)Construct a possible combined |
| public default Resource | Returns: the Resource for the provided URL, or null if the url points to a location that does not existthe URL url)Construct a |
| public default Resource | Returns: The new Resource, or null if string points to a location that does not existResource as string representation resource)
Deprecated
for removal since 12.0.2. use
newClassLoaderResource(String) or newClassLoaderResource(String, boolean) instead, will be removed in Jetty 12.1.0
Construct a Resource from a string reference into classloaders. |
| public static ResourceFactory | Returns: the ResourceFactory that builds from the Resourcethe resource to base this ResourceFactory from baseResource)A new ResourceFactory from a provided Resource, to base |
| public static ResourceFactory | |
| public static void | registerResourceFactory(String
the scheme to support (eg: `ftp`, `http`, `resource`, etc) scheme, ResourceFactory the ResourceFactory to be responsible for the registered scheme. resourceFactory)Register a new ResourceFactory that can handle the specific scheme for the Resource API. |
| public static ResourceFactory | |
| public static ResourceFactory | Returns: the existingResourceFactory that was registered to that scheme.the scheme to unregister scheme)Unregister a scheme that is supported by the Resource API. |
| LOG | back to summary |
|---|---|
| public static final Logger LOG | |
| closeable | back to summary |
|---|---|
| public static ResourceFactory. A ResourceFactory that can close it's opened resources using the Java standard
| |
| combine | back to summary |
|---|---|
| public static Resource combine(List<Resource> resources) Make a directory Resource containing a collection of other directory
| |
| combine | back to summary |
|---|---|
| public static Resource combine(Resource... resources) Make a directory Resource containing a collection of directory
| |
| isSupported | back to summary |
|---|---|
| public static boolean isSupported(String str) Test to see if provided string is supported.
| |
| isSupported | back to summary |
|---|---|
| public static boolean isSupported(URI uri) Test to see if provided uri is supported.
| |
| lifecycle | back to summary |
|---|---|
| public static ResourceFactory. A ResourceFactory that implements the Jetty LifeCycle. This style of ResourceFactory can be attached to the normal Jetty LifeCycle to clean up it's allocated resources.
| |
| newClassLoaderResource | back to summary |
|---|---|
| public default Resource newClassLoaderResource(String resource, boolean searchSystemClassLoader) Construct a Resource from a search of ClassLoaders. Search order is:
See
If a provided resource name starts with a
| |
| newClassLoaderResource | back to summary |
|---|---|
| public default Resource newClassLoaderResource(String resource) Construct a Resource from a search of ClassLoaders.
Convenience method
| |
| newClassPathResource | back to summary |
|---|---|
| public default Resource newClassPathResource(String resource)
Deprecated for removal since 12.0.2. use Construct a Resource from a search of ClassLoaders.
Convenience method
| |
| newJarFileResource | back to summary |
|---|---|
| public default Resource newJarFileResource(URI uri) Construct a
| |
| newMemoryResource | back to summary |
|---|---|
| public default Resource newMemoryResource(URL url) Load a URL into a memory resource.
A Memory Resource is created from a the contents of
| |
| newResource | back to summary |
|---|---|
| public Resource newResource(URI uri) Construct a resource from a uri. | |
| newResource | back to summary |
|---|---|
| public default Resource newResource(String resource) Construct a resource from a string.
| |
| newResource | back to summary |
|---|---|
| public default Resource newResource(Path path) Construct a Resource from provided path.
| |
| newResource | back to summary |
|---|---|
| public default Resource newResource(List<URI> uris) Construct a possible combined
| |
| newResource | back to summary |
|---|---|
| public default Resource newResource(URL url) Construct a
| |
| newSystemResource | back to summary |
|---|---|
| public default Resource newSystemResource(String resource)
Deprecated for removal since 12.0.2. use Construct a Resource from a string reference into classloaders.
| |
| of | back to summary |
|---|---|
| public static ResourceFactory of(Resource baseResource) A new ResourceFactory from a provided Resource, to base
| |
| of | back to summary |
|---|---|
| public static ResourceFactory of(Container container) A new ResourceFactory tied to a Jetty Component
This is safe to call repeatedly against the same
| |
| registerResourceFactory | back to summary |
|---|---|
| public static void registerResourceFactory(String scheme, ResourceFactory resourceFactory) Register a new ResourceFactory that can handle the specific scheme for the Resource API. This allows
| |
| root | back to summary |
|---|---|
| public static ResourceFactory root() The JVM wide (root) ResourceFactory. Resources allocated this way are not released until the JVM is closed.
If you have a ResourceFactory need that needs to clean up it's resources at runtime, use
| |
| unregisterResourceFactory | back to summary |
|---|---|
| public static ResourceFactory unregisterResourceFactory(String scheme) Unregister a scheme that is supported by the Resource API.
| |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Redeclares java. |
| close | back to summary |
|---|---|
| public void close() Redeclares java. Doc from java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. As noted in
| |