Package io.github.fastclasspathscanner
Class ResourceList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<Resource>
-
- io.github.fastclasspathscanner.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
-
-
Constructor Summary
Constructors Constructor Description ResourceList()ResourceList(int sizeHint)ResourceList(Collection<Resource> collection)
-
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()Returns a list containing the path of eachResourcein this list, relative to the package root within its respective classpath element.List<URL>getURLs()Returns a list of the URLs of eachResourcein this list.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
-
-
-
-
Constructor Detail
-
ResourceList
public ResourceList()
-
ResourceList
public ResourceList(int sizeHint)
-
ResourceList
public ResourceList(Collection<Resource> collection)
-
-
Method Detail
-
getPaths
public List<String> getPaths()
Returns a list containing the path of eachResourcein this list, relative to the package root within its respective classpath element.
-
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
-
-