Package io.deephaven.util.channel
Interface SeekableChannelsProvider
- All Superinterfaces:
AutoCloseable,SafeCloseable
- All Known Implementing Classes:
CachedChannelProvider,SeekableChannelsProviderDelegate
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceContext object for writing to streams created bySeekableChannelsProvider. -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamchannelPositionInputStream(SeekableChannelsProvider provider, SeekableByteChannel ch, int sizeHint) WrapsgetInputStream(SeekableByteChannel, int)to ensure the channel's position is incremented the exact amount that has been consumed from the resulting input stream.booleanReturns true if the given URI exists in the underlying storage.getInputStream(SeekableByteChannel channel, int sizeHint) Creates anInputStreamfrom the current position ofchannelfrom which the caller expects to readsizeHintnumber of bytes.getOutputStream(@NotNull SeekableChannelsProvider.WriteContext channelContext, @NotNull URI uri, int bufferSizeHint) Creates aCompletableOutputStreamto write to the given URI.default SeekableByteChannelgetReadChannel(@NotNull SeekableChannelContext channelContext, @NotNull String uriStr) getReadChannel(@NotNull SeekableChannelContext channelContext, @NotNull URI uri) booleanisCompatibleWith(@NotNull SeekableChannelContext channelContext) Check if the given context is compatible with this provider for reading.Returns a stream of URIs, the elements of which are the entries in the directory.Create a newSeekableChannelContextobject for creating read channels via this provider.default SeekableChannelContextCreate a new "single-use"SeekableChannelContextobject for creating read channels via this provider.Create a new context object for creating output streams via this provider.Returns a stream of URIs, the elements of which are all the files in the file tree rooted at the given starting directory.Methods inherited from interface io.deephaven.util.SafeCloseable
close
-
Method Details
-
channelPositionInputStream
static InputStream channelPositionInputStream(SeekableChannelsProvider provider, SeekableByteChannel ch, int sizeHint) throws IOException WrapsgetInputStream(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 providerch- the seekable channelsizeHint- 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:
-
makeReadContext
SeekableChannelContext makeReadContext()Create a newSeekableChannelContextobject for creating read channels via this provider. -
makeSingleUseReadContext
Create a new "single-use"SeekableChannelContextobject 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. -
makeWriteContext
SeekableChannelsProvider.WriteContext makeWriteContext()Create a new context object for creating output streams via this provider. -
isCompatibleWith
Check if the given context is compatible with this provider for reading. Useful to test if we can use providedchannelContextobject for creating read channels with this provider. -
exists
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
Creates anInputStreamfrom the current position ofchannelfrom which the caller expects to readsizeHintnumber of bytes. Closing the resulting input stream does not close thechannel. TheInputStreamwill be buffered; either explicitly in the case where the implementation uses an unbufferedgetReadChannel(SeekableChannelContext, URI), or implicitly when the implementation uses a bufferedgetReadChannel(SeekableChannelContext, URI).channelmust have been created bythisprovider. The caller can't assume the position ofchannelafter consuming theInputStream. For use-cases that require the channel's position to be incremented the exact amount theInputStreamhas been consumed, usechannelPositionInputStream(SeekableChannelsProvider, SeekableByteChannel, int).- Parameters:
channel- the channelsizeHint- 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 SeekableChannelsProvider.WriteContext channelContext, @NotNull @NotNull URI uri, int bufferSizeHint) throws IOException Creates aCompletableOutputStreamto write to the given URI.- Parameters:
channelContext- the channel context to use for creating the output streamuri- the URI to write tobufferSizeHint- 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
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
StreamofURIs - Throws:
IOException
-
walk
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
StreamofURIs - Throws:
IOException
-