Class LazyCloseable<T extends Closeable>
java.lang.Object
com.apple.foundationdb.record.lucene.codec.LazyCloseable<T>
- Type Parameters:
T- the value opened
- All Implemented Interfaces:
Closeable,AutoCloseable
Similar to
LazyOpener, but that is also Closeable.
Calling close() on this object will not call the opener, and only close the stored value if it was
already opened.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()get()Get the object returned by theopener.Get the object returned by theopener, throwingUncheckedIOExceptionif theLazyOpener.Opener.open()method threwIOException.static <U extends Closeable>
LazyCloseable<U>supply(LazyOpener.Opener<U> opener) Create a newLazyCloseablefor the givenLazyOpener.Opener.
-
Method Details
-
supply
Create a newLazyCloseablefor the givenLazyOpener.Opener.The
openerwill be called at most once; seeSuppliers.memoize(Supplier).- Type Parameters:
U- the return type of theopener- Parameters:
opener- a function to "open" a resource- Returns:
- a new lazily opened object
-
get
Get the object returned by theopener.- Returns:
- the object returned by the
opener - Throws:
IOException- if callingLazyOpener.Opener.open()threw anIOException
-
getUnchecked
Get the object returned by theopener, throwingUncheckedIOExceptionif theLazyOpener.Opener.open()method threwIOException.- Returns:
- the object returned by the
opener
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- if the underlyingclosethrowsIOException.
-