Class DataChunk

  • All Implemented Interfaces:
    Chunk
    Direct Known Subclasses:
    CacheableDataChunk

    public class DataChunk
    extends java.lang.Object
    implements Chunk
    Buffer chunk representation. Helps HTTP module to avoid redundant String creation.
    Author:
    Alexey Stashok
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DataChunk.Type  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void delete​(int from, int to)  
      void duplicate​(DataChunk src)
      Copy the src into this DataChunk, allocating more space if needed
      boolean equals​(byte[] bytes)
      Compares the message data to the specified byte[].
      boolean equals​(byte[] bytes, int start, int len)
      Compares the message data to the specified byte[].
      boolean equals​(java.lang.Object object)
      Compares this DataChunk and the passed object.
      boolean equals​(java.lang.String s)
      Compares the message bytes to the specified String object.
      boolean equals​(BufferChunk bufferChunkToCheck)
      Compares the message data to the specified BufferChunk.
      boolean equals​(ByteChunk byteChunkToCheck)
      Compares the message data to the specified ByteChunk.
      boolean equals​(CharChunk charChunkToCheck)
      Compares the message data to the specified CharChunk.
      boolean equalsIgnoreCase​(byte[] bytes)
      Compares the message data to the specified byte[] ignoring case considerations.
      boolean equalsIgnoreCase​(byte[] bytes, int start, int len)
      Compares the message data to the specified byte[] ignoring case considerations.
      boolean equalsIgnoreCase​(java.lang.Object object)
      Compares this DataChunk and the passed object ignoring case considerations.
      boolean equalsIgnoreCase​(java.lang.String s)
      Compares the message bytes to the specified String object ignoring case considerations.
      boolean equalsIgnoreCase​(BufferChunk bufferChunkToCheck)
      Compares the message data to the specified BufferChunk ignoring case considerations.
      boolean equalsIgnoreCase​(ByteChunk byteChunkToCheck)
      Compares the message data to the specified ByteChunk ignoring case considerations.
      boolean equalsIgnoreCase​(CharChunk charChunkToCheck)
      Compares the message data to the specified CharChunk ignoring case considerations.
      boolean equalsIgnoreCaseLowerCase​(byte[] b)
      Compares the data chunk to the specified byte array representing lower-case ASCII characters.
      BufferChunk getBufferChunk()  
      ByteChunk getByteChunk()  
      CharChunk getCharChunk()  
      int getEnd()
      Returns the DataChunk end position.
      int getLength()
      Returns the DataChunk length.
      int getStart()
      Returns the DataChunk start position.
      DataChunk.Type getType()  
      int hashCode()
      Returns DataChunk hash code.
      int indexOf​(char c, int fromIndex)
      Returns true if the message bytes starts with the specified string.
      int indexOf​(java.lang.String s, int fromIndex)
      Returns true if the message bytes starts with the specified string.
      boolean isNull()  
      static DataChunk newInstance()  
      static DataChunk newInstance​(ByteChunk byteChunk, BufferChunk bufferChunk, CharChunk charChunk, java.lang.String stringValue)  
      void notifyDirectUpdate()
      Notify the Chunk that its content is going to be changed directly
      void recycle()  
      protected void reset()  
      protected void resetBuffer()  
      protected void resetByteChunk()  
      protected void resetCharChunk()  
      protected void resetString()  
      void set​(DataChunk value)  
      void set​(DataChunk value, int start, int end)  
      void setBuffer​(Buffer buffer)  
      void setBuffer​(Buffer buffer, int position, int limit)  
      void setBytes​(byte[] bytes)  
      void setBytes​(byte[] bytes, int position, int limit)  
      void setChars​(char[] chars, int position, int limit)  
      void setEnd​(int end)
      Sets the DataChunk end position.
      void setStart​(int start)
      Sets the DataChunk start position.
      void setString​(java.lang.String string)  
      boolean startsWith​(java.lang.String s, int pos)
      Returns true if the DataChunk starts with the specified string.
      boolean startsWithIgnoreCase​(java.lang.String s, int pos)
      Returns true if the DataChunk starts with the specified string.
      void toChars​(java.nio.charset.Charset charset)  
      DataChunk toImmutable()  
      java.lang.String toString()  
      java.lang.String toString​(int start, int end)
      java.lang.String toString​(java.nio.charset.Charset charset)  
      void trimLeft()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DataChunk

        protected DataChunk()
    • Method Detail

      • newInstance

        public static DataChunk newInstance()
      • toImmutable

        public DataChunk toImmutable()
      • set

        public void set​(DataChunk value,
                        int start,
                        int end)
      • notifyDirectUpdate

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

        public void setBuffer​(Buffer buffer,
                              int position,
                              int limit)
      • setBuffer

        public void setBuffer​(Buffer buffer)
      • getCharChunk

        public CharChunk getCharChunk()
      • setChars

        public void setChars​(char[] chars,
                             int position,
                             int limit)
      • getByteChunk

        public ByteChunk getByteChunk()
      • setBytes

        public void setBytes​(byte[] bytes)
      • setBytes

        public void setBytes​(byte[] bytes,
                             int position,
                             int limit)
      • setString

        public void setString​(java.lang.String string)
      • trimLeft

        public void trimLeft()
      • duplicate

        public void duplicate​(DataChunk src)
        Copy the src into this DataChunk, allocating more space if needed
      • toChars

        public void toChars​(java.nio.charset.Charset charset)
                     throws java.io.CharConversionException
        Throws:
        java.io.CharConversionException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(java.nio.charset.Charset charset)
      • getLength

        public int getLength()
        Returns the DataChunk length.
        Specified by:
        getLength in interface Chunk
        Returns:
        the DataChunk length.
      • getStart

        public int getStart()
        Returns the DataChunk start position.
        Specified by:
        getStart in interface Chunk
        Returns:
        the DataChunk start position.
      • setStart

        public void setStart​(int start)
        Sets the DataChunk start position.
        Specified by:
        setStart in interface Chunk
        Parameters:
        start - the DataChunk start position.
      • getEnd

        public int getEnd()
        Returns the DataChunk end position.
        Specified by:
        getEnd in interface Chunk
        Returns:
        the DataChunk end position.
      • setEnd

        public void setEnd​(int end)
        Sets the DataChunk end position.
        Specified by:
        setEnd in interface Chunk
        Parameters:
        end - the DataChunk end position.
      • indexOf

        public final int indexOf​(char c,
                                 int fromIndex)
        Returns true if the message bytes starts with the specified string.
        Specified by:
        indexOf in interface Chunk
        Parameters:
        c - the character
        fromIndex - The start position
      • indexOf

        public final int indexOf​(java.lang.String s,
                                 int fromIndex)
        Returns true if the message bytes starts with the specified string.
        Specified by:
        indexOf in interface Chunk
        Parameters:
        s - the string
        fromIndex - The start position
      • delete

        public final void delete​(int from,
                                 int to)
        Specified by:
        delete in interface Chunk
      • toString

        public java.lang.String toString​(int start,
                                         int end)
        Specified by:
        toString in interface Chunk
      • equals

        public boolean equals​(java.lang.Object object)
        Compares this DataChunk and the passed object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - the Object to compare
        Returns:
        true if the passed object represents another DataChunk and its content is equal to this DataChunk's content.
      • equals

        public boolean equals​(java.lang.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​(ByteChunk byteChunkToCheck)
        Compares the message data to the specified ByteChunk.
        Parameters:
        byteChunkToCheck - the ByteChunk to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equals

        public boolean equals​(BufferChunk bufferChunkToCheck)
        Compares the message data to the specified BufferChunk.
        Parameters:
        bufferChunkToCheck - the BufferChunk to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equals

        public boolean equals​(CharChunk charChunkToCheck)
        Compares the message data to the specified CharChunk.
        Parameters:
        charChunkToCheck - the CharChunk to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equals

        public boolean equals​(byte[] bytes)
        Compares the message data to the specified byte[].
        Parameters:
        bytes - the byte[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equals

        public boolean equals​(byte[] bytes,
                              int start,
                              int len)
        Compares the message data to the specified byte[].
        Parameters:
        bytes - the byte[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(java.lang.Object object)
        Compares this DataChunk and the passed object ignoring case considerations.
        Parameters:
        object - the Object to compare
        Returns:
        true if the passed object represents another DataChunk and its content is equal to this DataChunk's content ignoring case considerations.
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(java.lang.String s)
        Compares the message bytes to the specified String object ignoring case considerations.
        Parameters:
        s - the String to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(ByteChunk byteChunkToCheck)
        Compares the message data to the specified ByteChunk ignoring case considerations.
        Parameters:
        byteChunkToCheck - the ByteChunk to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(BufferChunk bufferChunkToCheck)
        Compares the message data to the specified BufferChunk ignoring case considerations.
        Parameters:
        bufferChunkToCheck - the BufferChunk to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(CharChunk charChunkToCheck)
        Compares the message data to the specified CharChunk ignoring case considerations.
        Parameters:
        charChunkToCheck - the CharChunk to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(byte[] bytes)
        Compares the message data to the specified byte[] ignoring case considerations.
        Parameters:
        bytes - the byte[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • equalsIgnoreCase

        public boolean equalsIgnoreCase​(byte[] bytes,
                                        int start,
                                        int len)
        Compares the message data to the specified byte[] ignoring case considerations.
        Parameters:
        bytes - the byte[] to compare
        Returns:
        true if the comparison succeeded, false otherwise
      • hashCode

        public int hashCode()
        Returns DataChunk hash code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        DataChunk hash code.
      • equalsIgnoreCaseLowerCase

        public final boolean equalsIgnoreCaseLowerCase​(byte[] b)
        Compares the data 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
      • startsWith

        public final boolean startsWith​(java.lang.String s,
                                        int pos)
        Returns true if the DataChunk starts with the specified string.
        Parameters:
        s - the string
        pos - The start position
        Returns:
        true if the DataChunk starts with the specified string.
      • startsWithIgnoreCase

        public final boolean startsWithIgnoreCase​(java.lang.String s,
                                                  int pos)
        Returns true if the DataChunk starts with the specified string.
        Parameters:
        s - the string
        pos - The start position
        Returns:
        true if the DataChunk starts with the specified string.
      • isNull

        public final boolean isNull()
      • resetBuffer

        protected void resetBuffer()
      • resetCharChunk

        protected void resetCharChunk()
      • resetByteChunk

        protected void resetByteChunk()
      • resetString

        protected void resetString()
      • reset

        protected void reset()
      • recycle

        public void recycle()