Java Code Examples for com.sun.org.apache.xerces.internal.util.XMLChar#isHighSurrogate()
The following examples show how to use
com.sun.org.apache.xerces.internal.util.XMLChar#isHighSurrogate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLDTDScannerImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Skip the DTD if javax.xml.stream.supportDTD is false. * * @param supportDTD The value of the property javax.xml.stream.supportDTD. * @return true if DTD is skipped, false otherwise. * @throws java.io.IOException if i/o error occurs */ @Override public boolean skipDTD(boolean supportDTD) throws IOException { if (supportDTD) return false; fStringBuffer.clear(); while (fEntityScanner.scanData("]", fStringBuffer, 0)) { int c = fEntityScanner.peekChar(); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(fStringBuffer); } if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInDTD", new Object[] { Integer.toHexString(c) }); fEntityScanner.scanChar(null); } } } fEntityScanner.fCurrentEntity.position--; return true; }
Example 2
Source File: XMLDTDScannerImpl.java From JDKSourceCode1.8 with MIT License | 6 votes |
/** * Skip the DTD if javax.xml.stream.supportDTD is false. * * @param supportDTD The value of the property javax.xml.stream.supportDTD. * @return true if DTD is skipped, false otherwise. * @throws java.io.IOException if i/o error occurs */ @Override public boolean skipDTD(boolean supportDTD) throws IOException { if (supportDTD) return false; fStringBuffer.clear(); while (fEntityScanner.scanData("]", fStringBuffer)) { int c = fEntityScanner.peekChar(); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(fStringBuffer); } if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInDTD", new Object[] { Integer.toHexString(c) }); fEntityScanner.scanChar(null); } } } fEntityScanner.fCurrentEntity.position--; return true; }
Example 3
Source File: XMLScanner.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Scans a comment. * <p> * <pre> * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' * </pre> * <p> * <strong>Note:</strong> Called after scanning past '<!--' * <strong>Note:</strong> This method uses fString, anything in it * at the time of calling is lost. * * @param text The buffer to fill in with the text. */ protected void scanComment(XMLStringBuffer text) throws IOException, XNIException { //System.out.println( "XMLScanner#scanComment# In Scan Comment" ); // text // REVISIT: handle invalid character, eof text.clear(); while (fEntityScanner.scanData("--", text)) { int c = fEntityScanner.peekChar(); //System.out.println( "XMLScanner#scanComment#text.toString() == " + text.toString() ); //System.out.println( "XMLScanner#scanComment#c == " + c ); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(text); } if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInComment", new Object[] { Integer.toHexString(c) }); fEntityScanner.scanChar(); } } } if (!fEntityScanner.skipChar('>')) { reportFatalError("DashDashInComment", null); } }
Example 4
Source File: XMLScanner.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Scans a comment. * <p> * <pre> * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' * </pre> * <p> * <strong>Note:</strong> Called after scanning past '<!--' * <strong>Note:</strong> This method uses fString, anything in it * at the time of calling is lost. * * @param text The buffer to fill in with the text. */ protected void scanComment(XMLStringBuffer text) throws IOException, XNIException { //System.out.println( "XMLScanner#scanComment# In Scan Comment" ); // text // REVISIT: handle invalid character, eof text.clear(); while (fEntityScanner.scanData("--", text)) { int c = fEntityScanner.peekChar(); //System.out.println( "XMLScanner#scanComment#text.toString() == " + text.toString() ); //System.out.println( "XMLScanner#scanComment#c == " + c ); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(text); } if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInComment", new Object[] { Integer.toHexString(c) }); fEntityScanner.scanChar(); } } } if (!fEntityScanner.skipChar('>')) { reportFatalError("DashDashInComment", null); } }
Example 5
Source File: BaseMarkupSerializer.java From JDKSourceCode1.8 with MIT License | 5 votes |
protected void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 6
Source File: BaseMarkupSerializer.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
protected void surrogates(int high, int low) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (content().inCData ) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 7
Source File: BaseMarkupSerializer.java From Bytecoder with Apache License 2.0 | 5 votes |
protected void surrogates(int high, int low, boolean inContent) throws IOException{ if (XMLChar.isHighSurrogate(high)) { if (!XMLChar.isLowSurrogate(low)) { //Invalid XML fatalError("The character '"+(char)low+"' is an invalid XML character"); } else { int supplemental = XMLChar.supplemental((char)high, (char)low); if (!XMLChar.isValid(supplemental)) { //Invalid XML fatalError("The character '"+(char)supplemental+"' is an invalid XML character"); } else { if (inContent && content().inCData) { _printer.printText("]]>&#x"); _printer.printText(Integer.toHexString(supplemental)); _printer.printText(";<![CDATA["); } else { printHex(supplemental); } } } } else { fatalError("The character '"+(char)high+"' is an invalid XML character"); } }
Example 8
Source File: XMLScanner.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Scans a comment. * <p> * <pre> * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' * </pre> * <p> * <strong>Note:</strong> Called after scanning past '<!--' * <strong>Note:</strong> This method uses fString, anything in it * at the time of calling is lost. * * @param text The buffer to fill in with the text. */ protected void scanComment(XMLStringBuffer text) throws IOException, XNIException { //System.out.println( "XMLScanner#scanComment# In Scan Comment" ); // text // REVISIT: handle invalid character, eof text.clear(); while (fEntityScanner.scanData("--", text)) { int c = fEntityScanner.peekChar(); //System.out.println( "XMLScanner#scanComment#text.toString() == " + text.toString() ); //System.out.println( "XMLScanner#scanComment#c == " + c ); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(text); } else if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInComment", new Object[] { Integer.toHexString(c) }); fEntityScanner.scanChar(NameType.COMMENT); } } } if (!fEntityScanner.skipChar('>', NameType.COMMENT)) { reportFatalError("DashDashInComment", null); } }
Example 9
Source File: XMLScanner.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Scans a comment. * <p> * <pre> * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' * </pre> * <p> * <strong>Note:</strong> Called after scanning past '<!--' * <strong>Note:</strong> This method uses fString, anything in it * at the time of calling is lost. * * @param text The buffer to fill in with the text. */ protected void scanComment(XMLStringBuffer text) throws IOException, XNIException { //System.out.println( "XMLScanner#scanComment# In Scan Comment" ); // text // REVISIT: handle invalid character, eof text.clear(); while (fEntityScanner.scanData("--", text)) { int c = fEntityScanner.peekChar(); //System.out.println( "XMLScanner#scanComment#text.toString() == " + text.toString() ); //System.out.println( "XMLScanner#scanComment#c == " + c ); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(text); } else if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInComment", new Object[] { Integer.toHexString(c) }); fEntityScanner.scanChar(NameType.COMMENT); } } } if (!fEntityScanner.skipChar('>', NameType.COMMENT)) { reportFatalError("DashDashInComment", null); } }
Example 10
Source File: XMLScanner.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Scans a comment. * <p> * <pre> * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' * </pre> * <p> * <strong>Note:</strong> Called after scanning past '<!--' * <strong>Note:</strong> This method uses fString, anything in it * at the time of calling is lost. * * @param text The buffer to fill in with the text. */ protected void scanComment(XMLStringBuffer text) throws IOException, XNIException { //System.out.println( "XMLScanner#scanComment# In Scan Comment" ); // text // REVISIT: handle invalid character, eof text.clear(); while (fEntityScanner.scanData("--", text)) { int c = fEntityScanner.peekChar(); //System.out.println( "XMLScanner#scanComment#text.toString() == " + text.toString() ); //System.out.println( "XMLScanner#scanComment#c == " + c ); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(text); } else if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInComment", new Object[] { Integer.toHexString(c) }); fEntityScanner.scanChar(NameType.COMMENT); } } } if (!fEntityScanner.skipChar('>', NameType.COMMENT)) { reportFatalError("DashDashInComment", null); } }
Example 11
Source File: XMLScanner.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Scans a comment. * <p> * <pre> * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' * </pre> * <p> * <strong>Note:</strong> Called after scanning past '<!--' * <strong>Note:</strong> This method uses fString, anything in it * at the time of calling is lost. * * @param text The buffer to fill in with the text. */ protected void scanComment(XMLStringBuffer text) throws IOException, XNIException { //System.out.println( "XMLScanner#scanComment# In Scan Comment" ); // text // REVISIT: handle invalid character, eof text.clear(); while (fEntityScanner.scanData("--", text)) { int c = fEntityScanner.peekChar(); //System.out.println( "XMLScanner#scanComment#text.toString() == " + text.toString() ); //System.out.println( "XMLScanner#scanComment#c == " + c ); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(text); } else if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInComment", new Object[] { Integer.toHexString(c) }); fEntityScanner.scanChar(NameType.COMMENT); } } } if (!fEntityScanner.skipChar('>', NameType.COMMENT)) { reportFatalError("DashDashInComment", null); } }
Example 12
Source File: XMLScanner.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Scans a pseudo attribute. * * @param scanningTextDecl True if scanning this pseudo-attribute for a * TextDecl; false if scanning XMLDecl. This * flag is needed to report the correct type of * error. * @param value The string to fill in with the attribute * value. * * @return The name of the attribute * * <strong>Note:</strong> This method uses fStringBuffer2, anything in it * at the time of calling is lost. */ protected String scanPseudoAttribute(boolean scanningTextDecl, XMLString value) throws IOException, XNIException { String name = scanPseudoAttributeName(); // XMLEntityManager.print(fEntityManager.getCurrentEntity()); if (name == null) { reportFatalError("PseudoAttrNameExpected", null); } fEntityScanner.skipSpaces(); if (!fEntityScanner.skipChar('=', null)) { reportFatalError(scanningTextDecl ? "EqRequiredInTextDecl" : "EqRequiredInXMLDecl", new Object[]{name}); } fEntityScanner.skipSpaces(); int quote = fEntityScanner.peekChar(); if (quote != '\'' && quote != '"') { reportFatalError(scanningTextDecl ? "QuoteRequiredInTextDecl" : "QuoteRequiredInXMLDecl" , new Object[]{name}); } fEntityScanner.scanChar(NameType.ATTRIBUTE); int c = fEntityScanner.scanLiteral(quote, value, false); if (c != quote) { fStringBuffer2.clear(); do { fStringBuffer2.append(value); if (c != -1) { if (c == '&' || c == '%' || c == '<' || c == ']') { fStringBuffer2.append((char)fEntityScanner.scanChar(NameType.ATTRIBUTE)); } else if (XMLChar.isHighSurrogate(c)) { scanSurrogates(fStringBuffer2); } else if (isInvalidLiteral(c)) { String key = scanningTextDecl ? "InvalidCharInTextDecl" : "InvalidCharInXMLDecl"; reportFatalError(key, new Object[] {Integer.toString(c, 16)}); fEntityScanner.scanChar(null); } } c = fEntityScanner.scanLiteral(quote, value, false); } while (c != quote); fStringBuffer2.append(value); value.setValues(fStringBuffer2); } if (!fEntityScanner.skipChar(quote, null)) { reportFatalError(scanningTextDecl ? "CloseQuoteMissingInTextDecl" : "CloseQuoteMissingInXMLDecl", new Object[]{name}); } // return return name; }
Example 13
Source File: UTF8OutputStreamWriter.java From hottub with GNU General Public License v2.0 | 4 votes |
public void write(int c) throws IOException { // Check in we are encoding at high and low surrogates if (lastUTF16CodePoint != 0) { final int uc = (((lastUTF16CodePoint & 0x3ff) << 10) | (c & 0x3ff)) + 0x10000; if (uc < 0 || uc >= 0x200000) { throw new IOException("Atttempting to write invalid Unicode code point '" + uc + "'"); } out.write(0xF0 | (uc >> 18)); out.write(0x80 | ((uc >> 12) & 0x3F)); out.write(0x80 | ((uc >> 6) & 0x3F)); out.write(0x80 | (uc & 0x3F)); lastUTF16CodePoint = 0; return; } // Otherwise, encode char as defined in UTF-8 if (c < 0x80) { // 1 byte, 7 bits out.write((int) c); } else if (c < 0x800) { // 2 bytes, 11 bits out.write(0xC0 | (c >> 6)); // first 5 out.write(0x80 | (c & 0x3F)); // second 6 } else if (c <= '\uFFFF') { if (!XMLChar.isHighSurrogate(c) && !XMLChar.isLowSurrogate(c)) { // 3 bytes, 16 bits out.write(0xE0 | (c >> 12)); // first 4 out.write(0x80 | ((c >> 6) & 0x3F)); // second 6 out.write(0x80 | (c & 0x3F)); // third 6 } else { lastUTF16CodePoint = c; } } }
Example 14
Source File: XIncludeHandler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private String escapeHref(String href) { int len = href.length(); int ch; final StringBuilder buffer = new StringBuilder(len*3); // for each character in the href int i = 0; for (; i < len; i++) { ch = href.charAt(i); // if it's not an ASCII character (excluding 0x7F), break here, and use UTF-8 encoding if (ch > 0x7E) { break; } // abort: href does not allow this character if (ch < 0x20) { return href; } if (gNeedEscaping[ch]) { buffer.append('%'); buffer.append(gAfterEscaping1[ch]); buffer.append(gAfterEscaping2[ch]); } else { buffer.append((char)ch); } } // we saw some non-ascii character if (i < len) { // check if remainder of href contains any illegal characters before proceeding for (int j = i; j < len; ++j) { ch = href.charAt(j); if ((ch >= 0x20 && ch <= 0x7E) || (ch >= 0xA0 && ch <= 0xD7FF) || (ch >= 0xF900 && ch <= 0xFDCF) || (ch >= 0xFDF0 && ch <= 0xFFEF)) { continue; } if (XMLChar.isHighSurrogate(ch) && ++j < len) { int ch2 = href.charAt(j); if (XMLChar.isLowSurrogate(ch2)) { ch2 = XMLChar.supplemental((char)ch, (char)ch2); if (ch2 < 0xF0000 && (ch2 & 0xFFFF) <= 0xFFFD) { continue; } } } // abort: href does not allow this character return href; } // get UTF-8 bytes for the remaining sub-string byte[] bytes = null; byte b; try { bytes = href.substring(i).getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { // should never happen return href; } len = bytes.length; // for each byte for (i = 0; i < len; i++) { b = bytes[i]; // for non-ascii character: make it positive, then escape if (b < 0) { ch = b + 256; buffer.append('%'); buffer.append(gHexChs[ch >> 4]); buffer.append(gHexChs[ch & 0xf]); } else if (gNeedEscaping[b]) { buffer.append('%'); buffer.append(gAfterEscaping1[b]); buffer.append(gAfterEscaping2[b]); } else { buffer.append((char)b); } } } // If escaping happened, create a new string; // otherwise, return the orginal one. if (buffer.length() != len) { return buffer.toString(); } else { return href; } }
Example 15
Source File: XIncludeHandler.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private String escapeHref(String href) { int len = href.length(); int ch; final StringBuilder buffer = new StringBuilder(len*3); // for each character in the href int i = 0; for (; i < len; i++) { ch = href.charAt(i); // if it's not an ASCII character (excluding 0x7F), break here, and use UTF-8 encoding if (ch > 0x7E) { break; } // abort: href does not allow this character if (ch < 0x20) { return href; } if (gNeedEscaping[ch]) { buffer.append('%'); buffer.append(gAfterEscaping1[ch]); buffer.append(gAfterEscaping2[ch]); } else { buffer.append((char)ch); } } // we saw some non-ascii character if (i < len) { // check if remainder of href contains any illegal characters before proceeding for (int j = i; j < len; ++j) { ch = href.charAt(j); if ((ch >= 0x20 && ch <= 0x7E) || (ch >= 0xA0 && ch <= 0xD7FF) || (ch >= 0xF900 && ch <= 0xFDCF) || (ch >= 0xFDF0 && ch <= 0xFFEF)) { continue; } if (XMLChar.isHighSurrogate(ch) && ++j < len) { int ch2 = href.charAt(j); if (XMLChar.isLowSurrogate(ch2)) { ch2 = XMLChar.supplemental((char)ch, (char)ch2); if (ch2 < 0xF0000 && (ch2 & 0xFFFF) <= 0xFFFD) { continue; } } } // abort: href does not allow this character return href; } // get UTF-8 bytes for the remaining sub-string byte[] bytes = null; byte b; try { bytes = href.substring(i).getBytes("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { // should never happen return href; } len = bytes.length; // for each byte for (i = 0; i < len; i++) { b = bytes[i]; // for non-ascii character: make it positive, then escape if (b < 0) { ch = b + 256; buffer.append('%'); buffer.append(gHexChs[ch >> 4]); buffer.append(gHexChs[ch & 0xf]); } else if (gNeedEscaping[b]) { buffer.append('%'); buffer.append(gAfterEscaping1[b]); buffer.append(gAfterEscaping2[b]); } else { buffer.append((char)b); } } } // If escaping happened, create a new string; // otherwise, return the orginal one. if (buffer.length() != len) { return buffer.toString(); } else { return href; } }
Example 16
Source File: UTF8OutputStreamWriter.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void write(int c) throws IOException { // Check in we are encoding at high and low surrogates if (lastUTF16CodePoint != 0) { final int uc = (((lastUTF16CodePoint & 0x3ff) << 10) | (c & 0x3ff)) + 0x10000; if (uc < 0 || uc >= 0x200000) { throw new IOException("Atttempting to write invalid Unicode code point '" + uc + "'"); } out.write(0xF0 | (uc >> 18)); out.write(0x80 | ((uc >> 12) & 0x3F)); out.write(0x80 | ((uc >> 6) & 0x3F)); out.write(0x80 | (uc & 0x3F)); lastUTF16CodePoint = 0; return; } // Otherwise, encode char as defined in UTF-8 if (c < 0x80) { // 1 byte, 7 bits out.write((int) c); } else if (c < 0x800) { // 2 bytes, 11 bits out.write(0xC0 | (c >> 6)); // first 5 out.write(0x80 | (c & 0x3F)); // second 6 } else if (c <= '\uFFFF') { if (!XMLChar.isHighSurrogate(c) && !XMLChar.isLowSurrogate(c)) { // 3 bytes, 16 bits out.write(0xE0 | (c >> 12)); // first 4 out.write(0x80 | ((c >> 6) & 0x3F)); // second 6 out.write(0x80 | (c & 0x3F)); // third 6 } else { lastUTF16CodePoint = c; } } }
Example 17
Source File: XMLDocumentFragmentScannerImpl.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Scans a CDATA section. * <p> * <strong>Note:</strong> This method uses the fTempString and * fStringBuffer variables. * * @param complete True if the CDATA section is to be scanned * completely. * * @return True if CDATA is completely scanned. */ //CHANGED: protected boolean scanCDATASection(XMLStringBuffer contentBuffer, boolean complete) throws IOException, XNIException { // call handler if (fDocumentHandler != null) { //fDocumentHandler.startCDATA(null); } while (true) { //scanData will fill the contentBuffer if (!fEntityScanner.scanData("]]>", contentBuffer)) { break ; /** We dont need all this code if we pass ']]>' as delimeter.. * int brackets = 2; * while (fEntityScanner.skipChar(']')) { * brackets++; * } * * //When we find more than 2 square brackets * if (fDocumentHandler != null && brackets > 2) { * //we dont need to clear the buffer.. * //contentBuffer.clear(); * for (int i = 2; i < brackets; i++) { * contentBuffer.append(']'); * } * fDocumentHandler.characters(contentBuffer, null); * } * * if (fEntityScanner.skipChar('>')) { * break; * } * if (fDocumentHandler != null) { * //we dont need to clear the buffer now.. * //contentBuffer.clear(); * contentBuffer.append("]]"); * fDocumentHandler.characters(contentBuffer, null); * } **/ } else { int c = fEntityScanner.peekChar(); if (c != -1 && isInvalidLiteral(c)) { if (XMLChar.isHighSurrogate(c)) { //contentBuffer.clear(); //scan surrogates if any.... scanSurrogates(contentBuffer); } else { reportFatalError("InvalidCharInCDSect", new Object[]{Integer.toString(c,16)}); fEntityScanner.scanChar(); } } //by this time we have also read surrogate contents if any... if (fDocumentHandler != null) { //fDocumentHandler.characters(contentBuffer, null); } } } fMarkupDepth--; if (fDocumentHandler != null && contentBuffer.length > 0) { //fDocumentHandler.characters(contentBuffer, null); } // call handler if (fDocumentHandler != null) { //fDocumentHandler.endCDATA(null); } return true; }
Example 18
Source File: UTF8OutputStreamWriter.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void write(int c) throws IOException { // Check in we are encoding at high and low surrogates if (lastUTF16CodePoint != 0) { final int uc = (((lastUTF16CodePoint & 0x3ff) << 10) | (c & 0x3ff)) + 0x10000; if (uc < 0 || uc >= 0x200000) { throw new IOException("Atttempting to write invalid Unicode code point '" + uc + "'"); } out.write(0xF0 | (uc >> 18)); out.write(0x80 | ((uc >> 12) & 0x3F)); out.write(0x80 | ((uc >> 6) & 0x3F)); out.write(0x80 | (uc & 0x3F)); lastUTF16CodePoint = 0; return; } // Otherwise, encode char as defined in UTF-8 if (c < 0x80) { // 1 byte, 7 bits out.write((int) c); } else if (c < 0x800) { // 2 bytes, 11 bits out.write(0xC0 | (c >> 6)); // first 5 out.write(0x80 | (c & 0x3F)); // second 6 } else if (c <= '\uFFFF') { if (!XMLChar.isHighSurrogate(c) && !XMLChar.isLowSurrogate(c)) { // 3 bytes, 16 bits out.write(0xE0 | (c >> 12)); // first 4 out.write(0x80 | ((c >> 6) & 0x3F)); // second 6 out.write(0x80 | (c & 0x3F)); // third 6 } else { lastUTF16CodePoint = c; } } }
Example 19
Source File: UTF8OutputStreamWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public void write(int c) throws IOException { // Check in we are encoding at high and low surrogates if (lastUTF16CodePoint != 0) { final int uc = (((lastUTF16CodePoint & 0x3ff) << 10) | (c & 0x3ff)) + 0x10000; if (uc < 0 || uc >= 0x200000) { throw new IOException("Atttempting to write invalid Unicode code point '" + uc + "'"); } out.write(0xF0 | (uc >> 18)); out.write(0x80 | ((uc >> 12) & 0x3F)); out.write(0x80 | ((uc >> 6) & 0x3F)); out.write(0x80 | (uc & 0x3F)); lastUTF16CodePoint = 0; return; } // Otherwise, encode char as defined in UTF-8 if (c < 0x80) { // 1 byte, 7 bits out.write((int) c); } else if (c < 0x800) { // 2 bytes, 11 bits out.write(0xC0 | (c >> 6)); // first 5 out.write(0x80 | (c & 0x3F)); // second 6 } else if (c <= '\uFFFF') { if (!XMLChar.isHighSurrogate(c) && !XMLChar.isLowSurrogate(c)) { // 3 bytes, 16 bits out.write(0xE0 | (c >> 12)); // first 4 out.write(0x80 | ((c >> 6) & 0x3F)); // second 6 out.write(0x80 | (c & 0x3F)); // third 6 } else { lastUTF16CodePoint = c; } } }
Example 20
Source File: XMLScanner.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Scans a processing data. This is needed to handle the situation * where a document starts with a processing instruction whose * target name <em>starts with</em> "xml". (e.g. xmlfoo) * * This method would always read the whole data. We have while loop and data is buffered * until delimeter is encountered. * * @param target The PI target * @param data The string to fill in with the data */ //CHANGED: //Earlier:This method uses the fStringBuffer and later buffer values are set to //the supplied XMLString.... //Now: Changed the signature of this function to pass XMLStringBuffer.. and data would //be appended to that buffer protected void scanPIData(String target, XMLStringBuffer data) throws IOException, XNIException { // check target if (target.length() == 3) { char c0 = Character.toLowerCase(target.charAt(0)); char c1 = Character.toLowerCase(target.charAt(1)); char c2 = Character.toLowerCase(target.charAt(2)); if (c0 == 'x' && c1 == 'm' && c2 == 'l') { reportFatalError("ReservedPITarget", null); } } // spaces if (!fEntityScanner.skipSpaces()) { if (fEntityScanner.skipString("?>")) { // we found the end, there is no data just return return; } else { // if there is data there should be some space reportFatalError("SpaceRequiredInPI", null); } } // since scanData appends the parsed data to the buffer passed // a while loop would append the whole of parsed data to the buffer(data:XMLStringBuffer) //until all of the data is buffered. if (fEntityScanner.scanData("?>", data, 0)) { do { int c = fEntityScanner.peekChar(); if (c != -1) { if (XMLChar.isHighSurrogate(c)) { scanSurrogates(data); } else if (isInvalidLiteral(c)) { reportFatalError("InvalidCharInPI", new Object[]{Integer.toHexString(c)}); fEntityScanner.scanChar(null); } } } while (fEntityScanner.scanData("?>", data, 0)); } }