FileDocCategorySizeDatePackage
Payload.javaAPI DocApache Lucene 2.2.04142Sat Jun 16 22:20:36 BST 2007org.apache.lucene.index

Payload

public class Payload extends Object implements Serializable
A 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[]
data
the byte array containing the payload data
protected int
offset
the offset within the byte array
protected int
length
the 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.

param
data the data of this payload

      this(data, 0, data.length);
    
public Payload(byte[] data, int offset, int length)
Creates a new payload with the the given array as data.

param
data the data of this payload
param
offset the offset in the data byte array
param
length the length of the data

      if (offset < 0 || offset + length > data.length) {
        throw new IllegalArgumentException();
      }
      this.data = data;
      this.offset = offset;
      this.length = length;
    
Methods Summary
public bytebyteAt(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 voidcopyTo(byte[] target, int targetOffset)
Copies the payload data to a byte array.

param
target the target byte array
param
targetOffset the offset in the target byte array

      if (this.length > target.length + targetOffset) {
        throw new ArrayIndexOutOfBoundsException();
      }
      System.arraycopy(this.data, this.offset, target, targetOffset, this.length);
    
public intlength()
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;