The buffer can be modified and used for both input and output.
There are 2 modes: The chunk can be associated with a sink - ByteInputChannel or ByteOutputChannel, which will be used when the buffer is empty (on input) or filled (on output). For output, it can also grow. This operating mode is selected by calling setLimit() or allocate(initial, limit) with limit != -1.
Various search and append method are defined - similar with String and StringBuffer, but operating on bytes.
This is important because it allows processing the http headers directly on the received bytes, without converting to chars and Strings until the strings are needed. In addition, the charset is determined later, from headers or user code.
In a server it is very important to be able to operate on the original byte[] without converting everything to chars. Some protocols are ASCII only, and some allow different non-UNICODE encodings. The encoding is not known beforehand, and can even change during the execution of the protocol. ( for example a multipart message may have parts with different encoding )
For HTTP it is not very clear how the encoding of RequestURI and mime values can be determined, but it is a great advantage to be able to parse the request without converting to string.
| Modifier and Type | Class and Description |
|---|---|
| public static class | |
| public static interface | ByteChunk.
Input interface, used when the buffer is empty. |
| public static interface | ByteChunk.
When we need more space we'll either grow the buffer ( up to the limit ) or send it to a channel. |
| Modifier and Type | Field and Description |
|---|---|
| private byte[] | |
| private transient Charset | |
| public static final Charset | DEFAULT_CHARSET
Default encoding used to convert to strings. |
| private transient ByteChunk. | |
| private transient ByteChunk. | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| private boolean | |
| public Object | |
| public static byte[] | Returns: the byte array valueto convert to byte array value)Convert specified String to a byte array. |
| public boolean | equals(Object
the reference object with which to compare. obj)Overrides java. Indicates whether some other object is "equal to" this one. |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if the comparison succeeded, false otherwisethe array to compare to c2, int offset off2, int length len2)Compares the message bytes to the specified char array. |
| public boolean | Returns: true if the comparison succeeded, false otherwisethe String to compare s)Compares the message bytes to the specified String object. |
| public boolean | |
| public static int | Returns: The position of the first instance of the byte or -1 if the byte is not found.The byte array to search bytes, int The point to start searching from in the byte array start, int The point to stop searching in the byte array end, byte The byte to search for b)Returns the first instance of the given byte in the byte array between the specified start and end. |
| public static int | Returns: The position of the first instance of the byte or -1 if the byte is not found.The byte array to search bytes, int The point to start searching from in the byte array start, int The point to stop searching in the byte array end, byte[] The array of bytes to search for b)Returns the first instance of any of the given bytes in the byte array between the specified start and end. |
| public void | |
| public byte[] | |
| protected int | getBufferElement(int index)
Implements abstract org.
|
| public byte[] | |
| public Charset | |
| public long | |
| public int | Returns: The position of the first instance of the character or -1 if the character is not found.The character c, int The start position starting)Returns the first instance of the given character in this ByteChunk starting at the specified byte. |
| public static int | Returns: The position of the first instance of the character or -1 if the character is not found.The array to search bytes, int The point to start searching from in the array start, int The point to stop searching in the array end, char The character to search for s)Returns the first instance of the given character in the given byte array between the specified start and end. |
| public void | |
| private void | |
| public void | recycle()
Overrides org. Resets the chunk to an uninitialized state. |
| public void | setByteInputChannel(ByteChunk.
The input channel inWhen the buffer is empty, read the data from the input channel. |
| public void | setByteOutputChannel(ByteChunk.
The output channel outWhen the buffer is full, write the data to the output channel. |
| public void | setBytes(byte[]
the ascii bytes b, int the start offset of the bytes off, int the length of the bytes len)Sets the buffer to the specified subarray of bytes. |
| public void | |
| public boolean | Returns: true if the start matchesthe string s, int The position pos)Returns true if the buffer starts with the specified string when tested in a case sensitive manner. |
| public boolean | Returns: true if the start matchesthe string s, int The position pos)Returns true if the buffer starts with the specified string when tested in a case insensitive manner. |
| public int | |
| public int | |
| public int | Returns: an integer specifying the actual number of bytes read, or -1 if the end of the stream is reachedthe ByteBuffer into which bytes are to be written. to)Transfers bytes from the buffer to the specified ByteBuffer. |
| public byte | |
| public String | |
| public String | |
| public String | Returns: The result of converting the bytes to a String
Deprecated
Unused. This method will be removed in Tomcat 11 onwards.
Converts the current content of the byte buffer to a String using the configured character set. |
| public String | Returns: The result of converting the bytes to a StringAction to take if the input is malformed malformedInputAction, CodingErrorAction Action to take if a byte sequence can't be mapped to a character unmappableCharacterAction)Converts the current content of the byte buffer to a String using the configured character set. |
| private void |
| buff | back to summary |
|---|---|
| private byte[] buff | |
| charset | back to summary |
|---|---|
| private transient Charset charset | |
| DEFAULT_CHARSET | back to summary |
|---|---|
| public static final Charset DEFAULT_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. | |
| in | back to summary |
|---|---|
| private transient ByteChunk. | |
| out | back to summary |
|---|---|
| private transient ByteChunk. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides org. | |
| ByteChunk | back to summary |
|---|---|
| public ByteChunk() Creates a new, uninitialized ByteChunk object. | |
| ByteChunk | back to summary |
|---|---|
| public ByteChunk(int initial) | |
| allocate | back to summary |
|---|---|
| public void allocate(int initial, int limit) | |
| append | back to summary |
|---|---|
| public void append(byte b) throws IOException | |
| append | back to summary |
|---|---|
| public void append(ByteChunk src) throws IOException | |
| append | back to summary |
|---|---|
| public void append(byte[] src, int off, int len) throws IOException Add data to the buffer.
| |
| append | back to summary |
|---|---|
| public void append(ByteBuffer from) throws IOException Add data to the buffer.
| |
| checkEof | back to summary |
|---|---|
| private boolean checkEof() throws IOException | |
| clone | back to summary |
|---|---|
| public Object clone() throws CloneNotSupportedException Overrides java. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by
| |
| convertToBytes | back to summary |
|---|---|
| public static byte[] convertToBytes(String value) Convert specified String to a byte array. This ONLY WORKS for ascii, UTF chars will be truncated.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| equals | back to summary |
|---|---|
| public boolean equals(String s) Compares the message bytes to the specified String object. Note This only works for characters in the range 0-127.
| |
| equals | back to summary |
|---|---|
| public boolean equals(ByteChunk bb) | |
| equals | back to summary |
|---|---|
| public boolean equals(byte[] b2, int off2, int len2) | |
| equals | back to summary |
|---|---|
| public boolean equals(CharChunk cc) | |
| equals | back to summary |
|---|---|
| public boolean equals(char[] c2, int off2, int len2) Compares the message bytes to the specified char array. Note This only works for characters in the range 0-127.
| |
| equalsIgnoreCase | back to summary |
|---|---|
| public boolean equalsIgnoreCase(String s) Compares the message bytes to the specified String object. Note This only works for characters in the range 0-127.
| |
| equalsIgnoreCase | back to summary |
|---|---|
| public boolean equalsIgnoreCase(byte[] b2, int off2, int len2) | |
| findByte | back to summary |
|---|---|
| public static int findByte(byte[] bytes, int start, int end, byte b) Returns the first instance of the given byte in the byte array between the specified start and end.
| |
| findBytes | back to summary |
|---|---|
| public static int findBytes(byte[] bytes, int start, int end, byte[] b) Returns the first instance of any of the given bytes in the byte array between the specified start and end.
| |
| flushBuffer | back to summary |
|---|---|
| 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.
| |
| getBuffer | back to summary |
|---|---|
public byte[] getBuffer()
| |
| getBufferElement | back to summary |
|---|---|
| protected int getBufferElement(int index) Implements abstract org.
| |
| getBytes | back to summary |
|---|---|
public byte[] getBytes()
| |
| getCharset | back to summary |
|---|---|
| public Charset getCharset() | |
| getLong | back to summary |
|---|---|
| public long getLong() | |
| indexOf | back to summary |
|---|---|
| public int indexOf(char c, int starting) Returns the first instance of the given character in this ByteChunk starting at the specified byte. If the character is not found, -1 is returned. Note This only works for characters in the range 0-127.
| |
| indexOf | back to summary |
|---|---|
| public static int indexOf(byte[] bytes, int start, int end, char s) Returns the first instance of the given character in the given byte array between the specified start and end. Note This only works for characters in the range 0-127.
| |
| makeSpace | back to summary |
|---|---|
| public void makeSpace(int count) Make space for len bytes. If len is small, allocate a reserve space too. Never grow bigger than the limit or
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException | |
| recycle | back to summary |
|---|---|
| public void recycle() Overrides org. Doc from org. Resets the chunk to an uninitialized state.
| |
| setByteInputChannel | back to summary |
|---|---|
| public void setByteInputChannel(ByteChunk. When the buffer is empty, read the data from the input channel.
| |
| setByteOutputChannel | back to summary |
|---|---|
| public void setByteOutputChannel(ByteChunk. 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.
| |
| setBytes | back to summary |
|---|---|
| public void setBytes(byte[] b, int off, int len) Sets the buffer to the specified subarray of bytes.
| |
| setCharset | back to summary |
|---|---|
| public void setCharset(Charset charset) | |
| startsWith | back to summary |
|---|---|
| public boolean startsWith(String s, int pos) Returns true if the buffer starts with the specified string when tested in a case sensitive manner. Note This only works for characters in the range 0-127.
| |
| startsWithIgnoreCase | back to summary |
|---|---|
| public boolean startsWithIgnoreCase(String s, int pos) Returns true if the buffer starts with the specified string when tested in a case insensitive manner. Note This only works for characters in the range 0-127.
| |
| subtract | back to summary |
|---|---|
| public int subtract() throws IOException | |
| subtract | back to summary |
|---|---|
| public int subtract(byte[] dest, int off, int len) throws IOException | |
| subtract | back to summary |
|---|---|
| public int subtract(ByteBuffer to) throws IOException Transfers bytes from the buffer to the specified ByteBuffer. After the operation the position of the ByteBuffer will be returned to the one before the operation, the limit will be the position incremented by the number of the transferred bytes.
| |
| subtractB | back to summary |
|---|---|
| public byte subtractB() throws IOException | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| toString | back to summary |
|---|---|
| public String toString(CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction) throws CharacterCodingException | |
| toStringInternal | back to summary |
|---|---|
| public String toStringInternal()
Deprecated Unused. This method will be removed in Tomcat 11 onwards. Converts the current content of the byte buffer to a String using the configured character set.
| |
| toStringInternal | back to summary |
|---|---|
| public String toStringInternal(CodingErrorAction malformedInputAction, CodingErrorAction unmappableCharacterAction) throws CharacterCodingException Converts the current content of the byte buffer to a String using the configured character set.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream oos) throws IOException | |
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| public |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| BufferOverflowException | back to summary |
|---|---|
| public BufferOverflowException(String message) | |
| Modifier and Type | Method and Description |
|---|---|
| public int |
| realReadBytes | back to summary |
|---|---|
| public int realReadBytes() throws IOException Read new bytes.
| |
| Modifier and Type | Method and Description |
|---|---|
| public void | realWriteBytes(byte[]
bytes that will be written buf, int offset in the bytes array off, int length that will be written len)Send the bytes ( usually the internal conversion buffer ). |
| public void | realWriteBytes(ByteBuffer
bytes that will be written from)Send the bytes ( usually the internal conversion buffer ). |
| realWriteBytes | back to summary |
|---|---|
| public void realWriteBytes(byte[] buf, int off, int len) throws IOException Send the bytes ( usually the internal conversion buffer ). Expect 8k output if the buffer is full.
| |
| realWriteBytes | back to summary |
|---|---|
| public void realWriteBytes(ByteBuffer from) throws IOException Send the bytes ( usually the internal conversion buffer ). Expect 8k output if the buffer is full.
| |