UTF_16BE_Writerpublic class UTF_16BE_Writer extends com.sun.cldc.i18n.StreamWriter The class encodes char array into byte stream in big-endian format.
Each char requires two bytes to encode it.
Note:
The Unicode standard allows for characters
whose representation requires more than 16 bit.
Characters whose code points are greater
than U+FFFF are called supplementary characters.
Since String represents a string in the UTF-16 format
in which supplementary characters are represented by surrogate pairs,
so a supplementary character uses two positions in a String.
Therefore, UTF_16BE_Writer doesn't care about supplementary characters,
it treats them as usual characters. |
Methods Summary |
---|
public int | sizeOf(char[] array, int offset, int length)Get the size in bytes of an array of chars.
return length*2;
| public void | write(char[] cbuf, int off, int len)Write a portion of an array of characters.
final int outputSize = 2; // Always write 2 encoded bytes
byte[] outputByte = new byte[outputSize];
char inputChar;
int count = 0;
while (count < len) {
inputChar = cbuf[off + count];
outputByte[0] = (byte)((inputChar >> 8) & 0xff);
outputByte[1] = (byte)(inputChar & 0xff);
out.write(outputByte, 0, outputSize);
count++;
}
|
|