public interface Closeable extends Closeable, QueryCloseable
Closeable is a source or destination of data that can be closed. The close method
is invoked to release resources that the object is holding (such as open files).
This interface is an extension of Closeable and QueryCloseable,
adding functionality for handling more resource types and closing them quietly without
throwing exceptions.
It is encouraged to use this interface in a try-with-resources statement.
Implementations of this interface should also consider extending AbstractCloseable
which provides common functionalities for closeable resources.
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this resource, releasing any system resources associated with it.
|
static void |
closeQuietly(Object... closeables)
Closes multiple closeable objects quietly, without throwing exceptions.
|
static void |
closeQuietly(@Nullable Object o)
Closes a single closeable object quietly, without throwing exceptions.
|
isClosed, isClosingstatic void closeQuietly(@Nullable
Object... closeables)
Example:
Closeable.closeQuietly(fileInputStream, socketChannel, listOfStreams);
closeables - the array of objects to be closedAbstractCloseable.performClose()static void closeQuietly(@Nullable
@Nullable Object o)
Example:
Closeable.closeQuietly(fileInputStream);
o - the object to be closedAbstractCloseable.performClose()void close()
Subclasses should override AbstractCloseable.performClose() to provide
the actual close logic.
close in interface AutoCloseableclose in interface CloseableIllegalStateException - if the resource cannot be closed.AbstractCloseable.performClose()Copyright © 2024. All rights reserved.