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

Gen_Writer

public class Gen_Writer extends StreamWriter
Generic interface for stream conversion writing of specific character encoded input streams. .

Fields Summary
private String
enc
Saved encoding string from construction.
private int
id
Native handle for conversion routines.
private byte[]
buf
Local buffer to write converted characters.
private int
maxByteLen
Maximum length of characters in local buffer.
Constructors Summary
Gen_Writer(String inp_enc)
Constructor for generic writer.

param
inp_enc character encoding to use for byte to character conversion.
exception
ClassNotFoundException is thrown if the conversion class is not available

        id = Conv.getHandler(inp_enc);
        if (id == -1) {
            throw new ClassNotFoundException();
        }
        enc = inp_enc;
        maxByteLen = Conv.getMaxByteLength(id);
        buf = new byte[maxByteLen];
    
Methods Summary
public java.io.Writeropen(java.io.OutputStream out, java.lang.String open_enc)
Generic routine to open an OutputStream with a specific character encoding.

param
out the output stream to process
param
open_enc the character encoding for the output stream
return
Writer instance for converted characters
throws
UnsupportedEncodingException if encoding is not supported

        if (!open_enc.equals(enc)) {
            throw new UnsupportedEncodingException();
        }
        return super.open(out, open_enc);
    
public intsizeOf(char[] cbuf, int off, int len)
Get the size of the converted bytes as a Unicode byte array.

param
cbuf array of bytes to compute size
param
off offset in the provided buffer
param
len length of bytes to process
return
length of converted characters.

        return Conv.sizeOfUnicodeInByte(id, cbuf, off, len);
    
public synchronized voidwrite(int c)
Write a single converted character.

param
c the character to be output
exception
IOException is thrown if the output stream could not be written with the converted bytes

        char cbuf[] = {(char)c};

        int len = Conv.charToByte(id, cbuf, 0, 1, buf, 0, buf.length);

        if (len > 0) {
            out.write(buf, 0, len);
        }
    
public synchronized voidwrite(char[] cbuf, int off, int len)
Write a block of converted characters.

param
cbuf output buffer of characters to convert
param
off initial offset into the provided buffer
param
len length of characters in the buffer
exception
IOException is thrown if the output stream could not be written with the converted bytes

        int maxlen = len * maxByteLen;
        if (buf.length < maxlen) {
            buf = new byte[maxlen];
        }

        len = Conv.charToByte(id, cbuf, off, len, buf, 0, buf.length);

        if (len > 0) {
            out.write(buf, 0, len);
        }

        if (buf.length > maxByteLen) {
            buf = new byte[maxByteLen];
        }
    
public synchronized voidwrite(java.lang.String str, int off, int len)
Write a block of converted characters from a string.

param
str string to convert
param
off initial offset into the string
param
len length of characters in the string to process
exception
IOException is thrown if the output stream could not be written with the converted bytes

        for (int i = 0; i < len; i++) {
            write(str.charAt(off + i));
        }