Class CharChunk

  • All Implemented Interfaces:
    Serializable, Cloneable, Chunk

    public final class CharChunk
    extends Object
    implements Chunk, Cloneable, Serializable
    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
    • Field Detail

      • DEFAULT_HTTP_CHARSET

        public static final Charset DEFAULT_HTTP_CHARSET
        Default encoding used to convert to strings. It should be UTF8, as most standards seem to converge, but the servlet API requires 8859_1, and this object is used mostly for servlets.
    • Constructor Detail

      • CharChunk

        public CharChunk()
        Creates a new, uninitialized CharChunk object.
      • CharChunk

        public CharChunk​(int size)
    • Method Detail

      • isNull

        public boolean isNull()
      • recycle

        public void recycle()
        Resets the message bytes to an uninitialized state.
      • reset

        public void reset()
      • allocate

        public void allocate​(int initial,
                             int limit)
      • ensureCapacity

        public void ensureCapacity​(int size)
      • 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.
        Specified by:
        getStart in interface Chunk
      • setStart

        public void setStart​(int start)
        Returns the start offset of the bytes.
        Specified by:
        setStart in interface Chunk
      • getLength

        public int getLength()
        Returns the length of the bytes.
        Specified by:
        getLength in interface Chunk
      • getEnd

        public int getEnd()
        Specified by:
        getEnd in interface Chunk
      • setEnd

        public void setEnd​(int i)
        Specified by:
        setEnd in interface Chunk
      • append

        public void append​(char[] src,
                           int off,
                           int len)
                    throws IOException
        Add data to the buffer
        Throws:
        IOException
      • delete

        public void delete​(int start,
                           int end)
        Specified by:
        delete in interface Chunk
      • notifyDirectUpdate

        protected void notifyDirectUpdate()
        Notify the Chunk that its content is going to be changed directly
      • resetStringCache

        protected void resetStringCache()
      • toString

        public String toString​(int start,
                               int end)
        Specified by:
        toString in interface Chunk
      • toStringInternal

        public String toStringInternal()
      • getInt

        public int getInt()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(CharSequence 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​(byte[] b)
        Compares the message bytes to the specified byte array representing ASCII characters.
        Parameters:
        b - the byte[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
        Since:
        2.3
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(CharSequence 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​(byte[] b)
        Compares the message bytes to the specified byte array representing ASCII characters.
        Parameters:
        b - the byte[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
        Since:
        2.1.2
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(byte[] b,
                                        int offset,
                                        int len)
        Compares the message bytes to the specified byte array representing ASCII characters.
        Parameters:
        b - the byte[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
        Since:
        2.3
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(char[] b,
                                        int offset,
                                        int len)
        Compares the message bytes to the specified char array representing ASCII characters.
        Parameters:
        b - the char[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
        Since:
        2.3
      • equalsIgnoreCaseLowerCase

        public boolean equalsIgnoreCaseLowerCase​(byte[] b)
        Compares the char chunk to the specified byte array representing lower-case ASCII characters.
        Parameters:
        b - the byte[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
        Since:
        2.1.2
      • equals

        public boolean equals​(CharChunk cc)
      • equals

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

        public boolean equals​(byte[] b2,
                              int off2,
                              int len2)
      • 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)
      • hash

        public int hash()
      • hashIgnoreCase

        public int hashIgnoreCase()
      • 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.
        Specified by:
        indexOf in interface Chunk
        Parameters:
        c - the character
      • indexOf

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

        public int indexOf​(String s,
                           int fromIndex)
        Specified by:
        indexOf in interface Chunk
      • indexOf

        public int indexOf​(String src,
                           int srcOff,
                           int srcLen,
                           int myOff)
      • trimLeft

        public void trimLeft()