java.lang.Object
org.newsclub.net.unix.Closeables
- All Implemented Interfaces:
Closeable
,AutoCloseable
A set of
Closeables
that can be closed at once.- Author:
- Christian Kohlschütter
-
Constructor Summary
ConstructorDescriptionCreates a newCloseables
instance.Closeables
(Closeable... closeable) Creates a newCloseables
instance, populating it with the givenCloseable
objects. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds the given closeable.boolean
add
(WeakReference<Closeable> closeable) Adds the given closeable, but only using a weak reference.void
close()
void
close
(IOException superException) Closes all registered closeables.boolean
isClosed()
Checks if this instance has been closed already.boolean
Removes the given closeable.
-
Constructor Details
-
Closeables
public Closeables()Creates a newCloseables
instance. -
Closeables
Creates a newCloseables
instance, populating it with the givenCloseable
objects.- Parameters:
closeable
- TheCloseable
s to add.
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
isClosed
public boolean isClosed()Checks if this instance has been closed already.- Returns:
true
if closed.
-
close
Closes all registered closeables.- Parameters:
superException
- If set, any exceptions thrown in here will be chained to the given exception via addSuppressed, and then thrown.- Throws:
IOException
- if an exception occurs.
-
add
Adds the given closeable, but only using a weak reference.- Parameters:
closeable
- The closeable.- Returns:
true
iff the closeable was added,false
if it wasnull
, already added before, or if theCloseables
instance has been closed already.
-
add
Adds the given closeable.- Parameters:
closeable
- The closeable.- Returns:
true
iff the closeable was added,false
if it wasnull
or already added before.
-
remove
Removes the given closeable.- Parameters:
closeable
- The closeable.- Returns:
true
iff the closeable was removed,fale
if it wasnull
or not previously added.
-