- java.lang.Object
-
- org.newsclub.net.unix.Closeables
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class Closeables extends java.lang.Object implements java.io.CloseableA set ofCloseablesthat can be closed at once.- Author:
- Christian Kohlschütter
-
-
Constructor Summary
Constructors Constructor Description Closeables()Closeables(java.io.Closeable... closeable)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.io.Closeable closeable)Adds the given closeable.booleanadd(java.lang.ref.WeakReference<java.io.Closeable> closeable)Adds the given closeable, but only using a weak reference.voidclose()voidclose(java.io.IOException superException)Closes all registered closeables.booleanremove(java.io.Closeable closeable)Removes the given closeable.
-
-
-
Method Detail
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
close
public void close(java.io.IOException superException) throws java.io.IOExceptionCloses 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:
java.io.IOException- if an exception occurs.
-
add
public boolean add(java.lang.ref.WeakReference<java.io.Closeable> closeable)
Adds the given closeable, but only using a weak reference.- Parameters:
closeable- The closeable.- Returns:
trueiff the closeable was added,falseif it wasnullor already added before.
-
add
public boolean add(java.io.Closeable closeable)
Adds the given closeable.- Parameters:
closeable- The closeable.- Returns:
trueiff the closeable was added,falseif it wasnullor already added before.
-
remove
public boolean remove(java.io.Closeable closeable)
Removes the given closeable.- Parameters:
closeable- The closeable.- Returns:
trueiff the closeable was removed,faleif it wasnullor not previously added.
-
-