protected final void throwUnpairedSurrogate() throws IOException { int surr = mSurrogate; mSurrogate = 0; throwUnpairedSurrogate(surr); }
protected final int calcSurrogate(int secondSurr) throws IOException { // First, let's verify first surrogate is valid: int firstSurr = mSurrogate; mSurrogate = 0; if (firstSurr < SURR1_FIRST || firstSurr > SURR1_LAST) { throwUnpairedSurrogate(firstSurr); } // Then that the second one is: if ((secondSurr < SURR2_FIRST) || (secondSurr > SURR2_LAST)) { throwUnpairedSurrogate(secondSurr); } int ch = 0x10000 + ((firstSurr - SURR1_FIRST) << 10) + (secondSurr - SURR2_FIRST); if (ch > XmlConsts.MAX_UNICODE_CHAR) { throw new IOException("Illegal surrogate character pair, resulting code 0x"+Integer.toHexString(ch)+" above legal XML character range"); } return ch; }
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; }
public void writeDTD(String data) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeRaw(data, 0, data.length()); }
protected final void writeAscii(byte b) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } if (mOutputPtr >= mOutputBuffer.length) { flushBuffer(); } mOutputBuffer[mOutputPtr++] = b; }
protected final void writeAscii(String str) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } int len = str.length(); int ptr = mOutputPtr; byte[] buf = mOutputBuffer; if ((ptr + len) >= buf.length) { /* It's even possible that String is longer than the buffer (not * likely, possible). If so, let's just call the full * method: */ if (len > buf.length) { writeRaw(str, 0, len); return; } flushBuffer(); ptr = mOutputPtr; } mOutputPtr += len; for (int i = 0; i < len; ++i) { buf[ptr++] = (byte)str.charAt(i); } }
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 writeEntityReference(String name) throws IOException, XMLStreamException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeAscii(BYTE_AMP); writeName(name); writeAscii(BYTE_SEMICOLON); }
/** * 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()); }
/** * 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(); } }
protected final void throwUnpairedSurrogate() throws IOException { int surr = mSurrogate; mSurrogate = 0; throwUnpairedSurrogate(surr); }
protected final void throwUnpairedSurrogate() throws IOException { int surr = mSurrogate; mSurrogate = 0; throwUnpairedSurrogate(surr); }
protected final void writeAscii(byte b) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } if (mOutputPtr >= mOutputBuffer.length) { flushBuffer(); } mOutputBuffer[mOutputPtr++] = b; }
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 writeAscii(byte b1, byte b2) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } if ((mOutputPtr + 1) >= mOutputBuffer.length) { flushBuffer(); } mOutputBuffer[mOutputPtr++] = b1; mOutputBuffer[mOutputPtr++] = b2; }
public void writeDTD(String data) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeRaw(data, 0, data.length()); }
public void writeDTD(String data) throws IOException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeRaw(data, 0, data.length()); }
public void writeEntityReference(String name) throws IOException, XMLStreamException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeAscii(BYTE_AMP); writeName(name); writeAscii(BYTE_SEMICOLON); }
public void writeEntityReference(String name) throws IOException, XMLStreamException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeAscii(BYTE_AMP); writeName(name); writeAscii(BYTE_SEMICOLON); }
public void writeEntityReference(String name) throws IOException, XMLStreamException { if (mSurrogate != 0) { throwUnpairedSurrogate(); } writeAscii(BYTE_AMP); writeName(name); writeAscii(BYTE_SEMICOLON); }