T - type of the pointerpublic final class AutoCloseablePointer<T extends AutoCloseable> extends Object implements AutoCloseable
If you're familiar with C++/Boost's shared_ptr<>, you might recognize some of the features here.
| Constructor and Description |
|---|
AutoCloseablePointer()
Constructor for a null-valued pointer.
|
AutoCloseablePointer(T pointer)
Constructor for a pointer value.
|
| Modifier and Type | Method and Description |
|---|---|
T |
adopt()
The caller adopts the pointer; the holder is set to
null, and will no longer be responsible for close()ing this pointer.
|
void |
assign(T newP)
Assign a new pointer to this holder.
|
void |
assignNoChecked(T newP)
Like
assign(AutoCloseable), except that any exception thrown
by closing the previously held pointer is wrapped with (an unchecked)
RuntimeException. |
void |
close() |
T |
get()
Get the raw pointer out for use.
|
public AutoCloseablePointer()
public AutoCloseablePointer(T pointer)
pointer - the initial pointer valuepublic void close()
throws Exception
close in interface AutoCloseableExceptionpublic T get()
public T adopt()
public void assign(T newP) throws Exception
This makes it convenient to assign a new pointer without having to check for a previous value and worry about cleaning it up; this does all that.
newP - the new pointer to holdException - any exception thrown by closing the currently held
pointerpublic void assignNoChecked(T newP)
assign(AutoCloseable), except that any exception thrown
by closing the previously held pointer is wrapped with (an unchecked)
RuntimeException.newP - the new pointer to holdCopyright © 2021 The Apache Software Foundation. All rights reserved.