Interface SeekableChannelsProvider

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

public interface SeekableChannelsProvider extends SafeCloseable
  • Method Details

    • channelPositionInputStream

      static InputStream channelPositionInputStream(SeekableChannelsProvider provider, SeekableByteChannel ch, int sizeHint) throws IOException
      Wraps getInputStream(SeekableByteChannel, int) to ensure the channel's position is incremented the exact amount that has been consumed from the resulting input stream. To remain valid, the caller must ensure that the resulting input stream isn't re-wrapped by any downstream code in a way that would adversely affect the position (such as re-wrapping the resulting input stream with buffering).

      Equivalent to ChannelPositionInputStream.of(ch, provider.getInputStream(ch, sizeHint)).

      Parameters:
      provider - the provider
      ch - the seekable channel
      sizeHint - the number of bytes the caller expects to read from the input stream
      Returns:
      the position-safe input stream
      Throws:
      IOException - if an IO exception occurs
      See Also:
    • makeContext

      SeekableChannelContext makeContext()
      Create a new SeekableChannelContext object for creating read channels via this provider.
    • makeSingleUseContext

      default SeekableChannelContext makeSingleUseContext()
      Create a new "single-use" SeekableChannelContext object for creating read channels via this provider. This is meant for contexts that have a short lifecycle and expect to read a small amount from a read channel.
    • isCompatibleWith

      boolean isCompatibleWith(@NotNull @NotNull SeekableChannelContext channelContext)
      Check if the given context is compatible with this provider. Useful to test if we can use provided context object for creating channels with this provider.
    • exists

      boolean exists(@NotNull @NotNull URI uri)
      Returns true if the given URI exists in the underlying storage.
      Parameters:
      uri - the URI to check
      Returns:
      true if the URI exists
    • getReadChannel

      default SeekableByteChannel getReadChannel(@NotNull @NotNull SeekableChannelContext channelContext, @NotNull @NotNull String uriStr) throws IOException
      Throws:
      IOException
    • getReadChannel

      SeekableByteChannel getReadChannel(@NotNull @NotNull SeekableChannelContext channelContext, @NotNull @NotNull URI uri) throws IOException
      Throws:
      IOException
    • getInputStream

      InputStream getInputStream(SeekableByteChannel channel, int sizeHint) throws IOException
      Creates an InputStream from the current position of channel from which the caller expects to read sizeHint number of bytes. Closing the resulting input stream does not close the channel. The InputStream will be buffered; either explicitly in the case where the implementation uses an unbuffered getReadChannel(SeekableChannelContext, URI), or implicitly when the implementation uses a buffered getReadChannel(SeekableChannelContext, URI). channel must have been created by this provider. The caller can't assume the position of channel after consuming the InputStream. For use-cases that require the channel's position to be incremented the exact amount the InputStream has been consumed, use channelPositionInputStream(SeekableChannelsProvider, SeekableByteChannel, int).
      Parameters:
      channel - the channel
      sizeHint - the number of bytes the caller expects to read from the input stream
      Returns:
      the input stream
      Throws:
      IOException - if an IO exception occurs
    • getOutputStream

      CompletableOutputStream getOutputStream(@NotNull @NotNull URI uri, int bufferSizeHint) throws IOException
      Creates a CompletableOutputStream to write to the given URI.
      Parameters:
      uri - the URI to write to
      bufferSizeHint - the number of bytes the caller expects to buffer before flushing
      Returns:
      the output stream
      Throws:
      IOException - if an IO exception occurs
      See Also:
    • list

      Stream<URI> list(@NotNull @NotNull URI directory) throws IOException
      Returns a stream of URIs, the elements of which are the entries in the directory. The listing is non-recursive. The URIs supplied by the stream will not have any unnecessary slashes or path separators. Also, the URIs will be file URIs (not ending with "/") irrespective of whether the URI corresponds to a file or a directory. The caller should manage file vs. directory handling in the processor. The caller is also responsible for closing the stream, preferably using a try-with-resources block.
      Parameters:
      directory - the URI of the directory to list
      Returns:
      The Stream of URIs
      Throws:
      IOException
    • walk

      Stream<URI> walk(@NotNull @NotNull URI directory) throws IOException
      Returns a stream of URIs, the elements of which are all the files in the file tree rooted at the given starting directory. The URIs supplied by the stream will not have any unnecessary slashes or path separators. Also, the URIs will be file URIs (not ending with "/") irrespective of whether the URI corresponds to a file or a directory. The caller should manage file vs. directory handling in the processor. The caller is also responsible for closing the stream, preferably using a try-with-resources block.
      Parameters:
      directory - the URI of the directory to walk
      Returns:
      The Stream of URIs
      Throws:
      IOException