Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.util.resource;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
import java.util.StringTokenizer;
import org.eclipse.jetty.util.FileID;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.component.Container;
import org.eclipse.jetty.util.component.Dumpable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
ResourceFactory is the source of new {@link Resource} instances.
*
*
* Some {@link Resource} objects have an internal allocation / release model,
* that the {@link ResourceFactory} is responsible for.
* Once a {@link ResourceFactory} is stopped, the {@link Resource}
* objects created from that {@link ResourceFactory} are released.
*
*
*
A {@link ResourceFactory.LifeCycle} tied to a Jetty {@link org.eclipse.jetty.util.component.Container}
* The use of {@link ResourceFactory#of(Container)} results in a {@link ResourceFactory.LifeCycle} that is tied
* to a specific Jetty {@link org.eclipse.jetty.util.component.Container} such as a {@code Server},
* {@code ServletContextHandler}, or {@code WebAppContext}. This will free the {@code Resource}
* instances created by the {@link org.eclipse.jetty.util.resource.ResourceFactory} once
* the {@code container} that manages it is stopped.
*
*
*
A {@link ResourceFactory.Closeable} that exists within a {@code try-with-resources} call
* The use of {@link ResourceFactory#closeable()} results in a {@link ResourceFactory} that only exists for
* the duration of the {@code try-with-resources} code block, once this {@code try-with-resources} is closed,
* all {@link Resource} objects associated with that {@link ResourceFactory} are freed as well.
*
*
*
A {@code ResourceFactory} that lives at the JVM level
* The use of {@link ResourceFactory#root()} results in a {@link ResourceFactory} that exists for
* the life of the JVM, and the resources allocated via this {@link ResourceFactory} will not
* be freed until the JVM exits.
*
*
*
Supported URI Schemes
*
* By default, the following schemes are supported by Jetty.
*
*
*
file
*
The standard Java {@code file:/path/to/dir/} syntax
*
*
jar
*
The standard Java {@code jar:file:/path/to/file.jar!/} syntax
*
*
jrt
*
The standard Java {@code jrt:module-name} syntax
*
*
* Special Note: An effort is made to discover any new schemes that
* might be present at JVM startup (eg: graalvm and {@code resource:} scheme).
* At startup Jetty will access an internal Jetty resource (found in
* the jetty-util jar) and seeing what {@code scheme} it is using to access
* it, and will register it with a call to
* {@link ResourceFactory#registerResourceFactory(String, ResourceFactory)}.
*
*
*
Supporting more Schemes
*
* You can register a new URI scheme to a {@link ResourceFactory} implementation
* using the {@link 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://jetty.org/");
* Resource resource = ResourceFactory.root().newResource(web);
*
Make a directory Resource containing a collection of other directory {@link Resource}s
* @param resources multiple directory {@link Resource}s to combine as a single resource. Order is significant.
* @return A {@link CombinedResource} for multiple resources;
* or a single {@link Resource} if only 1 is passed;
* or null if none are passed.
* The returned {@link Resource} will always return {@code true} from {@link Resource#isDirectory()}
* @throws IllegalArgumentException if a non-directory resource is passed.
*/
static Resource combine(List resources)
{
return CombinedResource.combine(resources);
}
/**
*
Make a directory Resource containing a collection of directory {@link Resource}s
* @param resources multiple directory {@link Resource}s to combine as a single resource. Order is significant.
* @return A {@link CombinedResource} for multiple resources;
* or a single {@link Resource} if only 1 is passed;
* or null if none are passed.
* The returned {@link Resource} will always return {@code true} from {@link Resource#isDirectory()}
* @throws IllegalArgumentException if a non-directory resource is passed.
*/
static Resource combine(Resource... resources)
{
return CombinedResource.combine(List.of(resources));
}
/**
* Construct a resource from a uri.
*
* @param uri A URI.
* @return A Resource object.
*/
Resource newResource(URI uri);
/**
*
Construct a Resource from a string reference into classloaders.
*
* @param resource Resource as string representation
* @return The new Resource
* @throws IllegalArgumentException if string is blank
* @see #newClassLoaderResource(String, boolean)
* @deprecated use {@link #newClassLoaderResource(String)} or {@link #newClassLoaderResource(String, boolean)} instead, will be removed in Jetty 12.1.0
*/
@Deprecated(since = "12.0.2", forRemoval = true)
default Resource newSystemResource(String resource)
{
return newClassLoaderResource(resource);
}
/**
*
Construct a Resource from a search of ClassLoaders.
* See {@link ClassLoader#getResource(String)} for rules on resource name parameter.
*
*
*
* If a provided resource name starts with a {@code /} (example: {@code /org/example/ClassName.class})
* then the non-slash version is also tried against the same ClassLoader (example: {@code org/example/ClassName.class}).
*
*
* @param resource the resource name to find in a classloader
* @param searchSystemClassLoader true to search {@link ClassLoader#getSystemResource(String)}, false to skip
* @return The new Resource, which may be a {@link CombinedResource} if multiple directory resources are found.
* @throws IllegalArgumentException if resource name or resulting URL from ClassLoader is invalid.
*/
default Resource newClassLoaderResource(String resource, boolean searchSystemClassLoader)
{
if (StringUtil.isBlank(resource))
throw new IllegalArgumentException("Resource String is invalid: " + resource);
// We need a local interface to combine static and non-static methods
interface Source
{
Enumeration getResources(String name) throws IOException;
}
List