Package org.apache.hadoop.io.file.tfile
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
Entry to a <Key, Value> pair.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(byte[] buf) Compare the entry key to another key.intcompareTo(byte[] buf, int offset, int length) Compare the entry key to another key.intcompareTo(RawComparable key) Compare an entry with a RawComparable object.booleanCompare whether this and other points to the same key value.voidget(BytesWritable key, BytesWritable value) Copy the key and value in one shot into BytesWritables.intgetKey(byte[] buf) Copy the key into user supplied buffer.intgetKey(byte[] buf, int offset) Copy the key into user supplied buffer.intgetKey(BytesWritable key) Copy the key into BytesWritable.intGet the length of the key.Streaming access to the key.intgetValue(byte[] buf) Copy value into user-supplied buffer.intgetValue(byte[] buf, int offset) Copy value into user-supplied buffer.longgetValue(BytesWritable value) Copy the value into BytesWritable.intGet the length of the value. isValueLengthKnown() must be tested true.Stream access to value.inthashCode()booleanCheck whether it is safe to call getValueLength().intwriteKey(OutputStream out) Writing the key to the output stream.longwriteValue(OutputStream out) Writing the value to the output stream.
-
Constructor Details
-
Entry
public Entry()
-
-
Method Details
-
getKeyLength
public int getKeyLength()Get the length of the key.- Returns:
- the length of the key.
-
get
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
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
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
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
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
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
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
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
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
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
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 bufferoffset- offset into the key buffer.length- the length of the key.- Returns:
- comparison result between the entry key with the input key.
-
compareTo
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:
compareToin interfaceComparable<RawComparable>
-
equals
Compare whether this and other points to the same key value. -
hashCode
public int hashCode()
-