Skip to content

Add readBytes method to RandomAccessInput #12599

@iverase

Description

@iverase

We can currently read a RandomAccessInput byte by byte but it does not provide a method to bulk read a chunck of bytes, similary to what DataInput provides with DataInput#readBytes(byte[], int, int). Therefore I would like to propose to add it with a default implementation that reads bye per byte:

  /**
   * Reads a specified number of bytes starting at a given position into an array at the specified
   * offset.
   *
   * @see DataInput#readBytes
   */
  default void readBytes(long pos, byte[] bytes, int offset, int length) throws IOException {
    for (int i = 0; i < length; i++) {
      bytes[offset + i] = readByte(pos + i);
    }
  }

We can add faster implementation for all know implementations in Lucene code base.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions