org.apache.tomcat.util.buf

## Class CharChunk

- java.lang.Object
- - org.apache.tomcat.util.buf.CharChunk

- All Implemented Interfaces:
    Serializable, CharSequence, Cloneable

      public final class CharChunk
      extends Object
      implements Cloneable, Serializable, CharSequence

  Utilities to manipulate char chunks. While String is the easiest way to manipulate chars ( search, substrings, etc), it is known to not be the most efficient solution - Strings are designed as immutable and secure objects.
  Author:
    dac@sun.com, James Todd [gonzo@sun.com], Costin Manolache, Remy Maucherat
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `CharChunk.CharInputChannel`
    `static interface` | `CharChunk.CharOutputChannel` When we need more space we'll either grow the buffer ( up to the limit ) or send it to a channel.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CharChunk()` Creates a new, uninitialized CharChunk object.
    `CharChunk(int size)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `allocate(int initial, int limit)`
    `void` | `append(char b)`
    `void` | `append(char[] src, int off, int len)` Add data to the buffer
    `void` | `append(CharChunk src)`
    `void` | `append(String s)` Append a string to the buffer
    `void` | `append(StringBuilder sb)` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `void` | `append(String s, int off, int len)` Append a string to the buffer
    `char` | `charAt(int index)`
    `boolean` | `endsWith(String s)` Returns true if the message bytes end with the specified string.
    `boolean` | `equals(byte[] b2, int off2, int len2)` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `boolean` | `equals(char[] b2, int off2, int len2)`
    `boolean` | `equals(CharChunk cc)`
    `boolean` | `equals(String s)` Compares the message bytes to the specified String object.
    `boolean` | `equalsIgnoreCase(String s)` Compares the message bytes to the specified String object.
    `void` | `flushBuffer()`
    `char[]` | `getBuffer()`
    `char[]` | `getChars()`
    `CharChunk` | `getClone()` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `int` | `getEnd()`
    `int` | `getInt()` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `int` | `getLength()` Returns the length of the bytes.
    `int` | `getLimit()`
    `int` | `getOffset()`
    `int` | `getStart()` Returns the start offset of the bytes.
    `int` | `hash()`
    `int` | `hashIgnoreCase()` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `int` | `indexOf(char c)`
    `static int` | `indexOf(char[] chars, int off, int cend, char qq)`
    `int` | `indexOf(char c, int starting)` Returns true if the message bytes starts with the specified string.
    `int` | `indexOf(String src, int srcOff, int srcLen, int myOff)`
    `boolean` | `isNull()`
    `int` | `length()`
    `void` | `makeSpace(int count)` Make space for len chars.
    `void` | `recycle()` Resets the message bytes to an uninitialized state.
    `void` | `reset()` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `void` | `setCharInputChannel(CharChunk.CharInputChannel in)` When the buffer is empty, read the data from the input channel.
    `void` | `setCharOutputChannel(CharChunk.CharOutputChannel out)` When the buffer is full, write the data to the output channel.
    `void` | `setChars(char[] c, int off, int len)`
    `void` | `setEnd(int i)`
    `void` | `setLimit(int limit)` Maximum amount of data in this buffer.
    `void` | `setOffset(int off)` Returns the start offset of the bytes.
    `void` | `setOptimizedWrite(boolean optimizedWrite)`
    `boolean` | `startsWith(String s)` Returns true if the message bytes starts with the specified string.
    `boolean` | `startsWithIgnoreCase(String s, int pos)` Returns true if the message bytes starts with the specified string.
    `CharSequence` | `subSequence(int start, int end)`
    `int` | `substract()`
    `int` | `substract(char[] src, int off, int len)`
    `int` | `substract(CharChunk src)` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `String` | `toString()`
    `String` | `toStringInternal()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### CharChunk

          public CharChunk()

      Creates a new, uninitialized CharChunk object.

    - #### CharChunk

          public CharChunk(int size)

  - ### Method Detail

    - #### getClone

          @Deprecated
          public CharChunk getClone()

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.

    - #### isNull

          public boolean isNull()

    - #### recycle

          public void recycle()

      Resets the message bytes to an uninitialized state.

    - #### reset

          @Deprecated
          public void reset()

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.

    - #### allocate

          public void allocate(int initial,
                      int limit)

    - #### setOptimizedWrite

          public void setOptimizedWrite(boolean optimizedWrite)

    - #### setChars

          public void setChars(char[] c,
                      int off,
                      int len)

    - #### setLimit

          public void setLimit(int limit)

      Maximum amount of data in this buffer. If -1 or not set, the buffer will grow indefinitely. 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.

    - #### getLimit

          public int getLimit()

    - #### setCharInputChannel

          public void setCharInputChannel(CharChunk.CharInputChannel in)

      When the buffer is empty, read the data from the input channel.

    - #### setCharOutputChannel

          public void setCharOutputChannel(CharChunk.CharOutputChannel out)

      When the buffer is full, write the data to the output channel. Also used when large amount of data is appended. If not set, the buffer will grow to the limit.

    - #### getChars

          public char[] getChars()

    - #### getBuffer

          public char[] getBuffer()

    - #### getStart

          public int getStart()

      Returns the start offset of the bytes. For output this is the end of the buffer.

    - #### getOffset

          public int getOffset()

    - #### setOffset

          public void setOffset(int off)

      Returns the start offset of the bytes.

    - #### getLength

          public int getLength()

      Returns the length of the bytes.

    - #### getEnd

          public int getEnd()

    - #### setEnd

          public void setEnd(int i)

    - #### append

          public void append(char b)
                      throws IOException

      Throws:
        `IOException`

    - #### append

          public void append(CharChunk src)
                      throws IOException

      Throws:
        `IOException`

    - #### append

          public void append(char[] src,
                    int off,
                    int len)
                      throws IOException

      Add data to the buffer
      Throws:
        `IOException`

    - #### append

          @Deprecated
          public void append(StringBuilder sb)
                      throws IOException

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Add data to the buffer.
      Throws:
        `IOException`

    - #### append

          public void append(String s)
                      throws IOException

      Append a string to the buffer
      Throws:
        `IOException`

    - #### append

          public void append(String s,
                    int off,
                    int len)
                      throws IOException

      Append a string to the buffer
      Throws:
        `IOException`

    - #### substract

          public int substract()
                        throws IOException

      Throws:
        `IOException`

    - #### substract

          @Deprecated
          public int substract(CharChunk src)
                        throws IOException

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Throws:
        `IOException`

    - #### substract

          public int substract(char[] src,
                      int off,
                      int len)
                        throws IOException

      Throws:
        `IOException`

    - #### flushBuffer

          public void flushBuffer()
                           throws IOException

      Throws:
        `IOException`

    - #### makeSpace

          public void makeSpace(int count)

      Make space for len chars. If len is small, allocate a reserve space too. Never grow bigger than limit.

    - #### toString

          public String toString()

      Specified by:
        `toString` in interface `CharSequence`
      Overrides:
        `toString` in class `Object`

    - #### toStringInternal

          public String toStringInternal()

    - #### getInt

          @Deprecated
          public int getInt()

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.

    - #### equals

          public boolean equals(String s)

      Compares the message bytes to the specified String object.
      Parameters:
        `s` - the String to compare
      Returns:
        true if the comparison succeeded, false otherwise

    - #### equalsIgnoreCase

          public boolean equalsIgnoreCase(String s)

      Compares the message bytes to the specified String object.
      Parameters:
        `s` - the String to compare
      Returns:
        true if the comparison succeeded, false otherwise

    - #### equals

          public boolean equals(CharChunk cc)

    - #### equals

          public boolean equals(char[] b2,
                       int off2,
                       int len2)

    - #### equals

          @Deprecated
          public boolean equals(byte[] b2,
                                  int off2,
                                  int len2)

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.

    - #### startsWith

          public boolean startsWith(String s)

      Returns true if the message bytes starts with the specified string.
      Parameters:
        `s` - the string

    - #### startsWithIgnoreCase

          public boolean startsWithIgnoreCase(String s,
                                     int pos)

      Returns true if the message bytes starts with the specified string.
      Parameters:
        `s` - the string

    - #### endsWith

          public boolean endsWith(String s)

      Returns true if the message bytes end with the specified string.
      Parameters:
        `s` - the string

    - #### hash

          public int hash()

    - #### hashIgnoreCase

          @Deprecated
          public int hashIgnoreCase()

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.

    - #### indexOf

          public int indexOf(char c)

    - #### indexOf

          public int indexOf(char c,
                    int starting)

      Returns true if the message bytes starts with the specified string.
      Parameters:
        `c` - the character

    - #### indexOf

          public static int indexOf(char[] chars,
                    int off,
                    int cend,
                    char qq)

    - #### indexOf

          public int indexOf(String src,
                    int srcOff,
                    int srcLen,
                    int myOff)

    - #### charAt

          public char charAt(int index)

      Specified by:
        `charAt` in interface `CharSequence`

    - #### subSequence

          public CharSequence subSequence(int start,
                                 int end)

      Specified by:
        `subSequence` in interface `CharSequence`

    - #### length

          public int length()

      Specified by:
        `length` in interface `CharSequence`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.