Package io.github.classgraph
Class ResourceList
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<T>
io.github.classgraph.ResourceList
- All Implemented Interfaces:
Serializable,AutoCloseable,Cloneable,Iterable<Resource>,Collection<Resource>,List<Resource>,RandomAccess
public class ResourceList extends ArrayList<T> implements AutoCloseable
An AutoCloseable list of AutoCloseable
Resource objects.- 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. -
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(Collection<Resource> resourceCollection)Create a new modifiable emptyResourceList, given an initial collection ofResourceobjects. -
Method Summary
Modifier and Type Method Description voidadd(int index, T element)booleanadd(T element)booleanaddAll(int index, Collection<? extends T> c)booleanaddAll(Collection<? extends T> c)Map<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".voidclear()voidclose()Close all theResourceobjects in thisResourceList.static ResourceListemptyList()Return an unmodifiable emptyResourceList.booleanequals(Object o)ResourceListfilter(ResourceList.ResourceFilter filter)Find the subset of theResourceobjects in this list for which the given filter predicate is true.List<Map.Entry<String,ResourceList>>findDuplicatePaths()Find duplicate resource paths within thisResourceList.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().ResourceListget(String resourcePath)Returns a list of all resources with the requested path.List<String>getPaths()Get the paths of all resources in this list relative to the package root.List<String>getPathsRelativeToClasspathElement()Get the paths of all resources in this list relative to the root of the classpath element.List<URI>getURIs()Get the URIs of all resources in this list, by callingResource.getURI()for each item in the list.List<URL>getURLs()Get the URLs of all resources in this list, by callingResource.getURL()for each item in the list.inthashCode()Iterator<T>iterator()ListIterator<T>listIterator()ResourceListnonClassFilesOnly()Return a newResourceListconsisting of non-classfile resources only.Tremove(int index)booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)Tset(int index, T element)Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, lastIndexOf, listIterator, removeIf, replaceAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Constructor Details
-
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
Create a new modifiable emptyResourceList, given an initial collection ofResourceobjects.- Parameters:
resourceCollection- the collection ofResourceobjects.
-
-
Method Details
-
emptyList
Return an unmodifiable emptyResourceList.- Returns:
- the unmodifiable empty
ResourceList.
-
get
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
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
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
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
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
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
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
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
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
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:
IllegalArgumentException- if ignoreExceptions is false, and anIOExceptionis thrown while trying to load any of the resources.
-
forEachByteArray
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:
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:
IllegalArgumentException- if ignoreExceptions is false, and anIOExceptionis thrown while trying to open any of the resources.
-
forEachInputStream
Fetch anInputStreamfor eachResourcein thisResourceList, pass theInputStreamto the givenResourceList.InputStreamConsumer, then close theInputStreamafter theResourceList.InputStreamConsumerreturns, by callingResource.close().- Parameters:
inputStreamConsumer- TheResourceList.InputStreamConsumer.- Throws:
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:
IllegalArgumentException- if ignoreExceptions is false, and anIOExceptionis thrown while trying to load any of the resources.
-
forEachByteBuffer
Read eachResourcein thisResourceListas aByteBuffer, pass theByteBufferto the givenResourceList.InputStreamConsumer, then release theByteBufferafter theResourceList.ByteBufferConsumerreturns, by callingResource.close().- Parameters:
byteBufferConsumer- TheResourceList.ByteBufferConsumer.- Throws:
IllegalArgumentException- if trying to load any of the resources results in anIOExceptionbeing thrown.
-
close
public void close()Close all theResourceobjects in thisResourceList.- Specified by:
closein interfaceAutoCloseable
-
equals
-
hashCode
public int hashCode() -
add
public boolean add(T element) -
add
public void add(int index, T element) -
remove
-
remove
public T remove(int index) -
addAll
-
addAll
-
removeAll
-
retainAll
-
clear
public void clear() -
set
public T set(int index, T element) -
iterator
-
listIterator
- Specified by:
listIteratorin interfaceList<T>- Overrides:
listIteratorin classArrayList<T>
-