Class TFile.Reader.Scanner.Entry

java.lang.Object
org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner.Entry
All Implemented Interfaces:
Comparable<RawComparable>
Enclosing class:
TFile.Reader.Scanner

public class TFile.Reader.Scanner.Entry extends Object implements Comparable<RawComparable>
Entry to a <Key, Value> pair.
  • Constructor Details

    • Entry

      public Entry()
  • Method Details

    • getKeyLength

      public int getKeyLength()
      Get the length of the key.
      Returns:
      the length of the key.
    • get

      public void get(BytesWritable key, BytesWritable value) throws IOException
      Copy the key and value in one shot into BytesWritables. This is equivalent to getKey(key); getValue(value);
      Parameters:
      key - BytesWritable to hold key.
      value - BytesWritable to hold value
      Throws:
      IOException - raised on errors performing I/O.
    • getKey

      public int getKey(BytesWritable key) throws IOException
      Copy the key into BytesWritable. The input BytesWritable will be automatically resized to the actual key size.
      Parameters:
      key - BytesWritable to hold the key.
      Returns:
      the key into BytesWritable.
      Throws:
      IOException - raised on errors performing I/O.
    • getValue

      public long getValue(BytesWritable value) throws IOException
      Copy the value into BytesWritable. The input BytesWritable will be automatically resized to the actual value size. The implementation directly uses the buffer inside BytesWritable for storing the value. The call does not require the value length to be known.
      Parameters:
      value - value.
      Returns:
      long value.
      Throws:
      IOException - raised on errors performing I/O.
    • writeKey

      public int writeKey(OutputStream out) throws IOException
      Writing the key to the output stream. This method avoids copying key buffer from Scanner into user buffer, then writing to the output stream.
      Parameters:
      out - The output stream
      Returns:
      the length of the key.
      Throws:
      IOException - raised on errors performing I/O.
    • writeValue

      public long writeValue(OutputStream out) throws IOException
      Writing the value to the output stream. This method avoids copying value data from Scanner into user buffer, then writing to the output stream. It does not require the value length to be known.
      Parameters:
      out - The output stream
      Returns:
      the length of the value
      Throws:
      IOException - raised on errors performing I/O.
    • getKey

      public int getKey(byte[] buf) throws IOException
      Copy the key into user supplied buffer.
      Parameters:
      buf - The buffer supplied by user. The length of the buffer must not be shorter than the key length.
      Returns:
      The length of the key.
      Throws:
      IOException - raised on errors performing I/O.
    • getKey

      public int getKey(byte[] buf, int offset) throws IOException
      Copy the key into user supplied buffer.
      Parameters:
      buf - The buffer supplied by user.
      offset - The starting offset of the user buffer where we should copy the key into. Requiring the key-length + offset no greater than the buffer length.
      Returns:
      The length of the key.
      Throws:
      IOException - raised on errors performing I/O.
    • getKeyStream

      public DataInputStream getKeyStream()
      Streaming access to the key. Useful for desrializing the key into user objects.
      Returns:
      The input stream.
    • getValueLength

      public int getValueLength()
      Get the length of the value. isValueLengthKnown() must be tested true.
      Returns:
      the length of the value.
    • getValue

      public int getValue(byte[] buf) throws IOException
      Copy value into user-supplied buffer. User supplied buffer must be large enough to hold the whole value. The value part of the key-value pair pointed by the current cursor is not cached and can only be examined once. Calling any of the following functions more than once without moving the cursor will result in exception: getValue(byte[]), getValue(byte[], int), getValueStream().
      Parameters:
      buf - buf.
      Returns:
      the length of the value. Does not require isValueLengthKnown() to be true.
      Throws:
      IOException - raised on errors performing I/O.
    • getValue

      public int getValue(byte[] buf, int offset) throws IOException
      Copy value into user-supplied buffer. User supplied buffer must be large enough to hold the whole value (starting from the offset). The value part of the key-value pair pointed by the current cursor is not cached and can only be examined once. Calling any of the following functions more than once without moving the cursor will result in exception: getValue(byte[]), getValue(byte[], int), getValueStream().
      Parameters:
      buf - buf.
      offset - offset.
      Returns:
      the length of the value. Does not require isValueLengthKnown() to be true.
      Throws:
      IOException - raised on errors performing I/O.
    • getValueStream

      public DataInputStream getValueStream() throws IOException
      Stream access to value. The value part of the key-value pair pointed by the current cursor is not cached and can only be examined once. Calling any of the following functions more than once without moving the cursor will result in exception: getValue(byte[]), getValue(byte[], int), getValueStream().
      Returns:
      The input stream for reading the value.
      Throws:
      IOException - raised on errors performing I/O.
    • isValueLengthKnown

      public boolean isValueLengthKnown()
      Check whether it is safe to call getValueLength().
      Returns:
      true if value length is known before hand. Values less than the chunk size will always have their lengths known before hand. Values that are written out as a whole (with advertised length up-front) will always have their lengths known in read.
    • compareTo

      public int compareTo(byte[] buf)
      Compare the entry key to another key. Synonymous to compareTo(key, 0, key.length).
      Parameters:
      buf - The key buffer.
      Returns:
      comparison result between the entry key with the input key.
    • compareTo

      public int compareTo(byte[] buf, int offset, int length)
      Compare the entry key to another key. Synonymous to compareTo(new ByteArray(buf, offset, length)
      Parameters:
      buf - The key buffer
      offset - offset into the key buffer.
      length - the length of the key.
      Returns:
      comparison result between the entry key with the input key.
    • compareTo

      public int compareTo(RawComparable key)
      Compare an entry with a RawComparable object. This is useful when Entries are stored in a collection, and we want to compare a user supplied key.
      Specified by:
      compareTo in interface Comparable<RawComparable>
    • equals

      public boolean equals(Object other)
      Compare whether this and other points to the same key value.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object