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 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.ByteBufferConsumerstatic interfaceResourceList.InputStreamConsumerstatic interfaceResourceList.ResourceFilterFilter aResourceListusing a predicate mapping aResourceobject to a boolean, producing anotherResourceListfor 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()ResourceListclassFilesOnly()voidclose()Close all theResourceobjects in thisResourceList.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()voidforEachByteArray(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().voidforEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)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)Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close().voidforEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close().voidforEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close().voidforEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close().java.util.List<java.lang.String>getPaths()java.util.List<java.lang.String>getPathsRelativeToClasspathElement()java.util.List<java.net.URL>getURLs()ResourceListnonClassFilesOnly()java.lang.StringtoString()-
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
ResourceListconsisting of only the resources with the filename extension ".class".
-
nonClassFilesOnly
public ResourceList nonClassFilesOnly()
- 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()
- Returns:
- This
ResourceListas a map from path (obtained fromResource.getPath()), to aResourceListofResourceobjects that have that path.
-
findDuplicatePaths
public java.util.List<java.util.Map.Entry<java.lang.String,ResourceList>> findDuplicatePaths()
- 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
public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)
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
public void forEachByteArray(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().- Parameters:
byteArrayConsumer- TheResourceList.ByteArrayConsumer.- Throws:
java.lang.IllegalArgumentException- if trying to load any of the resources results in anIOExceptionbeing thrown.
-
forEachInputStream
public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)
Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close().- 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
public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)
Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close().- Parameters:
inputStreamConsumer- TheResourceList.InputStreamConsumer.- Throws:
java.lang.IllegalArgumentException- if trying to open any of the resources results in anIOExceptionbeing thrown.
-
forEachByteBuffer
public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)
Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close().- 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
public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)
Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close().- Parameters:
byteBufferConsumer- TheResourceList.ByteBufferConsumer.- Throws:
java.lang.IllegalArgumentException- if trying to load any of the resources results in anIOExceptionbeing thrown.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<Resource>
-
close
public void close()
Close all theResourceobjects in thisResourceList.- Specified by:
closein interfacejava.lang.AutoCloseable
-
-