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 AutoCloseableResource
objects.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ResourceList.ByteArrayConsumer
AFunctionalInterface
for consuming the contents of aResource
as a byte array.static interface
ResourceList.ByteBufferConsumer
static interface
ResourceList.InputStreamConsumer
static interface
ResourceList.ResourceFilter
Filter aResourceList
using a predicate mapping aResource
object to a boolean, producing anotherResourceList
for 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 void
close()
Close all theResource
objects in thisResourceList
.ResourceList
filter(ResourceList.ResourceFilter filter)
Find the subset of theResource
objects in this list for which the given filter predicate is true.void
forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer)
Fetch the content of eachResource
in thisResourceList
as a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close()
.void
forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)
Fetch the content of eachResource
in thisResourceList
as a byte array, pass the byte array to the givenResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying ByteBuffer by callingResource.close()
.void
forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)
Read eachResource
in thisResourceList
as aByteBuffer
, pass theByteBuffer
to the givenResourceList.InputStreamConsumer
, then release theByteBuffer
after theResourceList.ByteBufferConsumer
returns, by callingResource.close()
.void
forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)
Read eachResource
in thisResourceList
as aByteBuffer
, pass theByteBuffer
to the givenResourceList.InputStreamConsumer
, then release theByteBuffer
after theResourceList.ByteBufferConsumer
returns, by callingResource.close()
.void
forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)
Fetch anInputStream
for eachResource
in thisResourceList
, pass theInputStream
to the givenResourceList.InputStreamConsumer
, then close theInputStream
after theResourceList.InputStreamConsumer
returns, by callingResource.close()
.void
forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)
Fetch anInputStream
for eachResource
in thisResourceList
, pass theInputStream
to the givenResourceList.InputStreamConsumer
, then close theInputStream
after theResourceList.InputStreamConsumer
returns, by callingResource.close()
.List<String>
getPaths()
Returns a list containing the path of eachResource
in this list, relative to the package root within its respective classpath element.List<URL>
getURLs()
Returns a list of the URLs of eachResource
in this list.String
toString()
-
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 eachResource
in this list, relative to the package root within its respective classpath element.
-
filter
public ResourceList filter(ResourceList.ResourceFilter filter)
Find the subset of theResource
objects in this list for which the given filter predicate is true.- Parameters:
filter
- TheResourceList.ResourceFilter
to apply.- Returns:
- The subset of the
Resource
objects in this list for which the given filter predicate is true.
-
forEachByteArray
public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)
Fetch the content of eachResource
in thisResourceList
as 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, anyIOException
thrown while trying to load any of the resources will be silently ignored.- Throws:
IllegalArgumentException
- if ignoreExceptions is false, and anIOException
is thrown while trying to load any of the resources.
-
forEachByteArray
public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer)
Fetch the content of eachResource
in thisResourceList
as 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 anIOException
being thrown.
-
forEachInputStream
public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)
Fetch anInputStream
for eachResource
in thisResourceList
, pass theInputStream
to the givenResourceList.InputStreamConsumer
, then close theInputStream
after theResourceList.InputStreamConsumer
returns, by callingResource.close()
.- Parameters:
inputStreamConsumer
- TheResourceList.InputStreamConsumer
.ignoreIOExceptions
- if true, anyIOException
thrown while trying to load any of the resources will be silently ignored.- Throws:
IllegalArgumentException
- if ignoreExceptions is false, and anIOException
is thrown while trying to open any of the resources.
-
forEachInputStream
public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)
Fetch anInputStream
for eachResource
in thisResourceList
, pass theInputStream
to the givenResourceList.InputStreamConsumer
, then close theInputStream
after theResourceList.InputStreamConsumer
returns, by callingResource.close()
.- Parameters:
inputStreamConsumer
- TheResourceList.InputStreamConsumer
.- Throws:
IllegalArgumentException
- if trying to open any of the resources results in anIOException
being thrown.
-
forEachByteBuffer
public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)
Read eachResource
in thisResourceList
as aByteBuffer
, pass theByteBuffer
to the givenResourceList.InputStreamConsumer
, then release theByteBuffer
after theResourceList.ByteBufferConsumer
returns, by callingResource.close()
.- Parameters:
byteBufferConsumer
- TheResourceList.ByteBufferConsumer
.ignoreIOExceptions
- if true, anyIOException
thrown while trying to load any of the resources will be silently ignored.- Throws:
IllegalArgumentException
- if ignoreExceptions is false, and anIOException
is thrown while trying to load any of the resources.
-
forEachByteBuffer
public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)
Read eachResource
in thisResourceList
as aByteBuffer
, pass theByteBuffer
to the givenResourceList.InputStreamConsumer
, then release theByteBuffer
after theResourceList.ByteBufferConsumer
returns, by callingResource.close()
.- Parameters:
byteBufferConsumer
- TheResourceList.ByteBufferConsumer
.- Throws:
IllegalArgumentException
- if trying to load any of the resources results in anIOException
being thrown.
-
toString
public String toString()
- Overrides:
toString
in classAbstractCollection<Resource>
-
close
public void close()
Close all theResource
objects in thisResourceList
.- Specified by:
close
in interfaceAutoCloseable
-
-