private int pushNsDecls() { int total = nsContext.count(); NamespaceContextImpl.Element ns = nsContext.getCurrent(); if(total > prefixes.length) { // reallocate int m = Math.max(total,prefixes.length*2); Encoded[] buf = new Encoded[m]; System.arraycopy(prefixes,0,buf,0,prefixes.length); for( int i=prefixes.length; i<buf.length; i++ ) buf[i] = new Encoded(); prefixes = buf; } int base = Math.min(prefixCount,ns.getBase()); int size = nsContext.count(); for( int i=base; i<size; i++ ) { String p = nsContext.getPrefix(i); Encoded e = prefixes[i]; if(p.length()==0) { e.buf = EMPTY_BYTE_ARRAY; e.len = 0; } else { e.set(p); e.append(':'); } } prefixCount = size; return base; }
/** * * @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; } }
private void doText(String value,boolean isAttribute) throws IOException { if (escapeHandler != null) { StringWriter sw = new StringWriter(); escapeHandler.escape(value.toCharArray(), 0, value.length(), isAttribute, sw); textBuffer.set(sw.toString()); } else { textBuffer.setEscape(value, isAttribute); } textBuffer.write(this); }
private void writePrefix(int prefix) throws IOException { prefixes[prefix].write(this); }
ensureSize(length*6+1); // in the worst case the text is like """""", so we need 6 bytes per char ptr1 = writeEntity(ent,ptr1); else buf[ptr1++] = (byte)chr;
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; }
/** * * @param localNames * local names encoded in UTF-8. */ public UTF8XmlOutput(OutputStream out, Encoded[] localNames, CharacterEscapeHandler escapeHandler) { this.out = out; this.localNames = localNames; for( int i=0; i<prefixes.length; i++ ) prefixes[i] = new Encoded(); this.escapeHandler = escapeHandler; }
public Encoded(String text) { set(text); }
@Override public void startDocument(XMLSerializer serializer, boolean fragment, int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext) throws IOException, SAXException, XMLStreamException { super.startDocument(serializer, fragment,nsUriIndex2prefixIndex,nsContext); octetBufferIndex = 0; if(!fragment) { write(XML_DECL); } if(header!=null) { textBuffer.set(header); textBuffer.write(this); } }
private void doText(String value,boolean isAttribute) throws IOException { if (escapeHandler != null) { StringWriter sw = new StringWriter(); escapeHandler.escape(value.toCharArray(), 0, value.length(), isAttribute, sw); textBuffer.set(sw.toString()); } else { textBuffer.setEscape(value, isAttribute); } textBuffer.write(this); }
private void writeName(Name name) throws IOException { writePrefix(nsUriIndex2prefixIndex[name.nsUriIndex]); localNames[name.localNameIndex].write(this); }
ensureSize(length*6+1); // in the worst case the text is like """""", so we need 6 bytes per char ptr1 = writeEntity(ent,ptr1); else buf[ptr1++] = (byte)chr;
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); }
/** * * @param localNames * local names encoded in UTF-8. */ public UTF8XmlOutput(OutputStream out, Encoded[] localNames, CharacterEscapeHandler escapeHandler) { this.out = out; this.localNames = localNames; for( int i=0; i<prefixes.length; i++ ) prefixes[i] = new Encoded(); this.escapeHandler = escapeHandler; }
public Encoded(String text) { set(text); }
private void doText(String value,boolean isAttribute) throws IOException { if (escapeHandler != null) { StringWriter sw = new StringWriter(); escapeHandler.escape(value.toCharArray(), 0, value.length(), isAttribute, sw); textBuffer.set(sw.toString()); } else { textBuffer.setEscape(value, isAttribute); } textBuffer.write(this); }
private int pushNsDecls() { int total = nsContext.count(); NamespaceContextImpl.Element ns = nsContext.getCurrent(); if(total > prefixes.length) { // reallocate int m = Math.max(total,prefixes.length*2); Encoded[] buf = new Encoded[m]; System.arraycopy(prefixes,0,buf,0,prefixes.length); for( int i=prefixes.length; i<buf.length; i++ ) buf[i] = new Encoded(); prefixes = buf; } int base = Math.min(prefixCount,ns.getBase()); int size = nsContext.count(); for( int i=base; i<size; i++ ) { String p = nsContext.getPrefix(i); Encoded e = prefixes[i]; if(p.length()==0) { e.buf = EMPTY_BYTE_ARRAY; e.len = 0; } else { e.set(p); e.append(':'); } } prefixCount = size; return base; }