DataInput (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.store, class: DataInput

Package org.apache.lucene.store

# Class DataInput

java.lang.Object
org.apache.lucene.store.DataInput

All Implemented Interfaces:
  `Cloneable`

Direct Known Subclasses:
  `ByteArrayDataInput`, `ByteBuffersDataInput`, `FST.BytesReader`, `IndexInput`, `InputStreamDataInput`, `PagedBytes.PagedBytesDataInput`

public abstract class DataInput extends Object implements Cloneable
Abstract base class for performing read operations of Lucene's low-level data types.

`DataInput` may only be used from one thread, because it is not thread safe (it keeps internal state like file position). To allow multithreaded use, every `DataInput` instance must be cloned before used in another thread. Subclasses must therefore implement `clone()`, returning a new `DataInput` which operates on the same underlying resource, but positioned independently.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DataInput()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `DataInput`
  `clone()`
  Returns a clone of this stream.
  `abstract byte`
  `readByte()`
  Reads and returns a single byte.
  `abstract void`
  `readBytes(byte[] b, int offset, int len)`
  Reads a specified number of bytes into an array at the specified offset.
  `void`
  `readBytes(byte[] b, int offset, int len, boolean useBuffer)`
  Reads a specified number of bytes into an array at the specified offset with control over whether the read should be buffered (callers who have their own buffer should pass in "false" for useBuffer).
  `void`
  `readFloats(float[] floats, int offset, int len)`
  Reads a specified number of floats into an array at the specified offset.
  `void`
  `readGroupVInt(int[] dst, int offset)`
  Deprecated.
  This method is no longer called by Lucene.
  `int`
  `readInt()`
  Reads four bytes and returns an int (LE byte order).
  `void`
  `readInts(int[] dst, int offset, int length)`
  Reads a specified number of ints into an array at the specified offset.
  `long`
  `readLong()`
  Reads eight bytes and returns a long (LE byte order).
  `void`
  `readLongs(long[] dst, int offset, int length)`
  Read a specified number of longs.
  `Map<String,String>`
  `readMapOfStrings()`
  Reads a Map<String,String> previously written with `DataOutput.writeMapOfStrings(Map)`.
  `Set<String>`
  `readSetOfStrings()`
  Reads a Set<String> previously written with `DataOutput.writeSetOfStrings(Set)`.
  `short`
  `readShort()`
  Reads two bytes and returns a short (LE byte order).
  `String`
  `readString()`
  Reads a string.
  `int`
  `readVInt()`
  Reads an int stored in variable-length format.
  `long`
  `readVLong()`
  Reads a long stored in variable-length format.
  `int`
  `readZInt()`
  Read a `zig-zag`-encoded `variable-length` integer.
  `long`
  `readZLong()`
  Read a `zig-zag`-encoded `variable-length` integer.
  `abstract void`
  `skipBytes(long numBytes)`
  Skip over `numBytes` bytes.

  ### Methods inherited from class java.lang.Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DataInput

    public DataInput()

- ## Method Details

  - ### readByte

    public abstract byte readByte() throws IOException
    Reads and returns a single byte.
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeByte(byte)`

  - ### readBytes

    public abstract void readBytes(byte[] b, int offset, int len) throws IOException
    Reads a specified number of bytes into an array at the specified offset.
    Parameters:
      `b` - the array to read bytes into
      `offset` - the offset in the array to start storing bytes
      `len` - the number of bytes to read
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeBytes(byte[],int)`

  - ### readBytes

    public void readBytes(byte[] b, int offset, int len, boolean useBuffer) throws IOException
    Reads a specified number of bytes into an array at the specified offset with control over whether the read should be buffered (callers who have their own buffer should pass in "false" for useBuffer). Currently only `BufferedIndexInput` respects this parameter.
    Parameters:
      `b` - the array to read bytes into
      `offset` - the offset in the array to start storing bytes
      `len` - the number of bytes to read
      `useBuffer` - set to false if the caller will handle buffering.
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeBytes(byte[],int)`

  - ### readShort

    public short readShort() throws IOException
    Reads two bytes and returns a short (LE byte order).
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeShort(short)`
      - `BitUtil.VH_LE_SHORT`

  - ### readInt

    public int readInt() throws IOException
    Reads four bytes and returns an int (LE byte order).
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeInt(int)`
      - `BitUtil.VH_LE_INT`

  - ### readGroupVInt

    @Deprecated public void readGroupVInt(int[] dst, int offset) throws IOException
    Deprecated.
    This method is no longer called by Lucene. It is only kept for backwards compatibility. Code calling this method should migrate to `GroupVIntUtil.readGroupVInts(DataInput, int[], int)` to decode a full group including tails instead.
    Legacy: This method allowed to implement GroupVInt encoding in a more efficient way when this implementation supports random access. It is no longer called by Lucene's code.

    If you have implemented this method, simply remove it!

    Throws:
      `IOException`
    WARNING: This API is experimental and might change in incompatible ways in the next release.

  - ### readVInt

    public int readVInt() throws IOException
    Reads an int stored in variable-length format. Reads between one and five bytes. Smaller values take fewer bytes. Negative numbers are supported, but should be avoided.

    The format is described further in `DataOutput.writeVInt(int)`.

    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeVInt(int)`

  - ### readZInt

    public int readZInt() throws IOException
    Read a `zig-zag`-encoded `variable-length` integer.
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeZInt(int)`

  - ### readLong

    public long readLong() throws IOException
    Reads eight bytes and returns a long (LE byte order).
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeLong(long)`
      - `BitUtil.VH_LE_LONG`

  - ### readLongs

    public void readLongs(long[] dst, int offset, int length) throws IOException
    Read a specified number of longs.
    Throws:
      `IOException`
    WARNING: This API is experimental and might change in incompatible ways in the next release.

  - ### readInts

    public void readInts(int[] dst, int offset, int length) throws IOException
    Reads a specified number of ints into an array at the specified offset.
    Parameters:
      `dst` - the array to read bytes into
      `offset` - the offset in the array to start storing ints
      `length` - the number of ints to read
    Throws:
      `IOException`

  - ### readFloats

    public void readFloats(float[] floats, int offset, int len) throws IOException
    Reads a specified number of floats into an array at the specified offset.
    Parameters:
      `floats` - the array to read bytes into
      `offset` - the offset in the array to start storing floats
      `len` - the number of floats to read
    Throws:
      `IOException`

  - ### readVLong

    public long readVLong() throws IOException
    Reads a long stored in variable-length format. Reads between one and nine bytes. Smaller values take fewer bytes. Negative numbers are not supported.

    The format is described further in `DataOutput.writeVInt(int)`.

    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeVLong(long)`

  - ### readZLong

    public long readZLong() throws IOException
    Read a `zig-zag`-encoded `variable-length` integer. Reads between one and ten bytes.
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeZLong(long)`

  - ### readString

    public String readString() throws IOException
    Reads a string.
    Throws:
      `IOException`
    See Also:
      - `DataOutput.writeString(String)`

  - ### clone

    public DataInput clone()
    Returns a clone of this stream.

    Clones of a stream access the same data, and are positioned at the same point as the stream they were cloned from.

    Expert: Subclasses must ensure that clones may be positioned at different points in the input from each other and from the stream they were cloned from.

    Overrides:
      `clone` in class `Object`

  - ### readMapOfStrings

    public Map<String,String> readMapOfStrings() throws IOException
    Reads a Map<String,String> previously written with `DataOutput.writeMapOfStrings(Map)`.
    Returns:
      An immutable map containing the written contents.
    Throws:
      `IOException`

  - ### readSetOfStrings

    public Set<String> readSetOfStrings() throws IOException
    Reads a Set<String> previously written with `DataOutput.writeSetOfStrings(Set)`.
    Returns:
      An immutable set containing the written contents.
    Throws:
      `IOException`

  - ### skipBytes

    public abstract void skipBytes(long numBytes) throws IOException
    Skip over `numBytes` bytes. This method may skip bytes in whatever way is most optimal, and may not have the same behavior as reading the skipped bytes. In general, negative `numBytes` are not supported.
    Throws:
      `IOException`