public class CompositeCloseable extends java.lang.Object implements java.io.Closeable, Cancelable
The class is thread safe.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
done
The done indicator.
|
protected java.util.List<java.io.Closeable> |
items
The list of items.
|
protected java.util.concurrent.locks.Lock |
lock
The lock guarding the items and done.
|
| Constructor and Description |
|---|
CompositeCloseable(java.io.Closeable... closeables)
Constructs the composite closeable with the supplied initial elements.
|
CompositeCloseable(int capacity)
Constructs a composite closeable where the backing list has the
supplied capacity.
|
CompositeCloseable(java.lang.Iterable<? extends java.io.Closeable> closeables)
Constructs the composite closeable with the supplied initial elements.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.io.Closeable... closeables)
Adds new closeables to this composite object.
|
void |
add(java.lang.Iterable<? extends java.io.Closeable> closeables)
Adds new closeables to this composite object.
|
void |
clear()
Closes the inner closeables but does not close this composite.
|
void |
close() |
void |
closeSilently()
Close this composite and ignore any IOExceptions.
|
boolean |
contains(java.io.Closeable c)
Returns true if the given closeable is in this composite.
|
boolean |
delete(java.io.Closeable c)
Removes the given closeable from this composite but does not close it.
|
boolean |
isClosed() |
boolean |
isEmpty() |
boolean |
remove(java.io.Closeable c)
Removes and closes the specified closeable instance if contained within this composite.
|
boolean |
removeSilently(java.io.Closeable c)
Removes and closes the specified closeable instance if
contained within this composite.
|
int |
size() |
protected final java.util.concurrent.locks.Lock lock
protected final java.util.List<java.io.Closeable> items
protected boolean done
public CompositeCloseable(int capacity)
capacity - the capacity value >= 1public CompositeCloseable(@Nonnull
java.io.Closeable... closeables)
closeables - the closeable elements to start withpublic CompositeCloseable(@Nonnull
java.lang.Iterable<? extends java.io.Closeable> closeables)
closeables - the closeable elements to start withpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic void add(java.io.Closeable... closeables)
closeables - the array of closeablespublic void add(java.lang.Iterable<? extends java.io.Closeable> closeables)
closeables - the sequence of closeablespublic boolean isClosed()
isClosed in interface Cancelablepublic int size()
public boolean remove(java.io.Closeable c)
throws java.io.IOException
c - the closeablejava.io.IOException - if the close method threw itpublic boolean removeSilently(java.io.Closeable c)
c - the closeablepublic boolean delete(java.io.Closeable c)
c - the closeable instancepublic void clear()
throws java.io.IOException
java.io.IOException - the exception(s) thrown by the close() callspublic boolean contains(java.io.Closeable c)
c - the closeable to testpublic void closeSilently()
public boolean isEmpty()