FileDocCategorySizeDatePackage
UTF_16BE_Writer.javaAPI DocphoneME MR2 API (J2ME)2923Wed May 02 18:00:30 BST 2007com.sun.cldc.i18n.j2me

UTF_16BE_Writer

public 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.

Fields Summary
Constructors Summary
Methods Summary
public intsizeOf(char[] array, int offset, int length)
Get the size in bytes of an array of chars.

param
array Source buffer
param
offset Offset at which to start counting bytes
param
length number of chars to use for counting
return
number of bytes that would be occupied

	return length*2;
    
public voidwrite(char[] cbuf, int off, int len)
Write a portion of an array of characters.

param
cbuf Array of characters
param
off Offset from which to start writing characters
param
len Number of characters to write
exception
IOException If an I/O error occurs

	
	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++;
	}