FileDocCategorySizeDatePackage
JadWriter.javaAPI DocphoneME MR2 API (J2ME)5630Wed May 02 18:00:26 BST 2007com.sun.midp.jadtool

JadWriter

public class JadWriter extends Object
A class for writing JAD's. for details see {@link #write(Properties, OutputStream, String)}

Fields Summary
private static final char[]
hexDigit
A table of hex digits
Constructors Summary
private JadWriter()
prevents anyone from instantiating this class

Methods Summary
private static java.lang.StringsaveConvert(java.lang.String theString)

        int len = theString.length();
        StringBuffer outBuffer = new StringBuffer(len*2);

        for (int x = 0; x < len; x++) {
            char aChar = theString.charAt(x);

            // don't for get to escape the '/'
            if ((aChar < 0x0020) || (aChar > 0x007e) || aChar == 0x005c) {
                outBuffer.append('\\");
                outBuffer.append('u");
                outBuffer.append(toHex((aChar >> 12) & 0xF));
                outBuffer.append(toHex((aChar >>  8) & 0xF));
                outBuffer.append(toHex((aChar >>  4) & 0xF));
                outBuffer.append(toHex(aChar         & 0xF));
                continue;
            }

            outBuffer.append(aChar);
        }

        return outBuffer.toString();
    
private static chartoHex(int nibble)
Convert a nibble to a hex character

param
nibble the nibble to convert.
return
a hex digit

	return hexDigit[(nibble & 0xF)];
    
public static voidwrite(com.sun.midp.util.Properties props, java.io.OutputStream out, java.lang.String enc)
Writes this property list (key and element pairs) in this Properties table to the output stream in a format suitable for loading into a Properties table using the load method. The stream is written using the character encoding specified by enc.

Then every entry in this Properties table is written out, one per line. For each entry the key string is written, then an ASCII =, then the associated element string. Each character of the element string is examined to see whether it should be rendered as an escape sequence. Characters less than \u0020 and characters greater than \u007E are written as \uxxxx for the appropriate hexadecimal value xxxx.

After the entries have been written, the output stream is flushed. The output stream remains open after this method returns.

param
out an output stream.
param
enc character encoding used on input stream.
exception
IOException if writing this property list to the specified output stream throws an IOException.
exception
ClassCastException if this Properties object contains any keys or values that are not Strings.

        OutputStreamWriter awriter;
        awriter = new OutputStreamWriter(out, enc);

	// output in order.
	for (int idx = 0; idx < props.size(); idx++) {
            String key = props.getKeyAt(idx);
	    String val = props.getValueAt(idx);

            if (enc.equals("ISO8859_1")) {
                key = saveConvert(key);	    
                val = saveConvert(val);
            }

            // don't forget the required space after the ":"
            writeln(awriter, key + ": " + val);
        }

        awriter.flush();
    
public static voidwrite(com.sun.midp.util.Properties props, java.io.OutputStream out)
Stores properties to the output stream using the ISO 8859-1 character encoding.

see
#write(Properties, OutputStream, String)
param
out an output stream.
exception
IOException if writing this property list to the specified output stream throws an IOException.
exception
ClassCastException if this Properties object contains any keys or values that are not Strings.

	write(props, out, "UTF-8");
    
private static voidwriteln(java.io.OutputStreamWriter ow, java.lang.String s)

        ow.write(s);
        ow.write("\n");