public final void set( String text ) { int length = text.length(); ensureSize(length*3+1); // +1 for append int ptr = 0; for (int i = 0; i < length; i++) { final char chr = text.charAt(i); if (chr > 0x7F) { if (chr > 0x7FF) { if(Character.MIN_HIGH_SURROGATE<=chr && chr<=Character.MAX_LOW_SURROGATE) { // surrogate int uc = (((chr & 0x3ff) << 10) | (text.charAt(++i) & 0x3ff)) + 0x10000; buf[ptr++] = (byte)(0xF0 | ((uc >> 18))); buf[ptr++] = (byte)(0x80 | ((uc >> 12) & 0x3F)); buf[ptr++] = (byte)(0x80 | ((uc >> 6) & 0x3F)); buf[ptr++] = (byte)(0x80 + (uc & 0x3F)); continue; } buf[ptr++] = (byte)(0xE0 + (chr >> 12)); buf[ptr++] = (byte)(0x80 + ((chr >> 6) & 0x3F)); } else { buf[ptr++] = (byte)(0xC0 + (chr >> 6)); } buf[ptr++] = (byte)(0x80 + (chr & 0x3F)); } else { buf[ptr++] = (byte)chr; } } len = ptr; }
ensureSize(length*6+1); // in the worst case the text is like """""", so we need 6 bytes per char
/** * * @param indentStr * set to null for no indentation and optimal performance. * otherwise the string is used for indentation. */ public IndentingUTF8XmlOutput(OutputStream out, String indentStr, Encoded[] localNames, CharacterEscapeHandler escapeHandler) { super(out, localNames, escapeHandler); if(indentStr!=null) { Encoded e = new Encoded(indentStr); indent8 = new Encoded(); indent8.ensureSize(e.len*8); unitLen = e.len; for( int i=0; i<8; i++ ) System.arraycopy(e.buf, 0, indent8.buf, unitLen*i, unitLen); } else { this.indent8 = null; this.unitLen = 0; } }
public final void text(int value) throws IOException { closeStartTag(); /* * TODO * Change to use the octet buffer directly */ // max is -2147483648 and 11 digits boolean minus = (value<0); textBuffer.ensureSize(11); byte[] buf = textBuffer.buf; int idx = 11; do { int r = value%10; if(r<0) r = -r; buf[--idx] = (byte)('0'|r); // really measn 0x30+r but 0<=r<10, so bit-OR would do. value /= 10; } while(value!=0); if(minus) buf[--idx] = (byte)'-'; write(buf,idx,11-idx); }
public final void set( String text ) { int length = text.length(); ensureSize(length*3+1); // +1 for append int ptr = 0; for (int i = 0; i < length; i++) { final char chr = text.charAt(i); if (chr > 0x7F) { if (chr > 0x7FF) { if(Character.MIN_HIGH_SURROGATE<=chr && chr<=Character.MAX_LOW_SURROGATE) { // surrogate int uc = (((chr & 0x3ff) << 10) | (text.charAt(++i) & 0x3ff)) + 0x10000; buf[ptr++] = (byte)(0xF0 | ((uc >> 18))); buf[ptr++] = (byte)(0x80 | ((uc >> 12) & 0x3F)); buf[ptr++] = (byte)(0x80 | ((uc >> 6) & 0x3F)); buf[ptr++] = (byte)(0x80 + (uc & 0x3F)); continue; } buf[ptr++] = (byte)(0xE0 + (chr >> 12)); buf[ptr++] = (byte)(0x80 + ((chr >> 6) & 0x3F)); } else { buf[ptr++] = (byte)(0xC0 + (chr >> 6)); } buf[ptr++] = (byte)(0x80 + (chr & 0x3F)); } else { buf[ptr++] = (byte)chr; } } len = ptr; }
ensureSize(length*6+1); // in the worst case the text is like """""", so we need 6 bytes per char
/** * * @param indentStr * set to null for no indentation and optimal performance. * otherwise the string is used for indentation. */ public IndentingUTF8XmlOutput(OutputStream out, String indentStr, Encoded[] localNames, CharacterEscapeHandler escapeHandler) { super(out, localNames, escapeHandler); if(indentStr!=null) { Encoded e = new Encoded(indentStr); indent8 = new Encoded(); indent8.ensureSize(e.len*8); unitLen = e.len; for( int i=0; i<8; i++ ) System.arraycopy(e.buf, 0, indent8.buf, unitLen*i, unitLen); } else { this.indent8 = null; this.unitLen = 0; } }
public final void text(int value) throws IOException { closeStartTag(); /* * TODO * Change to use the octet buffer directly */ // max is -2147483648 and 11 digits boolean minus = (value<0); textBuffer.ensureSize(11); byte[] buf = textBuffer.buf; int idx = 11; do { int r = value%10; if(r<0) r = -r; buf[--idx] = (byte)('0'|r); // really measn 0x30+r but 0<=r<10, so bit-OR would do. value /= 10; } while(value!=0); if(minus) buf[--idx] = (byte)'-'; write(buf,idx,11-idx); }
public final void set( String text ) { int length = text.length(); ensureSize(length*3+1); // +1 for append int ptr = 0; for (int i = 0; i < length; i++) { final char chr = text.charAt(i); if (chr > 0x7F) { if (chr > 0x7FF) { if(Character.MIN_HIGH_SURROGATE<=chr && chr<=Character.MAX_LOW_SURROGATE) { // surrogate int uc = (((chr & 0x3ff) << 10) | (text.charAt(++i) & 0x3ff)) + 0x10000; buf[ptr++] = (byte)(0xF0 | ((uc >> 18))); buf[ptr++] = (byte)(0x80 | ((uc >> 12) & 0x3F)); buf[ptr++] = (byte)(0x80 | ((uc >> 6) & 0x3F)); buf[ptr++] = (byte)(0x80 + (uc & 0x3F)); continue; } buf[ptr++] = (byte)(0xE0 + (chr >> 12)); buf[ptr++] = (byte)(0x80 + ((chr >> 6) & 0x3F)); } else { buf[ptr++] = (byte)(0xC0 + (chr >> 6)); } buf[ptr++] = (byte)(0x80 + (chr & 0x3F)); } else { buf[ptr++] = (byte)chr; } } len = ptr; }
public final void set( String text ) { int length = text.length(); ensureSize(length*3+1); // +1 for append int ptr = 0; for (int i = 0; i < length; i++) { final char chr = text.charAt(i); if (chr > 0x7F) { if (chr > 0x7FF) { if(Character.MIN_HIGH_SURROGATE<=chr && chr<=Character.MAX_LOW_SURROGATE) { // surrogate int uc = (((chr & 0x3ff) << 10) | (text.charAt(++i) & 0x3ff)) + 0x10000; buf[ptr++] = (byte)(0xF0 | ((uc >> 18))); buf[ptr++] = (byte)(0x80 | ((uc >> 12) & 0x3F)); buf[ptr++] = (byte)(0x80 | ((uc >> 6) & 0x3F)); buf[ptr++] = (byte)(0x80 + (uc & 0x3F)); continue; } buf[ptr++] = (byte)(0xE0 + (chr >> 12)); buf[ptr++] = (byte)(0x80 + ((chr >> 6) & 0x3F)); } else { buf[ptr++] = (byte)(0xC0 + (chr >> 6)); } buf[ptr++] = (byte)(0x80 + (chr & 0x3F)); } else { buf[ptr++] = (byte)chr; } } len = ptr; }
ensureSize(length*6+1); // in the worst case the text is like """""", so we need 6 bytes per char
/** * * @param indentStr * set to null for no indentation and optimal performance. * otherwise the string is used for indentation. */ public IndentingUTF8XmlOutput(OutputStream out, String indentStr, Encoded[] localNames, CharacterEscapeHandler escapeHandler) { super(out, localNames, escapeHandler); if(indentStr!=null) { Encoded e = new Encoded(indentStr); indent8 = new Encoded(); indent8.ensureSize(e.len*8); unitLen = e.len; for( int i=0; i<8; i++ ) System.arraycopy(e.buf, 0, indent8.buf, unitLen*i, unitLen); } else { this.indent8 = null; this.unitLen = 0; } }
ensureSize(length*6+1); // in the worst case the text is like """""", so we need 6 bytes per char
/** * * @param indentStr * set to null for no indentation and optimal performance. * otherwise the string is used for indentation. */ public IndentingUTF8XmlOutput(OutputStream out, String indentStr, Encoded[] localNames, CharacterEscapeHandler escapeHandler) { super(out, localNames, escapeHandler); if(indentStr!=null) { Encoded e = new Encoded(indentStr); indent8 = new Encoded(); indent8.ensureSize(e.len*8); unitLen = e.len; for( int i=0; i<8; i++ ) System.arraycopy(e.buf, 0, indent8.buf, unitLen*i, unitLen); } else { this.indent8 = null; this.unitLen = 0; } }
public final void text(int value) throws IOException { closeStartTag(); /* * TODO * Change to use the octet buffer directly */ // max is -2147483648 and 11 digits boolean minus = (value<0); textBuffer.ensureSize(11); byte[] buf = textBuffer.buf; int idx = 11; do { int r = value%10; if(r<0) r = -r; buf[--idx] = (byte)('0'|r); // really measn 0x30+r but 0<=r<10, so bit-OR would do. value /= 10; } while(value!=0); if(minus) buf[--idx] = (byte)'-'; write(buf,idx,11-idx); }
public final void text(int value) throws IOException { closeStartTag(); /* * TODO * Change to use the octet buffer directly */ // max is -2147483648 and 11 digits boolean minus = (value<0); textBuffer.ensureSize(11); byte[] buf = textBuffer.buf; int idx = 11; do { int r = value%10; if(r<0) r = -r; buf[--idx] = (byte)('0'|r); // really measn 0x30+r but 0<=r<10, so bit-OR would do. value /= 10; } while(value!=0); if(minus) buf[--idx] = (byte)'-'; write(buf,idx,11-idx); }