Class ByteChunk

All Implemented Interfaces:
Serializable, Cloneable

public final class ByteChunk extends AbstractChunk
This class is used to represent a chunk of bytes, and utilities to manipulate byte[].

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.

Author:, James Todd [], Costin Manolache, Remy Maucherat
See Also: