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:
Serializable,AutoCloseable,Cloneable,Iterable<Resource>,Collection<Resource>,List<Resource>,RandomAccess
public class ResourceList extends ArrayList<Resource> implements 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.
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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().List<String>getPaths()List<String>getPathsRelativeToClasspathElement()List<URL>getURLs()StringtoString()-
Methods inherited from class java.util.AbstractCollection
containsAll
-
Methods inherited from class java.util.AbstractList
equals, hashCode
-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from interface java.util.Collection
parallelStream, stream
-
Methods inherited from interface java.util.List
containsAll, equals, hashCode
-
-
-
-
Method Detail
-
getPaths
public List<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 List<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 List<URL> getURLs()
- Returns:
- The URLs of all resources in this list, by calling
Resource.getURL()for each item in the list.
-
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:
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:
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
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:
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
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:
IllegalArgumentException- if trying to load any of the resources results in anIOExceptionbeing thrown.
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<Resource>
-
close
public void close()
Close all theResourceobjects in thisResourceList.- Specified by:
closein interfaceAutoCloseable
-
-