Top Description Inners Fields Constructors Methods
org.newsclub.net.unix

public final Class Closeables

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .IOException, java.lang.ref.WeakReference, java.util.ArrayList, .Iterator, .List

A set of Closeables that can be closed at once.
Author
Christian Kohlschütter

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private List<WeakReference<Closeable>>

Constructor Summary

AccessConstructor and Description
public
Closeables()

Creates a new Closeables instance.

public
Closeables(Closeable...
The Closeables to add.
closeable
)

Creates a new Closeables instance, populating it with the given Closeable objects.

Method Summary

Modifier and TypeMethod and Description
public synchronized boolean

Returns:

true iff the closeable was added, false if it was null, already added before, or if the Closeables instance has been closed already.
add
(WeakReference<Closeable>
The closeable.
closeable
)

Adds the given closeable, but only using a weak reference.

public synchronized boolean

Returns:

true iff the closeable was added, false if it was null or already added before.
add
(Closeable
The closeable.
closeable
)

Adds the given closeable.

public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public void
close(IOException
If set, any exceptions thrown in here will be chained to the given exception via addSuppressed, and then thrown.
superException
)

Closes all registered closeables.

public synchronized boolean

Returns:

true if closed.
isClosed
()

Checks if this instance has been closed already.

public synchronized boolean

Returns:

true iff the closeable was removed, fale if it was null or not previously added.
remove
(Closeable
The closeable.
closeable
)

Removes the given closeable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private boolean closed
listback to summary
private List<WeakReference<Closeable>> list

Constructor Detail

Closeablesback to summary
public Closeables()

Creates a new Closeables instance.

Closeablesback to summary
public Closeables(Closeable... closeable)

Creates a new Closeables instance, populating it with the given Closeable objects.

Parameters
closeable:Closeable[]

The Closeables to add.

Method Detail

addback to summary
public synchronized boolean add(WeakReference<Closeable> closeable)

Adds the given closeable, but only using a weak reference.

Parameters
closeable:WeakReference<Closeable>

The closeable.

Returns:boolean

true iff the closeable was added, false if it was null, already added before, or if the Closeables instance has been closed already.

addback to summary
public synchronized boolean add(Closeable closeable)

Adds the given closeable.

Parameters
closeable:Closeable

The closeable.

Returns:boolean

true iff the closeable was added, false if it was null or already added before.

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
closeback to summary
public void close(IOException superException) throws IOException

Closes all registered closeables.

Parameters
superException:IOException

If set, any exceptions thrown in here will be chained to the given exception via addSuppressed, and then thrown.

Exceptions
IOException:
if an exception occurs.
isClosedback to summary
public synchronized boolean isClosed()

Checks if this instance has been closed already.

Returns:boolean

true if closed.

removeback to summary
public synchronized boolean remove(Closeable closeable)

Removes the given closeable.

Parameters
closeable:Closeable

The closeable.

Returns:boolean

true iff the closeable was removed, fale if it was null or not previously added.

org.newsclub.net.unix back to summary

private final Class Closeables.HardReference<V>

extends WeakReference<V>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final V

Constructor Summary

AccessConstructor and Description
pack-priv
HardReference(final V referent)

Method Summary

Modifier and TypeMethod and Description
public V
get()

Overrides java.lang.ref.Reference.get.

Returns this reference object's referent.

Field Detail

strongRefback to summary
private final V strongRef

Constructor Detail

HardReferenceback to summary
pack-priv HardReference(final V referent)
Annotations
@SuppressWarnings:null

Method Detail

getback to summary
public V get()

Overrides java.lang.ref.Reference.get.

Doc from java.lang.ref.Reference.get.

Returns this reference object's referent. If this reference object has been cleared, either by the program or by the garbage collector, then this method returns null.

Returns:V

The object to which this reference refers, or null if this reference object has been cleared

Annotations
@Override