/** * Writes the encoded bytes to the given output stream. */ public final void write(UTF8XmlOutput out) throws IOException { out.write(buf,0,len); }
public void beginStartTag(int prefix, String localName) throws IOException { closeStartTag(); int base= pushNsDecls(); write('<'); writeName(prefix,localName); writeNsDecls(base); }
@Override public void beginStartTag(Name name) throws IOException { closeStartTag(); int base = pushNsDecls(); write('<'); writeName(name); writeNsDecls(base); }
/** * Writes {@code '>'} to close the start tag, if necessary. */ protected final void closeStartTag() throws IOException { if(closeStartTagPending) { write('>'); closeStartTagPending = false; } }
protected final void write(byte[] b) throws IOException { write(b, 0, b.length); }
public void writeTo(UTF8XmlOutput output) throws IOException { int p = start; for( int i=len; i>0; i-- ) { if(i!=len) output.write(' '); output.text(data[p++]); } } }
/** * Writes a single namespace declaration for the specified prefix. */ protected final void writeNsDecl(int prefixIndex) throws IOException { String p = nsContext.getPrefix(prefixIndex); if(p.length()==0) { if(nsContext.getCurrent().isRootElement() && nsContext.getNamespaceURI(prefixIndex).length()==0) return; // no point in declaring xmlns="" on the root element write(XMLNS_EQUALS); } else { Encoded e = prefixes[prefixIndex]; write(XMLNS_COLON); write(e.buf,0,e.len-1); // skip the trailing ':' write(EQUALS); } doText(nsContext.getNamespaceURI(prefixIndex),true); write('\"'); }
public void text(String value, boolean needSP) throws IOException { closeStartTag(); if(needSP) write(' '); doText(value,false); }
public void text(Pcdata value, boolean needSP) throws IOException { closeStartTag(); if(needSP) write(' '); value.writeTo(this); }
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); }
@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); } }
public void text(String value, boolean needSP) throws IOException { closeStartTag(); if(needSP) write(' '); doText(value,false); }
public void text(Pcdata value, boolean needSP) throws IOException { closeStartTag(); if(needSP) write(' '); value.writeTo(this); }
@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); } }