...
The space for the data byte buffer should be allocated depending upon the maximum number of bytes required to write an encoded character. For example, UTF-8 encoded data requires a maximum of three bytes to denote one character. Although it seems counter intuitive, any character above U+FFFF requires a maximum of four bytes. However, such a sequence is split into two separate char values of two bytes each since Java internally uses UTF-16 for representing a char. Therefore Consequently the buffer size should be four times the size of a typical byte sequence.
...