public class ClassPathUtils extends Object
Constructor and Description |
---|
ClassPathUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
consumeAsPath(URL url,
Consumer<Path> consumer)
Attempts to represent a resource as a local file system path to be processed by a consumer.
|
static void |
consumeAsPaths(ClassLoader cl,
String resource,
Consumer<Path> consumer)
Locates specified resources on the classpath and attempts to represent them as local file system paths
to be processed by a consumer.
|
static void |
consumeAsPaths(String resource,
Consumer<Path> consumer)
Invokes
consumeAsPaths(ClassLoader, String, Consumer) passing in
an instance of the current thread's context classloader as the classloader
from which to load the resources. |
static void |
consumeAsStreams(ClassLoader cl,
String resource,
Consumer<InputStream> consumer)
Locates all the occurrences of a resource on the classpath of the provided classloader
and invokes the consumer providing the input streams for each located resource.
|
static void |
consumeAsStreams(String resource,
Consumer<InputStream> consumer)
Invokes
consumeAsStreams(ClassLoader, String, Consumer) passing in
an instance of the current thread's context classloader as the classloader
from which to load the resources. |
static void |
consumeStream(URL url,
Consumer<InputStream> consumer)
Invokes a consumer providing the input streams to read the content of the URL.
|
static <R> R |
processAsPath(URL url,
Function<Path,R> function)
Attempts to represent a resource as a local file system path to be processed by a function.
|
static <R> R |
readStream(URL url,
Function<InputStream,R> function)
Invokes a function providing the input streams to read the content of the URL.
|
static Path |
toLocalPath(URL url)
Translates a URL to local file system path.
|
public static void consumeAsStreams(String resource, Consumer<InputStream> consumer) throws IOException
consumeAsStreams(ClassLoader, String, Consumer)
passing in
an instance of the current thread's context classloader as the classloader
from which to load the resources.resource
- resource pathconsumer
- resource input stream consumerIOException
- in case of an IO failurepublic static void consumeAsStreams(ClassLoader cl, String resource, Consumer<InputStream> consumer) throws IOException
URL.openStream()
which
in case the resource is found in an archive (such as JAR) locks the containing archive
even if the caller properly closes the stream.cl
- classloader to load the resources fromresource
- resource pathconsumer
- resource input stream consumerIOException
- in case of an IO failurepublic static void consumeAsPaths(String resource, Consumer<Path> consumer) throws IOException
consumeAsPaths(ClassLoader, String, Consumer)
passing in
an instance of the current thread's context classloader as the classloader
from which to load the resources.resource
- resource pathconsumer
- resource path consumerIOException
- in case of an IO failurepublic static void consumeAsPaths(ClassLoader cl, String resource, Consumer<Path> consumer) throws IOException
Path
in a FileSystem
representing the JAR.
If the protocol of the URL representing the resource is neither 'file' nor 'jar', the method will fail
with an exception.cl
- classloader to load the resources fromresource
- resource pathconsumer
- resource path consumerIOException
- in case of an IO failurepublic static void consumeAsPath(URL url, Consumer<Path> consumer)
Path
in a FileSystem
representing the JAR.
If the protocol of the URL representing the resource is neither 'file' nor 'jar', the method will fail
with an exception.url
- resource urlconsumer
- resource path consumerpublic static <R> R processAsPath(URL url, Function<Path,R> function)
Path
in a FileSystem
representing the JAR.
If the protocol of the URL representing the resource is neither 'file' nor 'jar', the method will fail
with an exception.url
- resource urlfunction
- resource path functionpublic static void consumeStream(URL url, Consumer<InputStream> consumer) throws IOException
URL.openStream()
which
in case the resource is found in an archive (such as JAR) locks the containing archive
even if the caller properly closes the stream.url
- URLconsumer
- input stream consumerIOException
- in case of an IO failurepublic static <R> R readStream(URL url, Function<InputStream,R> function) throws IOException
URL.openStream()
which
in case the resource is found in an archive (such as JAR) locks the containing archive
even if the caller properly closes the stream.url
- URLfunction
- input stream processing functionIOException
- in case of an IO failurepublic static Path toLocalPath(URL url)
IllegalArgumentException
will be thrown.url
- URLCopyright © 2020 JBoss by Red Hat. All rights reserved.