Package io.quarkus.runtime.util
Class ClassPathUtils
java.lang.Object
io.quarkus.runtime.util.ClassPathUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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) InvokesconsumeAsPaths(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) InvokesconsumeAsStreams(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.static String
toResourceName
(Path path) Translates a file system-specific path to a Java classpath resource name that uses '/' as a separator.
-
Constructor Details
-
ClassPathUtils
public ClassPathUtils()
-
-
Method Details
-
toResourceName
Translates a file system-specific path to a Java classpath resource name that uses '/' as a separator.- Parameters:
path
- file system path- Returns:
- Java classpath resource name
-
consumeAsStreams
public static void consumeAsStreams(String resource, Consumer<InputStream> consumer) throws IOException InvokesconsumeAsStreams(ClassLoader, String, Consumer)
passing in an instance of the current thread's context classloader as the classloader from which to load the resources.- Parameters:
resource
- resource pathconsumer
- resource input stream consumer- Throws:
IOException
- in case of an IO failure
-
consumeAsStreams
public static void consumeAsStreams(ClassLoader cl, String resource, Consumer<InputStream> consumer) throws IOException 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. The consumer does not have to close the provided input stream. This method was introduced to avoid callingURL.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.- Parameters:
cl
- classloader to load the resources fromresource
- resource pathconsumer
- resource input stream consumer- Throws:
IOException
- in case of an IO failure
-
consumeAsPaths
InvokesconsumeAsPaths(ClassLoader, String, Consumer)
passing in an instance of the current thread's context classloader as the classloader from which to load the resources.- Parameters:
resource
- resource pathconsumer
- resource path consumer- Throws:
IOException
- in case of an IO failure
-
consumeAsPaths
public static void consumeAsPaths(ClassLoader cl, String resource, Consumer<Path> consumer) throws IOException Locates specified resources on the classpath and attempts to represent them as local file system paths to be processed by a consumer. If a resource appears to be an actual file or a directory, it is simply passed to the consumer as-is. If a resource is an entry in a JAR, the entry will be resolved as an instance ofPath
in aFileSystem
representing the JAR. If the protocol of the URL representing the resource is neither 'file' nor 'jar', the method will fail with an exception.- Parameters:
cl
- classloader to load the resources fromresource
- resource pathconsumer
- resource path consumer- Throws:
IOException
- in case of an IO failure
-
consumeAsPath
Attempts to represent a resource as a local file system path to be processed by a consumer. If a resource appears to be an actual file or a directory, it is simply passed to the consumer as-is. If a resource is an entry in a JAR, the entry will be resolved as an instance ofPath
in aFileSystem
representing the JAR. If the protocol of the URL representing the resource is neither 'file' nor 'jar', the method will fail with an exception.- Parameters:
url
- resource urlconsumer
- resource path consumer
-
processAsPath
Attempts to represent a resource as a local file system path to be processed by a function. If a resource appears to be an actual file or a directory, it is simply passed to the function as-is. If a resource is an entry in a JAR, the entry will be resolved as an instance ofPath
in aFileSystem
representing the JAR. If the protocol of the URL representing the resource is neither 'file' nor 'jar', the method will fail with an exception.- Parameters:
url
- resource urlfunction
- resource path function
-
consumeStream
Invokes a consumer providing the input streams to read the content of the URL. The consumer does not have to close the provided input stream. This method was introduced to avoid callingURL.openStream()
directly, 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.- Parameters:
url
- URLconsumer
- input stream consumer- Throws:
IOException
- in case of an IO failure
-
readStream
Invokes a function providing the input streams to read the content of the URL. The function does not have to close the provided input stream. This method was introduced to avoid callingURL.openStream()
directly, 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.- Parameters:
url
- URLfunction
- input stream processing function- Throws:
IOException
- in case of an IO failure
-
toLocalPath
Translates a URL to local file system path. In case the URL couldn't be translated to a file system path, an instance ofIllegalArgumentException
will be thrown.- Parameters:
url
- URL- Returns:
- local file system path
-