CharChunk (Apache Tomcat 7.0.103 API Documentation)

org.apache.tomcat.util.buf

## Class CharChunk

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

- All Implemented Interfaces:
    Serializable, CharSequence, Cloneable

      public final class CharChunk
      extends AbstractChunk
      implements 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` Input interface, used when the buffer is empty.
    `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.

  - ### Field Summary

    - ### Fields inherited from class org.apache.tomcat.util.buf.AbstractChunk

      `ARRAY_MAX_SIZE, end, hasHashCode, isSet, start`

  - ### Constructor Summary

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

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `allocate(int initial, int limit)`
    `void` | `append(char c)`
    `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)`
    `Object` | `clone()`
    `boolean` | `endsWith(String s)`
    `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(Object obj)`
    `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()` Send the buffer to the sink.
    `char[]` | `getBuffer()`
    `protected int` | `getBufferElement(int index)`
    `char[]` | `getChars()`
    `CharChunk` | `getClone()` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `int` | `getInt()` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `int` | `hashIgnoreCase()` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `int` | `indexOf(char c)`
    `static int` | `indexOf(char[] chars, int start, int end, char s)` Returns the first instance of the given character in the given char array between the specified start and end.
    `int` | `indexOf(char c, int starting)` Returns the first instance of the given character in this CharChunk starting at the specified char.
    `int` | `length()`
    `void` | `makeSpace(int count)` Make space for len chars.
    `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)` Sets the buffer to the specified subarray of characters.
    `void` | `setOptimizedWrite(boolean optimizedWrite)`
    `boolean` | `startsWith(String s)`
    `boolean` | `startsWithIgnoreCase(String s, int pos)` Returns true if the buffer starts with the specified string.
    `CharSequence` | `subSequence(int start, int end)`
    `int` | `substract()`
    `int` | `substract(char[] dest, 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 org.apache.tomcat.util.buf.AbstractChunk

      `getEnd, getLength, getLimit, getLimitInternal, getOffset, getStart, hash, hashCode, indexOf, isNull, recycle, setEnd, setLimit, setOffset`

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

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### CharChunk

          public CharChunk()

      Creates a new, uninitialized CharChunk object.

    - #### CharChunk

          public CharChunk(int initial)

  - ### Method Detail

    - #### getClone

          @Deprecated
          public CharChunk getClone()

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Returns:
        `clone()`

    - #### reset

          @Deprecated
          public void reset()

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

    - #### clone

          public Object clone()
                       throws CloneNotSupportedException

      Overrides:
        `clone` in class `Object`
      Throws:
        `CloneNotSupportedException`

    - #### allocate

          public void allocate(int initial,
                      int limit)

    - #### setOptimizedWrite

          public void setOptimizedWrite(boolean optimizedWrite)

    - #### setChars

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

      Sets the buffer to the specified subarray of characters.
      Parameters:
        `c` - the characters
        `off` - the start offset of the characters
        `len` - the length of the characters

    - #### getChars

          public char[] getChars()

      Returns:
        the buffer.

    - #### getBuffer

          public char[] getBuffer()

      Returns:
        the buffer.

    - #### setCharInputChannel

          public void setCharInputChannel(CharChunk.CharInputChannel in)

      When the buffer is empty, read the data from the input channel.
      Parameters:
        `in` - 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.
      Parameters:
        `out` - The output channel

    - #### append

          public void append(char c)
                      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.
      Parameters:
        `src` - Char array
        `off` - Offset
        `len` - Length
      Throws:
        `IOException` - Writing overflow data to the output channel failed

    - #### append

          @Deprecated
          public void append(StringBuilder sb)
                      throws IOException

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Append a string to the buffer.
      Parameters:
        `sb` - The string builder
      Throws:
        `IOException` - Writing overflow data to the output channel failed

    - #### append

          public void append(String s)
                      throws IOException

      Append a string to the buffer
      Parameters:
        `s` - The string
      Throws:
        `IOException` - Writing overflow data to the output channel failed

    - #### append

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

      Append a string to the buffer.
      Parameters:
        `s` - The string
        `off` - Offset
        `len` - Length
      Throws:
        `IOException` - Writing overflow data to the output channel failed

    - #### 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.
      Parameters:
        `src` - Destination for subtracted data
      Returns:
        count of bytes removed
      Throws:
        `IOException` - If an I/O error occurs

    - #### substract

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

      Throws:
        `IOException`

    - #### flushBuffer

          public void flushBuffer()
                           throws IOException

      Send the buffer to the sink. Called by append() when the limit is reached. You can also call it explicitly to force the data to be written.
      Throws:
        `IOException` - Writing overflow data to the output channel failed

    - #### makeSpace

          public void makeSpace(int count)

      Make space for len chars. If len is small, allocate a reserve space too. Never grow bigger than the limit or `AbstractChunk.ARRAY_MAX_SIZE`.
      Parameters:
        `count` - The size

    - #### 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.
      Returns:
        Buffer content parsed into an int

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### 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.
      Parameters:
        `b2` - Byte array to test
        `off2` - Offset for byte array
        `len2` - Length of byte array
      Returns:
        `true` if the contents of the provided byte array are equal to the contents of this object

    - #### startsWith

          public boolean startsWith(String s)

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

    - #### startsWithIgnoreCase

          public boolean startsWithIgnoreCase(String s,
                                     int pos)

      Returns true if the buffer starts with the specified string.
      Parameters:
        `s` - the string
        `pos` - The position
      Returns:
        `true` if the start matches

    - #### endsWith

          public boolean endsWith(String s)

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

    - #### getBufferElement

          protected int getBufferElement(int index)

      Specified by:
        `getBufferElement` in class `AbstractChunk`

    - #### hashIgnoreCase

          @Deprecated
          public int hashIgnoreCase()

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Returns:
        case insensitive (all lower case) hash code

    - #### indexOf

          public int indexOf(char c)

    - #### indexOf

          public int indexOf(char c,
                    int starting)

      Returns the first instance of the given character in this CharChunk starting at the specified char. If the character is not found, -1 is returned.
      Parameters:
        `c` - The character
        `starting` - The start position
      Returns:
        The position of the first instance of the character or -1 if the character is not found.

    - #### indexOf

          public static int indexOf(char[] chars,
                    int start,
                    int end,
                    char s)

      Returns the first instance of the given character in the given char array between the specified start and end.
      Parameters:
        `chars` - The array to search
        `start` - The point to start searching from in the array
        `end` - The point to stop searching in the array
        `s` - The character to search for
      Returns:
        The position of the first instance of the character or -1 if the character is not found.

    - #### 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-2020 Apache Software Foundation. All Rights Reserved.