Package io.deephaven.util.channel
Interface SeekableChannelsProvider
- All Superinterfaces:
AutoCloseable
,SafeCloseable
- All Known Implementing Classes:
CachedChannelProvider
-
Method Summary
Modifier and TypeMethodDescriptionstatic InputStream
channelPositionInputStream
(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.boolean
Returns true if the given URI exists in the underlying storage.getInputStream
(SeekableByteChannel channel, int sizeHint) Creates anInputStream
from the current position ofchannel
from which the caller expects to readsizeHint
number of bytes.getOutputStream
(@NotNull URI uri, int bufferSizeHint) Creates aCompletableOutputStream
to write to the given URI.default SeekableByteChannel
getReadChannel
(@NotNull SeekableChannelContext channelContext, @NotNull String uriStr) getReadChannel
(@NotNull SeekableChannelContext channelContext, @NotNull URI uri) boolean
isCompatibleWith
(@NotNull SeekableChannelContext channelContext) Check if the given context is compatible with this provider.Returns a stream of URIs, the elements of which are the entries in the directory.Create a newSeekableChannelContext
object for creating read channels via this provider.default SeekableChannelContext
Create a new "single-use"SeekableChannelContext
object for creating read channels 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:
-
makeContext
SeekableChannelContext makeContext()Create a newSeekableChannelContext
object for creating read channels via this provider. -
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
Check if the given context is compatible with this provider. Useful to test if we can use providedcontext
object for creating 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 anInputStream
from the current position ofchannel
from which the caller expects to readsizeHint
number of bytes. Closing the resulting input stream does not close thechannel
. TheInputStream
will 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)
.channel
must have been created bythis
provider. The caller can't assume the position ofchannel
after consuming theInputStream
. For use-cases that require the channel's position to be incremented the exact amount theInputStream
has 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 URI uri, int bufferSizeHint) throws IOException Creates aCompletableOutputStream
to write to the given URI.- Parameters:
uri
- 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
Stream
ofURI
s - 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
Stream
ofURI
s - Throws:
IOException
-