FileDocCategorySizeDatePackage
EscapeUnicode.javaAPI DocApache Ant 1.704002Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.filters

EscapeUnicode

public class EscapeUnicode extends BaseParamFilterReader implements ChainableReader
This method converts non-latin characters to unicode escapes. Useful to load properties containing non latin Example:
<escapeunicode>
Or:
<filterreader
classname="org.apache.tools.ant.filters.EscapeUnicode"/>
since
Ant 1.6

Fields Summary
private StringBuffer
unicodeBuf
Constructors Summary
public EscapeUnicode()
Constructor for "dummy" instances.

see
BaseFilterReader#BaseFilterReader()

        super();
        unicodeBuf = new StringBuffer();
    
public EscapeUnicode(Reader in)
Creates a new filtered reader.

param
in A Reader object providing the underlying stream. Must not be null.

        super(in);
        unicodeBuf = new StringBuffer();
    
Methods Summary
public final java.io.Readerchain(java.io.Reader rdr)
Creates a new EscapeUnicode using the passed in Reader for instantiation.

param
rdr A Reader object providing the underlying stream. Must not be null.
return
a new filter based on this configuration, but filtering the specified reader

        EscapeUnicode newFilter = new EscapeUnicode(rdr);
        newFilter.setInitialized(true);
        return newFilter;
    
private voidinitialize()
Parses the parameters (currently unused)

    
public final intread()
Returns the next character in the filtered stream, converting non latin characters to unicode escapes.

return
the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
exception
IOException if the underlying stream throws an IOException during reading

        if (!getInitialized()) {
            initialize();
            setInitialized(true);
        }

        int ch = -1;
        if (unicodeBuf.length() == 0) {
            ch = in.read();
            if (ch != -1) {
                char achar = (char) ch;
                if (achar >= '\u0080") {
                    unicodeBuf = new StringBuffer("u0000");
                    String s = Integer.toHexString(ch);
                    //replace the last 0s by the chars contained in s
                    for (int i = 0; i < s.length(); i++) {
                        unicodeBuf.setCharAt(unicodeBuf.length()
                                             - s.length() + i,
                                             s.charAt(i));
                    }
                    ch = '\\";
                }
            }
        } else {
            ch = (int) unicodeBuf.charAt(0);
            unicodeBuf.deleteCharAt(0);
        }
        return ch;