public void writeTypedAttribute(String prefix, String localName, AsciiValueEncoder enc) throws IOException, XMLStreamException { writeAscii(BYTE_SPACE); writeName(prefix); writeAscii(BYTE_COLON); writeName(localName); writeAscii(BYTE_EQ, BYTE_QUOT); if (enc.bufferNeedsFlush(mOutputBuffer.length - mOutputPtr)) { flush(); } while (true) { mOutputPtr = enc.encodeMore(mOutputBuffer, mOutputPtr, mOutputBuffer.length); if (enc.isCompleted()) { break; } flush(); } writeAscii(BYTE_QUOT); }
protected final void writeAscii(byte b1, byte b2) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } if ((mOutputPtr + 1) >= mOutputBuffer.length) { flushBuffer(); } mOutputBuffer[mOutputPtr++] = b1; mOutputBuffer[mOutputPtr++] = b2; }
protected final void writeName(String name) throws IOException, XMLStreamException { if (mCheckNames) { verifyNameValidity(name, mNsAware); } // TODO: maybe we could reuse some previously encoded names? writeRaw(name, 0, name.length()); }
public void writeEntityReference(String name) throws IOException, XMLStreamException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeAscii(BYTE_AMP); writeName(name); writeAscii(BYTE_SEMICOLON); }
public void writeStartTagStart(String localName) throws IOException, XMLStreamException { writeAscii(BYTE_LT); writeName(localName); }
public void writeAttribute(String localName, char[] value, int offset, int len) throws IOException, XMLStreamException { writeAscii(BYTE_SPACE); writeName(localName); writeAscii(BYTE_EQ, BYTE_QUOT); if (len > 0) { if (mAttrValueWriter != null) { // custom escaping? mAttrValueWriter.write(value, offset, len); } else { // nope, default writeAttrValue(value, offset, len); } } writeAscii(BYTE_QUOT); }
public int writeCData(String data) throws IOException { writeAscii("<![CDATA["); int ix = writeCDataContent(data); if (ix >= 0) { return ix; } writeAscii("]]>"); return -1; }
public void writeEndTag(String localName) throws IOException { writeAscii(BYTE_LT, BYTE_SLASH); /* At this point, it is assumed caller knows that end tag * matches with start tag, and that it (by extension) has been * validated if and as necessary */ writeNameUnchecked(localName); writeAscii(BYTE_GT); }
/** * 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 { writeAscii("<!--"); int ix = writeCommentContent(data); if (ix >= 0) { // unfixable '--'? return ix; } writeAscii("-->"); return -1; }
public final void writeRawAscii(char[] buf, int offset, int len) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } int ptr = mOutputPtr; byte[] dst = mOutputBuffer; if ((ptr + len) >= dst.length) { if (len > dst.length) { writeRaw(buf, offset, len); return; } flushBuffer(); ptr = mOutputPtr; } mOutputPtr += len; for (int i = 0; i < len; ++i) { dst[ptr+i] = (byte)buf[offset+i]; } }
public void writeStartTagStart(String prefix, String localName) throws IOException, XMLStreamException { if (prefix == null || prefix.length() == 0) { writeStartTagStart(localName); return; } writeAscii(BYTE_LT); writeName(prefix); writeAscii(BYTE_COLON); writeName(localName); }
public int writePI(String target, String data) throws IOException, XMLStreamException { writeAscii(BYTE_LT, BYTE_QMARK); writeName(target); if (data != null && data.length() > 0) { writeAscii(BYTE_SPACE); int ix = writePIData(data); if (ix >= 0) { // embedded "?>"? return ix; } } writeAscii(BYTE_QMARK, BYTE_GT); return -1; }
protected final void throwUnpairedSurrogate(int code) throws IOException { // Let's flush to make debugging easier flush(); throw new IOException("Unpaired surrogate character (0x"+Integer.toHexString(code)+")"); }
writeAscii(BYTE_SPACE); if (hasPrefix) { writeName(prefix); writeAscii(BYTE_COLON); writeName(localName); writeAscii(BYTE_EQ, BYTE_QUOT); writeRawAscii(copyBuffer, 0, last); if (enc.isCompleted()) { validator.validateAttribute(localName, nsURI, prefix, copyBuffer, 0, last); do { last = enc.encodeMore(copyBuffer, 0, copyBufferLen); writeRawAscii(copyBuffer, 0, last); sb.append(copyBuffer, 0, last); } while (!enc.isCompleted()); writeAscii(BYTE_QUOT);
public final void writePIStart(String target, boolean addSpace) throws IOException { writeAscii(BYTE_LT, BYTE_QMARK); writeRaw(target); if (addSpace) { writeAscii(BYTE_SPACE); } }
public void writeDTD(String data) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeRaw(data, 0, data.length()); }
public void writeStartTagEnd() throws IOException { writeAscii(BYTE_GT); }
/** * Non-validating version of typed write method */ public final void writeTypedElement(AsciiValueEncoder enc) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } if (enc.bufferNeedsFlush(mOutputBuffer.length - mOutputPtr)) { flush(); } while (true) { mOutputPtr = enc.encodeMore(mOutputBuffer, mOutputPtr, mOutputBuffer.length); // If no flushing needed, indicates that all data was encoded if (enc.isCompleted()) { break; } flush(); } }
public final void flush() throws IOException { flushBuffer(); mOut.flush(); }
/** * Validating version of typed write method */ public final void writeTypedElement(AsciiValueEncoder enc, XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } /* Ok, this gets trickier: can't use efficient direct-to-bytes * encoding since validator won't be able to use it. Instead * have to use temporary copy buffer. */ final int copyBufferLen = copyBuffer.length; // Copy buffer should never be too small, no need to check up front do { int ptr = enc.encodeMore(copyBuffer, 0, copyBufferLen); // False -> can't be sure it's the whole remaining text validator.validateText(copyBuffer, 0, ptr, false); writeRawAscii(copyBuffer, 0, ptr); } while (!enc.isCompleted()); }