AbstractChunk (Apache Tomcat 9.0.120 API Documentation)
Description: declaration: package: org.apache.tomcat.util.buf, class: AbstractChunk

# Class AbstractChunk

java.lang.Object
org.apache.tomcat.util.buf.AbstractChunk

All Implemented Interfaces:
  `Serializable, Cloneable`

Direct Known Subclasses:
  `ByteChunk, CharChunk`

public abstract class AbstractChunk extends Object implements Cloneable, Serializable
Base class for the *Chunk implementation to reduce duplication.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `ARRAY_MAX_SIZE`
  The maximum size of an array.
  `protected int`
  `end`
  The end position of the data in the buffer.
  `protected boolean`
  `hasHashCode`
  Indicates whether the hash code has been computed.
  `protected boolean`
  `isSet`
  Indicates whether the chunk has been initialized.
  `protected static final StringManager`
  `sm`
  The string manager for this package.
  `protected int`
  `start`
  The start position of the data in the buffer.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractChunk()`
  Constructs a new AbstractChunk.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract boolean`
  `equals(Object obj)`
  `protected abstract int`
  `getBufferElement(int index)`
  Returns the element at the specified index in the buffer.
  `int`
  `getEnd()`
  Returns the end position of the data in the buffer.
  `int`
  `getLength()`
  Returns the length of the data in the buffer.
  `int`
  `getLimit()`
  Returns the maximum amount of data in the buffer.
  `protected int`
  `getLimitInternal()`
  Returns the internal limit for the buffer.
  `int`
  `getOffset()`
  Deprecated.
  Unused.
  `int`
  `getStart()`
  Returns the start position of the data in the buffer.
  `int`
  `hash()`
  Returns the hash code for this buffer.
  `int`
  `hashCode()`
  `int`
  `indexOf(String src, int srcStart, int srcLen, int myOffset)`
  Return the index of the first occurrence of the subsequence of the given String, or -1 if it is not found.
  `boolean`
  `isNull()`
  Returns whether the buffer contains no data.
  `void`
  `recycle()`
  Resets the chunk to an uninitialized state.
  `void`
  `setEnd(int end)`
  Set the end position of the data in the buffer.
  `void`
  `setLimit(int limit)`
  Maximum amount of data in this buffer.
  `void`
  `setOffset(int off)`
  Deprecated.
  Unused.
  `void`
  `setStart(int start)`
  Set the start position of the data in the buffer.

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### sm

    protected static final StringManager sm
    The string manager for this package.

  - ### ARRAY_MAX_SIZE

    public static final int ARRAY_MAX_SIZE
    The maximum size of an array.
    See Also:
      - Constant Field Values

  - ### hasHashCode

    protected boolean hasHashCode
    Indicates whether the hash code has been computed.

  - ### isSet

    protected boolean isSet
    Indicates whether the chunk has been initialized.

  - ### start

    protected int start
    The start position of the data in the buffer.

  - ### end

    protected int end
    The end position of the data in the buffer.

- ## Constructor Details

  - ### AbstractChunk

    protected AbstractChunk()
    Constructs a new AbstractChunk.

- ## Method Details

  - ### setLimit

    public void setLimit(int limit)
    Maximum amount of data in this buffer. If -1 or not set, the buffer will grow to {`ARRAY_MAX_SIZE`. Can be smaller than the current buffer size ( which will not shrink ). When the limit is reached, the buffer will be flushed (if out is set) or throw exception.
    Parameters:
      `limit` - The new limit

  - ### getLimit

    public int getLimit()
    Returns the maximum amount of data in the buffer.
    Returns:
      the maximum amount of data in the buffer, and -1 if it has not been set

  - ### getLimitInternal

    protected int getLimitInternal()
    Returns the internal limit for the buffer.
    Returns:
      the internal limit

  - ### getStart

    public int getStart()
    Returns the start position of the data in the buffer.
    Returns:
      the start position of the data in the buffer

  - ### setStart

    public void setStart(int start)
    Set the start position of the data in the buffer.
    Parameters:
      `start` - the new start position

  - ### getEnd

    public int getEnd()
    Returns the end position of the data in the buffer.
    Returns:
      the end position of the data in the buffer

  - ### setEnd

    public void setEnd(int end)
    Set the end position of the data in the buffer.
    Parameters:
      `end` - the new end position

  - ### getOffset

    @Deprecated public int getOffset()
    Deprecated.
    Unused. This method will be removed in Tomcat 12.
    Returns:
      start

  - ### setOffset

    @Deprecated public void setOffset(int off)
    Deprecated.
    Unused. This method will be removed in Tomcat 12.
    Set start.
    Parameters:
      `off` - the new start

  - ### getLength

    public int getLength()
    Returns the length of the data in the buffer.
    Returns:
      the length of the data in the buffer

  - ### isNull

    public boolean isNull()
    Returns whether the buffer contains no data.
    Returns:
      `true` if the buffer contains no data

  - ### indexOf

    public int indexOf(String src, int srcStart, int srcLen, int myOffset)
    Return the index of the first occurrence of the subsequence of the given String, or -1 if it is not found.
    Parameters:
      `src` - the String to look for
      `srcStart` - the subsequence start in the String
      `srcLen` - the subsequence length in the String
      `myOffset` - the index on which to start the search in the buffer
    Returns:
      the position of the first character of the first occurrence of the subsequence in the buffer, or -1 if not found

  - ### recycle

    public void recycle()
    Resets the chunk to an uninitialized state.

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### equals

    public abstract boolean equals(Object obj)

    Sub-classes must provide an equals implementation that is consistent with `hashCode()`.

    Overrides:
      `equals` in class `Object`

  - ### hash

    public int hash()
    Returns the hash code for this buffer.
    Returns:
      the hash code for this buffer

  - ### getBufferElement

    protected abstract int getBufferElement(int index)
    Returns the element at the specified index in the buffer.
    Parameters:
      `index` - the element location in the buffer
    Returns:
      the element