Package dev.vortex.io

Class PooledReadable

java.lang.Object
dev.vortex.io.PooledReadable
All Implemented Interfaces:
NativeReadable, Closeable, AutoCloseable

public abstract class PooledReadable extends Object implements NativeReadable
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().

  • Constructor Details

    • PooledReadable

      protected PooledReadable(String name, long length)
      Parameters:
      name - stable unique name for this source, as required by NativeReadable.name()
      length - total size of the source in bytes
  • Method Details

    • openStream

      protected abstract PooledReadable.PositionalStream openStream() throws IOException
      Opens one more handle on this source. Called whenever a read finds no free stream in the pool.
      Throws:
      IOException
    • name

      public final String name()
      Description copied from interface: NativeReadable
      Unique 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:
      name in interface NativeReadable
    • length

      public final long length()
      Description copied from interface: NativeReadable
      Total length of the source in bytes. Must be cheap; called once when the source is registered.
      Specified by:
      length in interface NativeReadable
    • readFully

      public final void readFully(long position, ByteBuffer buffer) throws IOException
      Description copied from interface: NativeReadable
      Read exactly buffer.remaining() bytes starting at absolute position into buffer.

      Unlike InputStream.read(), short reads are not permitted: implementations must either fill the buffer completely (buffer.remaining() == 0 on return) or throw.

      buffer is a direct ByteBuffer wrapping 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 by byte[] APIs can bulk-put into it.

      Specified by:
      readFully in interface NativeReadable
      Throws:
      EOFException - if the range extends past the end of the source
      IOException - if the underlying storage fails
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException