Package dev.vortex.io
Class PooledReadable
java.lang.Object
dev.vortex.io.PooledReadable
- All Implemented Interfaces:
NativeReadable,Closeable,AutoCloseable
A
NativeReadable that serves each of Vortex's concurrent reads from its own stream.
Streams are opened on demand and reused until this readable is closed. Subclasses supply only
openStream().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceOne handle on the source, used by at most one read at a time.static interfaceA staging array, reused across the reads served by one stream. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()final longlength()Total length of the source in bytes.final Stringname()Unique name of this source, typically its original location (URI or file path).protected abstract PooledReadable.PositionalStreamOpens one more handle on this source.final voidreadFully(long position, ByteBuffer buffer) Read exactlybuffer.remaining()bytes starting at absolutepositionintobuffer.
-
Constructor Details
-
PooledReadable
- Parameters:
name- stable unique name for this source, as required byNativeReadable.name()length- total size of the source in bytes
-
-
Method Details
-
openStream
Opens one more handle on this source. Called whenever a read finds no free stream in the pool.- Throws:
IOException
-
name
Description copied from interface:NativeReadableUnique name of this source, typically its original location (URI or file path). Used to key per-session caches and in native error messages, so it must be stable and unique across sources; it must not contain glob characters (*?[).- Specified by:
namein interfaceNativeReadable
-
length
public final long length()Description copied from interface:NativeReadableTotal length of the source in bytes. Must be cheap; called once when the source is registered.- Specified by:
lengthin interfaceNativeReadable
-
readFully
Description copied from interface:NativeReadableRead exactlybuffer.remaining()bytes starting at absolutepositionintobuffer.Unlike
InputStream.read(), short reads are not permitted: implementations must either fill the buffer completely (buffer.remaining() == 0on return) or throw.bufferis a directByteBufferwrapping native memory owned by the caller, so bytes written to it land in the native reader without an extra copy. It is valid only for the duration of this call: implementations must not retain a reference to it after returning. Implementations backed bybyte[]APIs can bulk-putinto it.- Specified by:
readFullyin interfaceNativeReadable- Throws:
EOFException- if the range extends past the end of the sourceIOException- if the underlying storage fails
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-