Package io.deephaven.util.channel
Class CachedChannelProvider
java.lang.Object
io.deephaven.util.channel.CachedChannelProvider
- All Implemented Interfaces:
SeekableChannelsProvider
,SafeCloseable
,AutoCloseable
Channel provider
that will cache a bounded number of unused channels.-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static CachedChannelProvider
create
(@NotNull SeekableChannelsProvider wrappedProvider, int maximumPooledCount) 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.final CompletableOutputStream
getOutputStream
(@NotNull URI uri, int bufferSizeHint) Creates aCompletableOutputStream
to write to the given URI.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.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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.deephaven.util.channel.SeekableChannelsProvider
getReadChannel
-
Method Details
-
create
public static CachedChannelProvider create(@NotNull @NotNull SeekableChannelsProvider wrappedProvider, int maximumPooledCount) -
makeContext
Description copied from interface:SeekableChannelsProvider
Create a newSeekableChannelContext
object for creating read channels via this provider.- Specified by:
makeContext
in interfaceSeekableChannelsProvider
-
makeSingleUseContext
Description copied from interface:SeekableChannelsProvider
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.- Specified by:
makeSingleUseContext
in interfaceSeekableChannelsProvider
-
isCompatibleWith
Description copied from interface:SeekableChannelsProvider
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.- Specified by:
isCompatibleWith
in interfaceSeekableChannelsProvider
-
exists
Description copied from interface:SeekableChannelsProvider
Returns true if the given URI exists in the underlying storage.- Specified by:
exists
in interfaceSeekableChannelsProvider
- Parameters:
uri
- the URI to check- Returns:
- true if the URI exists
-
getReadChannel
public SeekableByteChannel getReadChannel(@NotNull @NotNull SeekableChannelContext channelContext, @NotNull @NotNull URI uri) throws IOException - Specified by:
getReadChannel
in interfaceSeekableChannelsProvider
- Throws:
IOException
-
getInputStream
Description copied from interface:SeekableChannelsProvider
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 unbufferedSeekableChannelsProvider.getReadChannel(SeekableChannelContext, URI)
, or implicitly when the implementation uses a bufferedSeekableChannelsProvider.getReadChannel(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, useSeekableChannelsProvider.channelPositionInputStream(SeekableChannelsProvider, SeekableByteChannel, int)
.- Specified by:
getInputStream
in interfaceSeekableChannelsProvider
- 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
public final CompletableOutputStream getOutputStream(@NotNull @NotNull URI uri, int bufferSizeHint) throws IOException Description copied from interface:SeekableChannelsProvider
Creates aCompletableOutputStream
to write to the given URI.- Specified by:
getOutputStream
in interfaceSeekableChannelsProvider
- 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
Description copied from interface:SeekableChannelsProvider
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.- Specified by:
list
in interfaceSeekableChannelsProvider
- Parameters:
directory
- the URI of the directory to list- Returns:
- The
Stream
ofURI
s - Throws:
IOException
-
walk
Description copied from interface:SeekableChannelsProvider
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.- Specified by:
walk
in interfaceSeekableChannelsProvider
- Parameters:
directory
- the URI of the directory to walk- Returns:
- The
Stream
ofURI
s - Throws:
IOException
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSafeCloseable
-