public class ResourceList extends ArrayList<T> implements AutoCloseable
Resource
objects.Modifier and Type | Class and Description |
---|---|
static interface |
ResourceList.ByteArrayConsumer
A
FunctionalInterface for consuming the contents of a Resource as a byte array. |
static interface |
ResourceList.ByteArrayConsumerThrowsIOException
A
FunctionalInterface for consuming the contents of a Resource as a byte array, throwing
IOException to the caller if an IO exception occurs. |
static interface |
ResourceList.ByteBufferConsumer
|
static interface |
ResourceList.ByteBufferConsumerThrowsIOException
A
FunctionalInterface for consuming the contents of a Resource as a ByteBuffer ,
throwing IOException to the caller if an IO exception occurs. |
static interface |
ResourceList.InputStreamConsumer
|
static interface |
ResourceList.InputStreamConsumerThrowsIOException
A
FunctionalInterface for consuming the contents of a Resource as an InputStream ,
throwing IOException to the caller if an IO exception occurs. |
static interface |
ResourceList.ResourceFilter
Filter a
ResourceList using a predicate mapping a Resource object to a boolean, producing
another ResourceList for all items in the list for which the predicate is true. |
Constructor and Description |
---|
ResourceList()
Create a new modifiable empty list of
Resource objects. |
ResourceList(Collection<Resource> resourceCollection)
Create a new modifiable empty
ResourceList , given an initial collection of Resource objects. |
ResourceList(int sizeHint)
Create a new modifiable empty list of
Resource objects, given a size hint. |
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
T element) |
boolean |
add(T element) |
boolean |
addAll(Collection<? extends T> c) |
boolean |
addAll(int index,
Collection<? extends T> c) |
Map<String,ResourceList> |
asMap()
Return this
ResourceList as a map from resource path (obtained from Resource.getPath() ) to a
ResourceList of Resource objects that have that path. |
ResourceList |
classFilesOnly()
Return a new
ResourceList consisting of only the resources with the filename extension ".class". |
void |
clear() |
void |
close()
Close all the
Resource objects in this ResourceList . |
static ResourceList |
emptyList()
Return an unmodifiable empty
ResourceList . |
boolean |
equals(Object o) |
ResourceList |
filter(ResourceList.ResourceFilter filter)
Find the subset of the
Resource objects in this list for which the given filter predicate is true. |
List<Map.Entry<String,ResourceList>> |
findDuplicatePaths()
Find duplicate resource paths within this
ResourceList . |
void |
forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer)
Deprecated.
|
void |
forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer,
boolean ignoreIOExceptions)
|
void |
forEachByteArrayIgnoringIOException(ResourceList.ByteArrayConsumer byteArrayConsumer)
Fetch the content of each
Resource in this ResourceList as a byte array, pass the byte array
to the given ResourceList.ByteArrayConsumer , then close the underlying InputStream or release the underlying
ByteBuffer by calling Resource.close() for each Resource . |
void |
forEachByteArrayThrowingIOException(ResourceList.ByteArrayConsumerThrowsIOException byteArrayConsumerThrowsIOException)
Fetch the content of each
Resource in this ResourceList as a byte array, pass the byte array
to the given ResourceList.ByteArrayConsumer , then close the underlying InputStream or release the underlying
ByteBuffer by calling Resource.close() . |
void |
forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)
Deprecated.
|
void |
forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer,
boolean ignoreIOExceptions)
|
void |
forEachByteBufferIgnoringIOException(ResourceList.ByteBufferConsumer byteBufferConsumer)
Read each
Resource in this ResourceList as a ByteBuffer , pass the ByteBuffer
to the given ResourceList.InputStreamConsumer , then release the ByteBuffer after the
ResourceList.ByteBufferConsumer returns, by calling Resource.close() for each Resource . |
void |
forEachByteBufferThrowingIOException(ResourceList.ByteBufferConsumerThrowsIOException byteBufferConsumerThrowsIOException)
Read each
Resource in this ResourceList as a ByteBuffer , pass the ByteBuffer
to the given ResourceList.InputStreamConsumer , then release the ByteBuffer after the
ResourceList.ByteBufferConsumer returns, by calling Resource.close() . |
void |
forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)
Deprecated.
|
void |
forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer,
boolean ignoreIOExceptions)
|
void |
forEachInputStreamIgnoringIOException(ResourceList.InputStreamConsumer inputStreamConsumer)
Fetch an
InputStream for each Resource in this ResourceList , pass the
InputStream to the given ResourceList.InputStreamConsumer , then close the InputStream after the
ResourceList.InputStreamConsumer returns, by calling Resource.close() for each Resource . |
void |
forEachInputStreamThrowingIOException(ResourceList.InputStreamConsumerThrowsIOException inputStreamConsumerThrowsIOException)
Fetch an
InputStream for each Resource in this ResourceList , pass the
InputStream to the given ResourceList.InputStreamConsumer , then close the InputStream after the
ResourceList.InputStreamConsumer returns, by calling Resource.close() . |
ResourceList |
get(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 calling
Resource.getURI() for each item in the list. |
List<URL> |
getURLs()
Get the URLs of all resources in this list, by calling
Resource.getURL() for each item in the list. |
int |
hashCode() |
Iterator<T> |
iterator() |
ListIterator<T> |
listIterator() |
ResourceList |
nonClassFilesOnly()
Return a new
ResourceList consisting of non-classfile resources only. |
T |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
T |
set(int index,
T element) |
clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, lastIndexOf, listIterator, removeIf, replaceAll, size, sort, spliterator, subList, toArray, toArray, trimToSize
containsAll, toString
containsAll
parallelStream, stream
public ResourceList()
Resource
objects.public ResourceList(int sizeHint)
Resource
objects, given a size hint.sizeHint
- the size hintpublic ResourceList(Collection<Resource> resourceCollection)
ResourceList
, given an initial collection of Resource
objects.resourceCollection
- the collection of Resource
objects.public static ResourceList emptyList()
ResourceList
.ResourceList
.public ResourceList get(String resourcePath)
ResourceList
rather than a
single Resource
.)resourcePath
- The path of a resourceResourceList
of Resource
objects 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 a ResourceList
rather than a single Resource
.) Returns the empty list if no
resource with is found with a matching path.public List<String> getPaths()
Resource.getPath()
for each item in the list.public List<String> getPathsRelativeToClasspathElement()
Resource.getPathRelativeToClasspathElement()
for each item in the list.public List<URL> getURLs()
Resource.getURL()
for each item in the list.
Note that any resource with a jrt:
URI (e.g. a system resource, or a resource from a jlink'd image)
will cause IllegalArgumentException
to be thrown, since URL
does not support this scheme, so
getURIs()
is strongly preferred over getURLs()
.public List<URI> getURIs()
Resource.getURI()
for each item in the list.public ResourceList classFilesOnly()
ResourceList
consisting of only the resources with the filename extension ".class".ResourceList
consisting of only the resources with the filename extension ".class".public ResourceList nonClassFilesOnly()
ResourceList
consisting of non-classfile resources only.ResourceList
consisting of only the resources that do not have the filename extension
".class".public Map<String,ResourceList> asMap()
ResourceList
as a map from resource path (obtained from Resource.getPath()
) to a
ResourceList
of Resource
objects that have that path.ResourceList
as a map from resource path (obtained from Resource.getPath()
) to a
ResourceList
of Resource
objects that have that path.public List<Map.Entry<String,ResourceList>> findDuplicatePaths()
ResourceList
.List
of Map.Entry
objects 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 returned Map.Entry
is the path (obtained from Resource.getPath()
), and the value is
a ResourceList
of at least two unique Resource
objects that have that path.public ResourceList filter(ResourceList.ResourceFilter filter)
Resource
objects in this list for which the given filter predicate is true.filter
- The ResourceList.ResourceFilter
to apply.Resource
objects in this list for which the given filter predicate is true.@Deprecated public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer, boolean ignoreIOExceptions)
forEachByteArrayIgnoringIOException(ByteArrayConsumer)
or
forEachByteArrayThrowingIOException(ByteArrayConsumerThrowsIOException)
instead.Resource
in this ResourceList
as a byte array, pass the byte array
to the given ResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying
ByteBuffer by calling Resource.close()
.byteArrayConsumer
- The ResourceList.ByteArrayConsumer
.ignoreIOExceptions
- if true, any IOException
thrown while trying to load any of the resources will be silently
ignored.IllegalArgumentException
- if ignoreExceptions is false, and an IOException
is thrown while trying to load any of
the resources.@Deprecated public void forEachByteArray(ResourceList.ByteArrayConsumer byteArrayConsumer)
forEachByteArrayThrowingIOException(ByteArrayConsumerThrowsIOException)
instead.Resource
in this ResourceList
as a byte array, pass the byte array
to the given ResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying
ByteBuffer by calling Resource.close()
.byteArrayConsumer
- The ResourceList.ByteArrayConsumer
.IllegalArgumentException
- if an IOException
is thrown while trying to load any of the resources.public void forEachByteArrayIgnoringIOException(ResourceList.ByteArrayConsumer byteArrayConsumer)
Resource
in this ResourceList
as a byte array, pass the byte array
to the given ResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying
ByteBuffer by calling Resource.close()
for each Resource
. If an IOException
occurs
while opening or reading from any resource, the resource is silently skipped.byteArrayConsumer
- The ResourceList.ByteArrayConsumer
.public void forEachByteArrayThrowingIOException(ResourceList.ByteArrayConsumerThrowsIOException byteArrayConsumerThrowsIOException) throws IOException
Resource
in this ResourceList
as a byte array, pass the byte array
to the given ResourceList.ByteArrayConsumer
, then close the underlying InputStream or release the underlying
ByteBuffer by calling Resource.close()
.byteArrayConsumerThrowsIOException
- The ResourceList.ByteArrayConsumerThrowsIOException
.IOException
- if trying to load any of the resources results in an IOException
being thrown.@Deprecated public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer, boolean ignoreIOExceptions)
forEachInputStreamIgnoringIOException(InputStreamConsumer)
or
forEachInputStreamThrowingIOException(InputStreamConsumerThrowsIOException)
instead.InputStream
for each Resource
in this ResourceList
, pass the
InputStream
to the given ResourceList.InputStreamConsumer
, then close the InputStream
after the
ResourceList.InputStreamConsumer
returns, by calling Resource.close()
for each Resource
.inputStreamConsumer
- The ResourceList.InputStreamConsumer
.ignoreIOExceptions
- if true, any IOException
thrown while trying to load any of the resources will be silently
ignored.IllegalArgumentException
- if ignoreExceptions is false, and an IOException
is thrown while trying to open any of
the resources.@Deprecated public void forEachInputStream(ResourceList.InputStreamConsumer inputStreamConsumer)
forEachInputStreamThrowingIOException(InputStreamConsumerThrowsIOException)
instead.InputStream
for each Resource
in this ResourceList
, pass the
InputStream
to the given ResourceList.InputStreamConsumer
, then close the InputStream
after the
ResourceList.InputStreamConsumer
returns, by calling Resource.close()
for each Resource
.inputStreamConsumer
- The ResourceList.InputStreamConsumer
.IllegalArgumentException
- an IOException
is thrown while trying to open any of the resources.public void forEachInputStreamIgnoringIOException(ResourceList.InputStreamConsumer inputStreamConsumer)
InputStream
for each Resource
in this ResourceList
, pass the
InputStream
to the given ResourceList.InputStreamConsumer
, then close the InputStream
after the
ResourceList.InputStreamConsumer
returns, by calling Resource.close()
for each Resource
. If an
IOException
occurs while opening or reading from any resource, the resource is silently skipped.inputStreamConsumer
- The ResourceList.InputStreamConsumer
.public void forEachInputStreamThrowingIOException(ResourceList.InputStreamConsumerThrowsIOException inputStreamConsumerThrowsIOException) throws IOException
InputStream
for each Resource
in this ResourceList
, pass the
InputStream
to the given ResourceList.InputStreamConsumer
, then close the InputStream
after the
ResourceList.InputStreamConsumer
returns, by calling Resource.close()
.inputStreamConsumerThrowsIOException
- The ResourceList.InputStreamConsumerThrowsIOException
.IOException
- if trying to open or read from any of the resources results in an IOException
being
thrown.@Deprecated public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer, boolean ignoreIOExceptions)
forEachByteBufferIgnoringIOException(ByteBufferConsumer)
or
forEachByteBufferThrowingIOException(ByteBufferConsumerThrowsIOException)
instead.Resource
in this ResourceList
as a ByteBuffer
, pass the ByteBuffer
to the given ResourceList.InputStreamConsumer
, then release the ByteBuffer
after the
ResourceList.ByteBufferConsumer
returns, by calling Resource.close()
for each Resource
.byteBufferConsumer
- The ResourceList.ByteBufferConsumer
.ignoreIOExceptions
- if true, any IOException
thrown while trying to load any of the resources will be silently
ignored.IllegalArgumentException
- if ignoreExceptions is false, and an IOException
is thrown while trying to load any of
the resources.@Deprecated public void forEachByteBuffer(ResourceList.ByteBufferConsumer byteBufferConsumer)
forEachByteBufferThrowingIOException(ByteBufferConsumerThrowsIOException)
instead.Resource
in this ResourceList
as a ByteBuffer
, pass the ByteBuffer
to the given ResourceList.InputStreamConsumer
, then release the ByteBuffer
after the
ResourceList.ByteBufferConsumer
returns, by calling Resource.close()
for each Resource
.byteBufferConsumer
- The ResourceList.ByteBufferConsumer
.IllegalArgumentException
- if an IOException
is thrown while trying to load any of the resources.public void forEachByteBufferIgnoringIOException(ResourceList.ByteBufferConsumer byteBufferConsumer)
Resource
in this ResourceList
as a ByteBuffer
, pass the ByteBuffer
to the given ResourceList.InputStreamConsumer
, then release the ByteBuffer
after the
ResourceList.ByteBufferConsumer
returns, by calling Resource.close()
for each Resource
. If an
IOException
occurs while opening or reading from any resource, the resource is silently skipped.byteBufferConsumer
- The ResourceList.ByteBufferConsumer
.public void forEachByteBufferThrowingIOException(ResourceList.ByteBufferConsumerThrowsIOException byteBufferConsumerThrowsIOException) throws IOException
Resource
in this ResourceList
as a ByteBuffer
, pass the ByteBuffer
to the given ResourceList.InputStreamConsumer
, then release the ByteBuffer
after the
ResourceList.ByteBufferConsumer
returns, by calling Resource.close()
.byteBufferConsumerThrowsIOException
- The ResourceList.ByteBufferConsumerThrowsIOException
.IOException
- if trying to load any of the resources results in an IOException
being thrown.public void close()
Resource
objects in this ResourceList
.close
in interface AutoCloseable
public boolean equals(Object o)
equals
in interface Collection<T>
equals
in interface List<T>
equals
in class AbstractList<T>
public int hashCode()
hashCode
in interface Collection<T>
hashCode
in interface List<T>
hashCode
in class AbstractList<T>
public boolean add(T element)
public void add(int index, T element)
public boolean remove(Object o)
public T remove(int index)
public boolean addAll(Collection<? extends T> c)
public boolean addAll(int index, Collection<? extends T> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public void clear()
public T set(int index, T element)
public Iterator<T> iterator()
public ListIterator<T> listIterator()
listIterator
in interface List<T>
listIterator
in class ArrayList<T>
Copyright © 2021. All rights reserved.