Package io.github.classgraph
Class ResourceList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<T>
-
- io.github.classgraph.PotentiallyUnmodifiableList<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 PotentiallyUnmodifiableList<Resource> implements java.lang.AutoCloseable
An AutoCloseable list of AutoCloseableResourceobjects.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceResourceList.ByteArrayConsumerAFunctionalInterfacefor consuming the contents of aResourceas a byte array.static interfaceResourceList.ByteArrayConsumerThrowsIOExceptionAFunctionalInterfacefor consuming the contents of aResourceas a byte array, throwingIOExceptionto the caller if an IO exception occurs.static interfaceResourceList.ByteBufferConsumerstatic interfaceResourceList.ByteBufferConsumerThrowsIOExceptionAFunctionalInterfacefor consuming the contents of aResourceas aByteBuffer, throwingIOExceptionto the caller if an IO exception occurs.static interfaceResourceList.InputStreamConsumerstatic interfaceResourceList.InputStreamConsumerThrowsIOExceptionAFunctionalInterfacefor consuming the contents of aResourceas anInputStream, throwingIOExceptionto the caller if an IO exception occurs.static interfaceResourceList.ResourceFilterFilter aResourceListusing a predicate mapping aResourceobject to a boolean, producing anotherResourceListfor all items in the list for which the predicate is true.
-
Field Summary
Fields Modifier and Type Field Description private static ResourceList.ResourceFilterCLASSFILE_FILTERReturns true if a Resource has a path ending in ".class".(package private) static ResourceListEMPTY_LISTAn unmodifiable emptyResourceList.(package private) static longserialVersionUIDserialVersionUID.-
Fields inherited from class io.github.classgraph.PotentiallyUnmodifiableList
modifiable
-
-
Constructor Summary
Constructors Constructor Description ResourceList()Create a new modifiable empty list ofResourceobjects.ResourceList(int sizeHint)Create a new modifiable empty list ofResourceobjects, given a size hint.ResourceList(java.util.Collection<Resource> resourceCollection)Create a new modifiable emptyResourceList, given an initial collection ofResourceobjects.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Map<java.lang.String,ResourceList>asMap()Return thisResourceListas a map from resource path (obtained fromResource.getPath()) to aResourceListofResourceobjects that have that path.ResourceListclassFilesOnly()Return a newResourceListconsisting of only the resources with the filename extension ".class".voidclose()Close all theResourceobjects in thisResourceList.static ResourceListemptyList()Return an unmodifiable emptyResourceList.ResourceListfilter(ResourceList.ResourceFilter filter)Find the subset of theResourceobjects in this list for which the given filter predicate is true.java.util.List<java.util.Map.Entry<java.lang.String,ResourceList>>findDuplicatePaths()Find duplicate resource paths within thisResourceList.voidforEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer)Deprecated.voidforEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)voidforEachByteArrayIgnoringIOException(ResourceList.ByteArrayConsumer byteArrayConsumer)Fetch the content of eachResourcein thisResourceListas a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close()for eachResource.voidforEachByteArrayThrowingIOException(ResourceList.ByteArrayConsumerThrowsIOException byteArrayConsumerThrowsIOException)Fetch the content of eachResourcein thisResourceListas a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close().voidforEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)Deprecated.voidforEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)voidforEachByteBufferIgnoringIOException(ResourceList.ByteBufferConsumer byteBufferConsumer)Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close()for eachResource.voidforEachByteBufferThrowingIOException(ResourceList.ByteBufferConsumerThrowsIOException byteBufferConsumerThrowsIOException)Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close().voidforEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)Deprecated.voidforEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)voidforEachInputStreamIgnoringIOException(ResourceList.InputStreamConsumer inputStreamConsumer)Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close()for eachResource.voidforEachInputStreamThrowingIOException(ResourceList.InputStreamConsumerThrowsIOException inputStreamConsumerThrowsIOException)Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close().ResourceListget(java.lang.String resourcePath)Returns a list of all resources with the requested path.java.util.List<java.lang.String>getPaths()Get the paths of all resources in this list relative to the package root.java.util.List<java.lang.String>getPathsRelativeToClasspathElement()Get the paths of all resources in this list relative to the root of the classpath element.java.util.List<java.net.URI>getURIs()Get the URIs of all resources in this list, by callingResource.getURI()for each item in the list.java.util.List<java.net.URL>getURLs()Get the URLs of all resources in this list, by callingResource.getURL()for each item in the list.ResourceListnonClassFilesOnly()Return a newResourceListconsisting of non-classfile resources only.-
Methods inherited from class io.github.classgraph.PotentiallyUnmodifiableList
add, add, addAll, addAll, clear, equals, hashCode, iterator, listIterator, makeUnmodifiable, remove, remove, removeAll, retainAll, set
-
Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, lastIndexOf, listIterator, removeIf, removeRange, replaceAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
-
-
-
Field Detail
-
serialVersionUID
static final long serialVersionUID
serialVersionUID.- See Also:
- Constant Field Values
-
EMPTY_LIST
static final ResourceList EMPTY_LIST
An unmodifiable emptyResourceList.
-
CLASSFILE_FILTER
private static final ResourceList.ResourceFilter CLASSFILE_FILTER
Returns true if a Resource has a path ending in ".class".
-
-
Constructor Detail
-
ResourceList
public ResourceList()
Create a new modifiable empty list ofResourceobjects.
-
ResourceList
public ResourceList(int sizeHint)
Create a new modifiable empty list ofResourceobjects, given a size hint.- Parameters:
sizeHint- the size hint
-
ResourceList
public ResourceList(java.util.Collection<Resource> resourceCollection)
Create a new modifiable emptyResourceList, given an initial collection ofResourceobjects.- Parameters:
resourceCollection- the collection ofResourceobjects.
-
-
Method Detail
-
emptyList
public static ResourceList emptyList()
Return an unmodifiable emptyResourceList.- Returns:
- the unmodifiable empty
ResourceList.
-
get
public ResourceList get(java.lang.String resourcePath)
Returns a list of all resources with the requested path. (There may be more than one resource with a given path, from different classpath elements or modules, so this returns aResourceListrather than a singleResource.)- Parameters:
resourcePath- The path of a resource- Returns:
- A
ResourceListofResourceobjects in this list that have the given path (there may be more than one resource with a given path, from different classpath elements or modules, so this returns aResourceListrather than a singleResource.) Returns the empty list if no resource with is found with a matching path.
-
getPaths
public java.util.List<java.lang.String> getPaths()
Get the paths of all resources in this list relative to the package root.- Returns:
- The paths of all resources in this list relative to the package root, by calling
Resource.getPath()for each item in the list.
-
getPathsRelativeToClasspathElement
public java.util.List<java.lang.String> getPathsRelativeToClasspathElement()
Get the paths of all resources in this list relative to the root of the classpath element.- 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.
-
getURLs
public java.util.List<java.net.URL> getURLs()
Get the URLs of all resources in this list, by callingResource.getURL()for each item in the list. Note that any resource with ajrt:URI (e.g. a system resource, or a resource from a jlink'd image) will causeIllegalArgumentExceptionto be thrown, sinceURLdoes not support this scheme, sogetURIs()is strongly preferred overgetURLs().- Returns:
- The URLs of all resources in this list.
-
getURIs
public java.util.List<java.net.URI> getURIs()
Get the URIs of all resources in this list, by callingResource.getURI()for each item in the list.- Returns:
- The URIs of all resources in this list.
-
classFilesOnly
public ResourceList classFilesOnly()
Return a newResourceListconsisting of only the resources with the filename extension ".class".- Returns:
- A new
ResourceListconsisting of only the resources with the filename extension ".class".
-
nonClassFilesOnly
public ResourceList nonClassFilesOnly()
Return a newResourceListconsisting of non-classfile resources only.- Returns:
- A new
ResourceListconsisting of only the resources that do not have the filename extension ".class".
-
asMap
public java.util.Map<java.lang.String,ResourceList> asMap()
Return thisResourceListas a map from resource path (obtained fromResource.getPath()) to aResourceListofResourceobjects that have that path.- Returns:
- This
ResourceListas a map from resource path (obtained fromResource.getPath()) to aResourceListofResourceobjects that have that path.
-
findDuplicatePaths
public java.util.List<java.util.Map.Entry<java.lang.String,ResourceList>> findDuplicatePaths()
Find duplicate resource paths within thisResourceList.- Returns:
- A
ListofMap.Entryobjects 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.Entryis the path (obtained fromResource.getPath()), and the value is aResourceListof at least two uniqueResourceobjects that have that path.
-
filter
public ResourceList filter(ResourceList.ResourceFilter filter)
Find the subset of theResourceobjects in this list for which the given filter predicate is true.- Parameters:
filter- TheResourceList.ResourceFilterto apply.- Returns:
- The subset of the
Resourceobjects in this list for which the given filter predicate is true.
-
forEachByteArray
@Deprecated public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)
Deprecated.Fetch the content of eachResourcein thisResourceListas 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, anyIOExceptionthrown while trying to load any of the resources will be silently ignored.- Throws:
java.lang.IllegalArgumentException- if ignoreExceptions is false, and anIOExceptionis thrown while trying to load any of the resources.
-
forEachByteArray
@Deprecated public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer)
Deprecated.Fetch the content of eachResourcein thisResourceListas 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 anIOExceptionis thrown while trying to load any of the resources.
-
forEachByteArrayIgnoringIOException
public void forEachByteArrayIgnoringIOException(ResourceList.ByteArrayConsumer byteArrayConsumer)
Fetch the content of eachResourcein thisResourceListas a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close()for eachResource. If anIOExceptionoccurs while opening or reading from any resource, the resource is silently skipped.- Parameters:
byteArrayConsumer- TheResourceList.ByteArrayConsumer.
-
forEachByteArrayThrowingIOException
public void forEachByteArrayThrowingIOException(ResourceList.ByteArrayConsumerThrowsIOException byteArrayConsumerThrowsIOException) throws java.io.IOException
Fetch the content of eachResourcein thisResourceListas 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:
byteArrayConsumerThrowsIOException- TheResourceList.ByteArrayConsumerThrowsIOException.- Throws:
java.io.IOException- if trying to load any of the resources results in anIOExceptionbeing thrown.
-
forEachInputStream
@Deprecated public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)
Deprecated.Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close()for eachResource.- Parameters:
inputStreamConsumer- TheResourceList.InputStreamConsumer.ignoreIOExceptions- if true, anyIOExceptionthrown while trying to load any of the resources will be silently ignored.- Throws:
java.lang.IllegalArgumentException- if ignoreExceptions is false, and anIOExceptionis thrown while trying to open any of the resources.
-
forEachInputStream
@Deprecated public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)
Deprecated.Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close()for eachResource.- Parameters:
inputStreamConsumer- TheResourceList.InputStreamConsumer.- Throws:
java.lang.IllegalArgumentException- anIOExceptionis thrown while trying to open any of the resources.
-
forEachInputStreamIgnoringIOException
public void forEachInputStreamIgnoringIOException(ResourceList.InputStreamConsumer inputStreamConsumer)
Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close()for eachResource. If anIOExceptionoccurs while opening or reading from any resource, the resource is silently skipped.- Parameters:
inputStreamConsumer- TheResourceList.InputStreamConsumer.
-
forEachInputStreamThrowingIOException
public void forEachInputStreamThrowingIOException(ResourceList.InputStreamConsumerThrowsIOException inputStreamConsumerThrowsIOException) throws java.io.IOException
Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close().- Parameters:
inputStreamConsumerThrowsIOException- TheResourceList.InputStreamConsumerThrowsIOException.- Throws:
java.io.IOException- if trying to open or read from any of the resources results in anIOExceptionbeing thrown.
-
forEachByteBuffer
@Deprecated public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)
Deprecated.Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close()for eachResource.- Parameters:
byteBufferConsumer- TheResourceList.ByteBufferConsumer.ignoreIOExceptions- if true, anyIOExceptionthrown while trying to load any of the resources will be silently ignored.- Throws:
java.lang.IllegalArgumentException- if ignoreExceptions is false, and anIOExceptionis thrown while trying to load any of the resources.
-
forEachByteBuffer
@Deprecated public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)
Deprecated.Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close()for eachResource.- Parameters:
byteBufferConsumer- TheResourceList.ByteBufferConsumer.- Throws:
java.lang.IllegalArgumentException- if anIOExceptionis thrown while trying to load any of the resources.
-
forEachByteBufferIgnoringIOException
public void forEachByteBufferIgnoringIOException(ResourceList.ByteBufferConsumer byteBufferConsumer)
Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close()for eachResource. If anIOExceptionoccurs while opening or reading from any resource, the resource is silently skipped.- Parameters:
byteBufferConsumer- TheResourceList.ByteBufferConsumer.
-
forEachByteBufferThrowingIOException
public void forEachByteBufferThrowingIOException(ResourceList.ByteBufferConsumerThrowsIOException byteBufferConsumerThrowsIOException) throws java.io.IOException
Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close().- Parameters:
byteBufferConsumerThrowsIOException- TheResourceList.ByteBufferConsumerThrowsIOException.- Throws:
java.io.IOException- if trying to load any of the resources results in anIOExceptionbeing thrown.
-
close
public void close()
Close all theResourceobjects in thisResourceList.- Specified by:
closein interfacejava.lang.AutoCloseable
-
-