Class VectorReader.Buffering

java.lang.Object
uk.co.parnmatt.vector.reader.VectorReader.Buffering
Enclosing class:
VectorReader

public static final class VectorReader.Buffering extends Object
The choice of how bytes are buffered as records are read.
Since:
0.4.0
  • Method Details

    • fixed

      public VectorReader.Decoding fixed(Buffers buffers)

      Buffer into a fixed-capacity buffer shared across records, reading ahead.

      Reads ahead into one buffer, so it suits an unbuffered Source such as a raw file or channel; the capacity must be at least the largest record.

      Parameters:
      buffers - the specification of the buffer to allocate
      Returns:
      the choice of element type
    • growable

      public VectorReader.Decoding growable(ByteOrder order)

      Buffer each record exactly into a buffer that grows as records require.

      Allocates no read-ahead buffer, so it suits records whose size is large or unknown up front, or an already-buffered Source where a second buffer would be redundant.

      // GZIPInputStream is already buffered, so growable avoids a second buffer
      try (InputStream input = new GZIPInputStream(source);
              CloseableIterator<float[]> vectors = VectorReader.from(Source.stream(input))
                      .growable(ByteOrder.LITTLE_ENDIAN)
                      .as(ElementType.FLOAT32)) {
          while (vectors.hasNext()) {
              float[] vector = vectors.next();
          }
      }
      
      Parameters:
      order - the byte order in which to interpret the buffered data
      Returns:
      the choice of element type