MessageBytes (Apache Tomcat 7.0.104 API Documentation)

org.apache.tomcat.util.buf

## Class MessageBytes

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

- All Implemented Interfaces:
    Serializable, Cloneable

      public final class MessageBytes
      extends Object
      implements Cloneable, Serializable

  This class is used to represent a subarray of bytes in an HTTP message. It represents all request/response elements. The byte/char conversions are delayed and cached. Everything is recyclable. The object can represent a byte[], a char[], or a (sub) String. All operations can be made in case sensitive mode or not.
  Author:
    dac@eng.sun.com, James Todd [gonzo@eng.sun.com], Costin Manolache
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `MessageBytes.MessageBytesFactory`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `T_BYTES` getType() is T_BYTES if the the object used to create the MessageBytes was a byte[]
    `static int` | `T_CHARS` getType() is T_CHARS if the the object used to create the MessageBytes was a char[]
    `static int` | `T_NULL`
    `static int` | `T_STR` getType() is T_STR if the the object used to create the MessageBytes was a String

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `duplicate(MessageBytes src)` Copy the src into this MessageBytes, allocating more space if needed.
    `boolean` | `equals(MessageBytes mb)`
    `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.
    `ByteChunk` | `getByteChunk()` Returns the byte chunk, representing the byte[] and offset/length.
    `CharChunk` | `getCharChunk()` Returns the char chunk, representing the char[] and offset/length.
    `Charset` | `getCharset()`
    `MessageBytes` | `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` | `getLength()` Returns the length of the original buffer.
    `long` | `getLong()` Convert the buffer to an long, cache the value.
    `String` | `getString()` Returns the string value.
    `int` | `getType()` Return the type of the original content.
    `int` | `hashCode()`
    `int` | `indexOf(char c)` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `int` | `indexOf(char c, int starting)` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `int` | `indexOf(String s)`
    `int` | `indexOf(String s, int starting)`
    `int` | `indexOfIgnoreCase(String s, int starting)`
    `boolean` | `isNull()`
    `static MessageBytes` | `newInstance()` Construct a new MessageBytes instance.
    `void` | `recycle()` Resets the message bytes to an uninitialized (NULL) state.
    `void` | `setBytes(byte[] b, int off, int len)` Sets the content to the specified subarray of bytes.
    `void` | `setChars(char[] c, int off, int len)` Sets the content to be a char[]
    `void` | `setCharset(Charset charset)` Set the Charset used for string<->byte conversions.
    `static void` | `setFactory(MessageBytes.MessageBytesFactory mbf)` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `void` | `setInt(int i)` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `void` | `setLong(long l)` Set the buffer to the representation of a long.
    `void` | `setString(String s)` Set the content to be a string
    `boolean` | `startsWith(String s)` Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
    `boolean` | `startsWithIgnoreCase(String s, int pos)`
    `void` | `toBytes()` Do a char->byte conversion.
    `void` | `toChars()` Convert to char[] and fill the CharChunk.
    `String` | `toString()` Compute the string value.

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

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

- - ### Field Detail

    - #### T_NULL

          public static final int T_NULL

      See Also:
        Constant Field Values

    - #### T_STR

          public static final int T_STR

      getType() is T_STR if the the object used to create the MessageBytes was a String
      See Also:
        Constant Field Values

    - #### T_BYTES

          public static final int T_BYTES

      getType() is T_BYTES if the the object used to create the MessageBytes was a byte[]
      See Also:
        Constant Field Values

    - #### T_CHARS

          public static final int T_CHARS

      getType() is T_CHARS if the the object used to create the MessageBytes was a char[]
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### newInstance

          public static MessageBytes newInstance()

      Construct a new MessageBytes instance.
      Returns:
        the instance

    - #### getClone

          @Deprecated
          public MessageBytes getClone()

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

    - #### isNull

          public boolean isNull()

    - #### recycle

          public void recycle()

      Resets the message bytes to an uninitialized (NULL) state.

    - #### setBytes

          public void setBytes(byte[] b,
                      int off,
                      int len)

      Sets the content to the specified subarray of bytes.
      Parameters:
        `b` - the bytes
        `off` - the start offset of the bytes
        `len` - the length of the bytes

    - #### setChars

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

      Sets the content to be a char[]
      Parameters:
        `c` - the chars
        `off` - the start offset of the chars
        `len` - the length of the chars

    - #### setString

          public void setString(String s)

      Set the content to be a string
      Parameters:
        `s` - The string

    - #### toString

          public String toString()

      Compute the string value.
      Overrides:
        `toString` in class `Object`
      Returns:
        the string

    - #### getType

          public int getType()

      Return the type of the original content. Can be T_STR, T_BYTES, T_CHARS or T_NULL
      Returns:
        the type

    - #### getByteChunk

          public ByteChunk getByteChunk()

      Returns the byte chunk, representing the byte[] and offset/length. Valid only if T_BYTES or after a conversion was made.
      Returns:
        the byte chunk

    - #### getCharChunk

          public CharChunk getCharChunk()

      Returns the char chunk, representing the char[] and offset/length. Valid only if T_CHARS or after a conversion was made.
      Returns:
        the char chunk

    - #### getString

          public String getString()

      Returns the string value. Valid only if T_STR or after a conversion was made.
      Returns:
        the string

    - #### getCharset

          public Charset getCharset()

      Returns:
        the Charset used for string<->byte conversions.

    - #### setCharset

          public void setCharset(Charset charset)

      Set the Charset used for string<->byte conversions.
      Parameters:
        `charset` - The charset

    - #### toBytes

          public void toBytes()

      Do a char->byte conversion.

    - #### toChars

          public void toChars()

      Convert to char[] and fill the CharChunk. XXX Not optimized - it converts to String first.

    - #### getLength

          public int getLength()

      Returns the length of the original buffer. Note that the length in bytes may be different from the length in chars.
      Returns:
        the length

    - #### 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(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### equals

          public boolean equals(MessageBytes mb)

    - #### startsWith

          @Deprecated
          public boolean startsWith(String s)

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Parameters:
        `s` - the string
      Returns:
        true if the message bytes starts with the specified string.

    - #### startsWithIgnoreCase

          public boolean startsWithIgnoreCase(String s,
                                     int pos)

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

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### indexOf

          @Deprecated
          public int indexOf(char c)

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Parameters:
        `c` - the character
      Returns:
        index of the specified character.

    - #### indexOf

          public int indexOf(String s,
                    int starting)

    - #### indexOf

          public int indexOf(String s)

    - #### indexOfIgnoreCase

          public int indexOfIgnoreCase(String s,
                              int starting)

    - #### indexOf

          @Deprecated
          public int indexOf(char c,
                               int starting)

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Parameters:
        `c` - the character
        `starting` - The start position
      Returns:
        index of the specified character.

    - #### duplicate

          public void duplicate(MessageBytes src)
                         throws IOException

      Copy the src into this MessageBytes, allocating more space if needed.
      Parameters:
        `src` - The source
      Throws:
        `IOException` - Writing overflow data to the output channel failed

    - #### setInt

          @Deprecated
          public void setInt(int i)

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Set the buffer to the representation of an int
      Parameters:
        `i` - The int

    - #### setLong

          public void setLong(long l)

      Set the buffer to the representation of a long.
      Parameters:
        `l` - The long

    - #### getInt

          @Deprecated
          public int getInt()

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Convert the buffer to an int, cache the value
      Returns:
        The contents of the buffer parsed as an int

    - #### getLong

          public long getLong()

      Convert the buffer to an long, cache the value.
      Returns:
        the long value

    - #### setFactory

          @Deprecated
          public static void setFactory(MessageBytes.MessageBytesFactory mbf)

      Deprecated. Unused. Will be removed in Tomcat 8.0.x onwards.
      Parameters:
        `mbf` - New factory for MessageByte instances

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