/** * Method that will try to output the content as specified. If * the content passed in has embedded "--" in it, it will either * add an intervening space between consequtive hyphens (if content * fixing is enabled), or return the offset of the first hyphen in * multi-hyphen sequence. */ public int writeComment(String data) throws IOException { if (mCheckContent) { int ix = verifyCommentContent(data); if (ix >= 0) { if (!mFixContent) { // Can we fix it? return ix; } // Yes we can! (...Bob the Builder...) writeSegmentedComment(data, ix); return -1; } } fastWriteRaw("<!--"); writeRaw(data); fastWriteRaw("-->"); return -1; }
verifyNameValidity(prefix, mNsAware); verifyNameValidity(localName, mNsAware); writePrefixedName(prefix, localName); fastWriteRaw('=', '"'); } else { int ptr = mOutputPtr; flush(); break; flush(); fastWriteRaw('"');
c = handleInvalidChar(c); } else { break inner_loop; // need quoting flushBuffer(); writeRaw(ent); } else { writeAsEntity(value[offset-1]);
public void writeEntityReference(String name) throws IOException, XMLStreamException { if (mCheckNames) { verifyNameValidity(name, mNsAware); } fastWriteRaw('&'); fastWriteRaw(name); fastWriteRaw(';'); }
protected void writeSegmentedCData(char[] c, int start, int len, int index) throws IOException { int end = start + len; while (index >= 0) { fastWriteRaw("<![CDATA["); writeRaw(c, start, (index+2) - start); fastWriteRaw("]]>"); start = index+2; index = verifyCDataContent(c, start, end); } // Ok, then the last segment fastWriteRaw("<![CDATA["); writeRaw(c, start, end-start); fastWriteRaw("]]>"); }
public int writeCData(char[] cbuf, int offset, int len) throws IOException { if (mCheckContent) { int ix = verifyCDataContent(cbuf, offset, len); if (ix >= 0) { if (!mFixContent) { // Can we fix it? return ix; } // Yes we can! (...Bob the Builder...) writeSegmentedCData(cbuf, offset, len, ix); return -1; } } fastWriteRaw("<![CDATA["); writeRaw(cbuf, offset, len); fastWriteRaw("]]>"); return -1; }
verifyNameValidity(localName, mNsAware); fastWriteRaw(' '); fastWriteRaw(localName); fastWriteRaw('=', '"'); } else { int ptr = mOutputPtr; mAttrValueWriter.write(value, offset, vlen); } else { // nope, default writeAttrValue(value, offset, vlen); fastWriteRaw('"');
if (c != '\n' && c != '\r' && c != '\t') { if (!mXml11 || c == 0) { throwInvalidChar(c); flushBuffer(); writeRaw(ent); } else { writeAsEntity(value[offset-1]);
throws IOException, XMLStreamException fastWriteRaw("<!DOCTYPE "); if (mCheckNames) { verifyNameValidity(rootName, false); fastWriteRaw(rootName); if (systemId != null) { if (publicId != null) { fastWriteRaw(" PUBLIC \""); fastWriteRaw(publicId); fastWriteRaw("\" \""); } else { fastWriteRaw(" SYSTEM \""); fastWriteRaw(systemId); fastWriteRaw('"'); fastWriteRaw(' ', '['); fastWriteRaw(internalSubset); fastWriteRaw(']'); fastWriteRaw('>');
public void writeStartTagStart(String prefix, String localName) throws IOException, XMLStreamException { if (prefix == null || prefix.length() == 0) { // shouldn't happen writeStartTagStart(localName); return; } if (mCheckNames) { verifyNameValidity(prefix, mNsAware); verifyNameValidity(localName, mNsAware); } int ptr = mOutputPtr; int len = prefix.length(); int extra = (mOutputBufLen - ptr) - (2 + localName.length() + len); if (extra < 0) { // across buffer boundary, slow case fastWriteRaw('<'); fastWriteRaw(prefix); fastWriteRaw(':'); fastWriteRaw(localName); } else { // fast case, all inlined char[] buf = mOutputBuffer; buf[ptr++] = '<'; prefix.getChars(0, len, buf, ptr); ptr += len; buf[ptr++] = ':'; len = localName.length(); localName.getChars(0, len, buf, ptr); mOutputPtr = ptr+len; } }
verifyNameValidity(localName, mNsAware); fastWriteRaw(' '); fastWriteRaw(localName); fastWriteRaw('=', '"'); } else { int ptr = mOutputPtr; flush(); break; flush(); fastWriteRaw('"');
c = handleInvalidChar(c); writeRaw(cbuf, start, outLen); writeRaw(ent); ent = null; } else if (offset < len) { writeAsEntity(c);
if (enc == CharsetNames.CS_UTF8) { w = new UTF8Writer(cfg, out, autoCloseOutput); xw = new BufferingXmlWriter(w, cfg, enc, autoCloseOutput, out, 16); } else if (enc == CharsetNames.CS_ISO_LATIN1) { xw = new ISOLatin1XmlWriter(out, cfg, autoCloseOutput); } else { w = new OutputStreamWriter(out, enc); xw = new BufferingXmlWriter(w, cfg, enc, autoCloseOutput, out, -1); xw = new BufferingXmlWriter(w, cfg, enc, autoCloseOutput, null, -1); } catch (IOException ex) { throw new XMLStreamException(ex);
public final void writeTypedElement(AsciiValueEncoder enc) throws IOException { if (mOut == null) { return; } int free = mOutputBufLen - mOutputPtr; if (enc.bufferNeedsFlush(free)) { flush(); } while (true) { mOutputPtr = enc.encodeMore(mOutputBuffer, mOutputPtr, mOutputBufLen); // If no flushing needed, indicates that all data was encoded if (enc.isCompleted()) { break; } flush(); } }
public final void writeCDataStart() throws IOException { fastWriteRaw("<![CDATA["); }
private final void fastWriteRaw(char c) throws IOException { if (mOutputPtr >= mOutputBufLen) { if (mOut == null) { return; } flushBuffer(); } mOutputBuffer[mOutputPtr++] = c; }
public void writeRaw(String str) throws IOException { if (mOut == null) { return; } final int len = str.length(); // First; is the new request small or not? If yes, needs to be buffered if (len < mSmallWriteSize) { // yup // Does it fit in with current buffer? If not, need to flush first if ((mOutputPtr + len) >= mOutputBufLen) { flushBuffer(); } str.getChars(0, len, mOutputBuffer, mOutputPtr); mOutputPtr += len; return; } // Otherwise, let's just call the main method writeRaw(str, 0, len); }
/** * @param outs Underlying OutputStream that the writer * (<code>out</code>) is using, if known. Needed to support * (optional) access to the underlying stream */ public BufferingXmlWriter(Writer out, WriterConfig cfg, String enc, boolean autoclose, OutputStream outs, int bitsize) throws IOException { super(cfg, enc, autoclose); mOut = out; mOutputBuffer = cfg.allocFullCBuffer(DEFAULT_BUFFER_SIZE); mOutputBufLen = mOutputBuffer.length; mSmallWriteSize = DEFAULT_SMALL_SIZE; mOutputPtr = 0; mUnderlyingStream = outs; // Let's use double-quotes, as usual; alternative is apostrophe mEncQuoteChar = '"'; mEncQuoteEntity = """; /* Note: let's actually exclude couple of illegal chars for * unicode-based encoders. But we do not have to worry about * surrogates quite here, fortunately. */ if (bitsize < 1) { bitsize = guessEncodingBitSize(enc); } mEncHighChar = ((bitsize < 16) ? (1 << bitsize) : 0xFFFE); }
verifyNameValidity(localName, mNsAware); fastWriteRaw(' '); fastWriteRaw(localName); fastWriteRaw('=', '"'); } else { int ptr = mOutputPtr; mAttrValueWriter.write(value, 0, len); } else { // nope, default writeAttrValue(value, len); fastWriteRaw('"');
public int writeCData(String data) throws IOException { if (mCheckContent) { int ix = verifyCDataContent(data); if (ix >= 0) { if (!mFixContent) { // Can we fix it? return ix; } // Yes we can! (...Bob the Builder...) writeSegmentedCData(data, ix); return -1; } } fastWriteRaw("<![CDATA["); writeRaw(data, 0, data.length()); fastWriteRaw("]]>"); return -1; }