Package io.github.classgraph
Class ResourceList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<Resource>
-
- io.github.classgraph.ResourceList
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.AutoCloseable
,java.lang.Cloneable
,java.lang.Iterable<Resource>
,java.util.Collection<Resource>
,java.util.List<Resource>
,java.util.RandomAccess
public class ResourceList extends java.util.ArrayList<Resource> implements java.lang.AutoCloseable
An AutoCloseable list of AutoCloseableResource
objects.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ResourceList.ByteArrayConsumer
AFunctionalInterface
for consuming the contents of aResource
as a byte array.static interface
ResourceList.ByteBufferConsumer
static interface
ResourceList.InputStreamConsumer
static interface
ResourceList.ResourceFilter
Filter aResourceList
using a predicate mapping aResource
object to a boolean, producing anotherResourceList
for all items in the list for which the predicate is true.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,ResourceList>
asMap()
ResourceList
classFilesOnly()
void
close()
Close all theResource
objects in thisResourceList
.ResourceList
filter(ResourceList.ResourceFilter filter)
Find the subset of theResource
objects in this list for which the given filter predicate is true.java.util.List<java.util.Map.Entry<java.lang.String,ResourceList>>
findDuplicatePaths()
void
forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer)
Fetch the content of eachResource
in thisResourceList
as a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close()
.void
forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)
Fetch the content of eachResource
in thisResourceList
as a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close()
.void
forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)
Read eachResource
in thisResourceList
as aByteBuffer
, pass theByteBuffer
to the givenResourceList.InputStreamConsumer
, then release theByteBuffer
after theResourceList.ByteBufferConsumer
returns, by callingResource.close()
.void
forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)
Read eachResource
in thisResourceList
as aByteBuffer
, pass theByteBuffer
to the givenResourceList.InputStreamConsumer
, then release theByteBuffer
after theResourceList.ByteBufferConsumer
returns, by callingResource.close()
.void
forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)
Fetch anInputStream
for eachResource
in thisResourceList
, pass theInputStream
to the givenResourceList.InputStreamConsumer
, then close theInputStream
after theResourceList.InputStreamConsumer
returns, by callingResource.close()
.void
forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)
Fetch anInputStream
for eachResource
in thisResourceList
, pass theInputStream
to the givenResourceList.InputStreamConsumer
, then close theInputStream
after theResourceList.InputStreamConsumer
returns, by callingResource.close()
.java.util.List<java.lang.String>
getPaths()
java.util.List<java.lang.String>
getPathsRelativeToClasspathElement()
java.util.List<java.net.URL>
getURLs()
ResourceList
nonClassFilesOnly()
java.lang.String
toString()
-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Method Detail
-
getPaths
public java.util.List<java.lang.String> getPaths()
- Returns:
- The paths of all resources in this list relative to the package root of the classpath element, by
calling
Resource.getPath()
for each item in the list. For example, given a resource path of "BOOT-INF/classes/com/xyz/resource.xml" and a package root of "BOOT-INF/classes/", returns "com/xyz/resource.xml".
-
getPathsRelativeToClasspathElement
public java.util.List<java.lang.String> getPathsRelativeToClasspathElement()
- Returns:
- The paths of all resources in this list relative to the root of the classpath element, by calling
Resource.getPathRelativeToClasspathElement()
for each item in the list. For example, given a resource path of "BOOT-INF/classes/com/xyz/resource.xml", returns "BOOT-INF/classes/com/xyz/resource.xml" (even if the package root is "BOOT-INF/classes/").
-
getURLs
public java.util.List<java.net.URL> getURLs()
- Returns:
- The URLs of all resources in this list, by calling
Resource.getURL()
for each item in the list.
-
classFilesOnly
public ResourceList classFilesOnly()
- Returns:
- A new
ResourceList
consisting of only the resources with the filename extension ".class".
-
nonClassFilesOnly
public ResourceList nonClassFilesOnly()
- Returns:
- A new
ResourceList
consisting of only the resources that do not have the filename extension ".class".
-
asMap
public java.util.Map<java.lang.String,ResourceList> asMap()
- Returns:
- This
ResourceList
as a map from path (obtained fromResource.getPath()
), to aResourceList
ofResource
objects that have that path.
-
findDuplicatePaths
public java.util.List<java.util.Map.Entry<java.lang.String,ResourceList>> findDuplicatePaths()
- Returns:
- A
List
ofMap.Entry
objects for all resources in the classpath and/or module path that have a non-unique path (i.e. where there are at least two resources with the same path). The key of each returnedMap.Entry
is the path (obtained fromResource.getPath()
), and the value is aResourceList
of at least two uniqueResource
objects that have that path.
-
filter
public ResourceList filter(ResourceList.ResourceFilter filter)
Find the subset of theResource
objects in this list for which the given filter predicate is true.- Parameters:
filter
- TheResourceList.ResourceFilter
to apply.- Returns:
- The subset of the
Resource
objects in this list for which the given filter predicate is true.
-
forEachByteArray
public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)
Fetch the content of eachResource
in thisResourceList
as a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close()
.- Parameters:
byteArrayConsumer
- TheResourceList.ByteArrayConsumer
.ignoreIOExceptions
- if true, anyIOException
thrown while trying to load any of the resources will be silently ignored.- Throws:
java.lang.IllegalArgumentException
- if ignoreExceptions is false, and anIOException
is thrown while trying to load any of the resources.
-
forEachByteArray
public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer)
Fetch the content of eachResource
in thisResourceList
as a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close()
.- Parameters:
byteArrayConsumer
- TheResourceList.ByteArrayConsumer
.- Throws:
java.lang.IllegalArgumentException
- if trying to load any of the resources results in anIOException
being thrown.
-
forEachInputStream
public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)
Fetch anInputStream
for eachResource
in thisResourceList
, pass theInputStream
to the givenResourceList.InputStreamConsumer
, then close theInputStream
after theResourceList.InputStreamConsumer
returns, by callingResource.close()
.- Parameters:
inputStreamConsumer
- TheResourceList.InputStreamConsumer
.ignoreIOExceptions
- if true, anyIOException
thrown while trying to load any of the resources will be silently ignored.- Throws:
java.lang.IllegalArgumentException
- if ignoreExceptions is false, and anIOException
is thrown while trying to open any of the resources.
-
forEachInputStream
public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)
Fetch anInputStream
for eachResource
in thisResourceList
, pass theInputStream
to the givenResourceList.InputStreamConsumer
, then close theInputStream
after theResourceList.InputStreamConsumer
returns, by callingResource.close()
.- Parameters:
inputStreamConsumer
- TheResourceList.InputStreamConsumer
.- Throws:
java.lang.IllegalArgumentException
- if trying to open any of the resources results in anIOException
being thrown.
-
forEachByteBuffer
public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)
Read eachResource
in thisResourceList
as aByteBuffer
, pass theByteBuffer
to the givenResourceList.InputStreamConsumer
, then release theByteBuffer
after theResourceList.ByteBufferConsumer
returns, by callingResource.close()
.- Parameters:
byteBufferConsumer
- TheResourceList.ByteBufferConsumer
.ignoreIOExceptions
- if true, anyIOException
thrown while trying to load any of the resources will be silently ignored.- Throws:
java.lang.IllegalArgumentException
- if ignoreExceptions is false, and anIOException
is thrown while trying to load any of the resources.
-
forEachByteBuffer
public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)
Read eachResource
in thisResourceList
as aByteBuffer
, pass theByteBuffer
to the givenResourceList.InputStreamConsumer
, then release theByteBuffer
after theResourceList.ByteBufferConsumer
returns, by callingResource.close()
.- Parameters:
byteBufferConsumer
- TheResourceList.ByteBufferConsumer
.- Throws:
java.lang.IllegalArgumentException
- if trying to load any of the resources results in anIOException
being thrown.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractCollection<Resource>
-
close
public void close()
Close all theResource
objects in thisResourceList
.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-