Payloadpublic class Payload extends Object implements SerializableA Payload is metadata that can be stored together with each occurrence
of a term. This metadata is stored inline in the posting list of the
specific term.
To store payloads in the index a {@link TokenStream} has to be used that
produces {@link Token}s containing payload data.
Use {@link TermPositions#getPayloadLength()} and {@link TermPositions#getPayload(byte[], int)}
to retrieve the payloads from the index.
WARNING: The status of the Payloads feature is experimental.
The APIs introduced here might change in the future and will not be
supported anymore in such a case. |
Fields Summary |
---|
protected byte[] | datathe byte array containing the payload data | protected int | offsetthe offset within the byte array | protected int | lengththe length of the payload data |
Constructors Summary |
---|
protected Payload()Creates an empty payload and does not allocate a byte array.
// no-arg constructor since this class implements Serializable
| public Payload(byte[] data)Creates a new payload with the the given array as data.
this(data, 0, data.length);
| public Payload(byte[] data, int offset, int length)Creates a new payload with the the given array as data.
if (offset < 0 || offset + length > data.length) {
throw new IllegalArgumentException();
}
this.data = data;
this.offset = offset;
this.length = length;
|
Methods Summary |
---|
public byte | byteAt(int index)Returns the byte at the given index.
if (0 <= index && index < this.length) {
return this.data[this.offset + index];
}
throw new ArrayIndexOutOfBoundsException(index);
| public void | copyTo(byte[] target, int targetOffset)Copies the payload data to a byte array.
if (this.length > target.length + targetOffset) {
throw new ArrayIndexOutOfBoundsException();
}
System.arraycopy(this.data, this.offset, target, targetOffset, this.length);
| public int | length()Returns the length of the payload data.
return this.length;
| public byte[] | toByteArray()Allocates a new byte array, copies the payload data into it and returns it.
byte[] retArray = new byte[this.length];
System.arraycopy(this.data, this.offset, retArray, 0, this.length);
return retArray;
|
|