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
ConstructorsConstructorDescriptionCreates a newCloseablesinstance.Closeables(Closeable... closeable) Creates a newCloseablesinstance, populating it with the givenCloseableobjects. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the given closeable.booleanadd(WeakReference<Closeable> closeable) Adds the given closeable, but only using a weak reference.voidclose()voidclose(IOException superException) Closes all registered closeables.booleanisClosed()Checks if this instance has been closed already.booleanRemoves the given closeable.
-
Constructor Details
-
Closeables
public Closeables()Creates a newCloseablesinstance. -
Closeables
Creates a newCloseablesinstance, populating it with the givenCloseableobjects.- Parameters:
closeable- TheCloseables to add.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
isClosed
public boolean isClosed()Checks if this instance has been closed already.- Returns:
trueif 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:
trueiff the closeable was added,falseif it wasnull, already added before, or if theCloseablesinstance has been closed already.
-
add
Adds the given closeable.- Parameters:
closeable- The closeable.- Returns:
trueiff the closeable was added,falseif it wasnullor already added before.
-
remove
Removes the given closeable.- Parameters:
closeable- The closeable.- Returns:
trueiff the closeable was removed,faleif it wasnullor not previously added.
-