Interface SeekableChannelContext

All Superinterfaces:
AutoCloseable, SafeCloseable
All Known Implementing Classes:
BaseSeekableChannelContext

public interface SeekableChannelContext extends SafeCloseable
Context object for reading and writing to channels created by SeekableChannelsProvider.

The context object can hold SafeCloseable resources corresponding to String keys, which can be plugged into the context by calling the getCachedResource(String, Supplier) method. These resources will be closed when the context is closed.

  • Field Details

  • Method Details

    • ensureContext

      A pattern that allows callers to ensure a valid context has been created for provider. In the case where the given context is compatible with provider, a no-op holder around that context will be returned. Otherwise, a holder with a new SeekableChannelsProvider.makeSingleUseContext() will be returned. The returned holder should ideally be used in a try-with-resources construction.
      Parameters:
      provider - the provider
      context - the context
      Returns:
      the context holder
    • getCachedResource

      @Nullable <T extends SafeCloseable> T getCachedResource(String key, Supplier<T> resourceFactory)
      If this instance holds a resource corresponding to the given key, return it. Otherwise, use the resource factory to create a new resource, store it, and return it. This method can return a null if the factory returns a null.
    • close

      default void close()
      Release any resources associated with this context. The context should not be used afterward.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface SafeCloseable