## org.apache.lucene.index
Class Payload

    java.lang.Object
      org.apache.lucene.index.Payload

All Implemented Interfaces:
  Serializable, Cloneable

    public class Payload

extends Object
implements Serializable, Cloneable

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 `TokenStream` has to be used that produces payload data.

Use `TermPositions.getPayloadLength()` and `TermPositions.getPayload(byte[], int)` to retrieve the payloads from the index.

See Also:
  Serialized Form

Field Summary
`protected byte[]` `data` the byte array containing the payload data
`protected int` `length` the length of the payload data
`protected int` `offset` the offset within the byte array

Constructor Summary
`Payload()` Creates an empty payload and does not allocate a byte array.
`Payload(byte[] data)` Creates a new payload with the the given array as data.
`Payload(byte[] data, int offset, int length)` Creates a new payload with the the given array as data.

Method Summary
`byte` `byteAt(int index)` Returns the byte at the given index.
`Object` `clone()` Clones this payload by creating a copy of the underlying byte array.
`void` `copyTo(byte[] target, int targetOffset)` Copies the payload data to a byte array.
`boolean` `equals(Object obj)`
`byte[]` `getData()` Returns a reference to the underlying byte array that holds this payloads data.
`int` `getOffset()` Returns the offset in the underlying byte array
`int` `hashCode()`
`int` `length()` Returns the length of the payload data.
`void` `setData(byte[] data)` Sets this payloads data.
`void` `setData(byte[] data, int offset, int length)` Sets this payloads data.
`byte[]` `toByteArray()` Allocates a new byte array, copies the payload data into it and returns it.

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### data

    protected byte[] data

  the byte array containing the payload data

### offset

    protected int offset

  the offset within the byte array

### length

    protected int length

  the length of the payload data

Constructor Detail

### Payload

    public Payload()

  Creates an empty payload and does not allocate a byte array.

### Payload

    public Payload(byte[] data)

  Creates a new payload with the the given array as data. A reference to the passed-in array is held, i. e. no copy is made.

  Parameters:
    `data` - the data of this payload

### Payload

    public Payload(byte[] data,
                   int offset,
                   int length)

  Creates a new payload with the the given array as data. A reference to the passed-in array is held, i. e. no copy is made.

  Parameters:
    `data` - the data of this payload
    `offset` - the offset in the data byte array
    `length` - the length of the data

Method Detail

### setData

    public void setData(byte[] data)

  Sets this payloads data. A reference to the passed-in array is held, i. e. no copy is made.

### setData

    public void setData(byte[] data,
                        int offset,
                        int length)

  Sets this payloads data. A reference to the passed-in array is held, i. e. no copy is made.

### getData

    public byte[] getData()

  Returns a reference to the underlying byte array that holds this payloads data.

### getOffset

    public int getOffset()

  Returns the offset in the underlying byte array

### length

    public int length()

  Returns the length of the payload data.

### byteAt

    public byte byteAt(int index)

  Returns the byte at the given index.

### toByteArray

    public byte[] toByteArray()

  Allocates a new byte array, copies the payload data into it and returns it.

### copyTo

    public void copyTo(byte[] target,
                       int targetOffset)

  Copies the payload data to a byte array.

  Parameters:
    `target` - the target byte array
    `targetOffset` - the offset in the target byte array

### clone

    public Object clone()

  Clones this payload by creating a copy of the underlying byte array.

  Overrides:
    `clone` in class `Object`

### equals

    public boolean equals(Object obj)

  Overrides:
    `equals` in class `Object`

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`