com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException Java Examples

The following examples show how to use com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException. 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: DOMDocumentParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected String convertEncodingAlgorithmDataToCharacters(boolean isAttributeValue) throws FastInfosetException, IOException {
    StringBuffer buffer = new StringBuffer();
    if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).
                decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
        BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array,  buffer);
    } else if (_identifier == EncodingAlgorithmIndexes.CDATA) {
        if (!isAttributeValue) {
            // Set back buffer position to start of encoded string
            _octetBufferOffset -= _octetBufferLength;
            return decodeUtf8StringAsString();
        }
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
    } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
        final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
        if (ea != null) {
            final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
            ea.convertToCharacters(data, buffer);
        } else {
            throw new EncodingAlgorithmException(
                    CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
        }
    }
    return buffer.toString();
}
 
Example #2
Source File: Encoder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encode a chunk of Character Information Items using
 * using an encoding algorithm.
 * Implementation of clause C.15 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
 *
 * @param id the built in encoding algorithm identifier.
 * @param data the data to be encoded using an encoding algorithm. The data
 *        represents an array of items specified by the encoding algorithm
 *        identifier
 * @param offset the offset into the array of bytes.
 * @param length the length of bytes.
 */
protected final void encodeCIIBuiltInAlgorithmData(int id, Object data, int offset, int length) throws FastInfosetException, IOException {
    // Encode identification and top two bits of encoding algorithm id
    write (EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_ENCODING_ALGORITHM_FLAG |
            ((id & 0xC0) >> 6));

    // Encode bottom 6 bits of enoding algorithm id
    _b = (id & 0x3F) << 2;

    final int octetLength = BuiltInEncodingAlgorithmFactory.getAlgorithm(id).
                getOctetLengthFromPrimitiveLength(length);

    encodeNonZeroOctetStringLengthOnSenventhBit(octetLength);

    ensureSize(octetLength);
    BuiltInEncodingAlgorithmFactory.getAlgorithm(id).
            encodeToBytes(data, offset, length, _octetBuffer, _octetBufferIndex);
    _octetBufferIndex += octetLength;
}
 
Example #3
Source File: DOMDocumentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected String convertEncodingAlgorithmDataToCharacters(boolean isAttributeValue) throws FastInfosetException, IOException {
    StringBuffer buffer = new StringBuffer();
    if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).
                decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
        BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array,  buffer);
    } else if (_identifier == EncodingAlgorithmIndexes.CDATA) {
        if (!isAttributeValue) {
            // Set back buffer position to start of encoded string
            _octetBufferOffset -= _octetBufferLength;
            return decodeUtf8StringAsString();
        }
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
    } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
        final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
        if (ea != null) {
            final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
            ea.convertToCharacters(data, buffer);
        } else {
            throw new EncodingAlgorithmException(
                    CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
        }
    }
    return buffer.toString();
}
 
Example #4
Source File: Decoder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected final void decodeFourBitAlphabetOctetsAsCharBuffer(char[] restrictedAlphabet) throws FastInfosetException, IOException {
    _charBufferLength = 0;
    final int characters = _octetBufferLength * 2;
    if (_charBuffer.length < characters) {
        _charBuffer = new char[characters];
    }

    int v = 0;
    for (int i = 0; i < _octetBufferLength - 1; i++) {
        v = _octetBuffer[_octetBufferStart++] & 0xFF;
        _charBuffer[_charBufferLength++] = restrictedAlphabet[v >> 4];
        _charBuffer[_charBufferLength++] = restrictedAlphabet[v & 0x0F];
    }
    v = _octetBuffer[_octetBufferStart++] & 0xFF;
    _charBuffer[_charBufferLength++] = restrictedAlphabet[v >> 4];
    v &= 0x0F;
    if (v != 0x0F) {
        _charBuffer[_charBufferLength++] = restrictedAlphabet[v & 0x0F];
    }
}
 
Example #5
Source File: Encoder.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Encode a chunk of Character Information Items using
 * using an encoding algorithm.
 * Implementation of clause C.15 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
 *
 * @param id the built in encoding algorithm identifier.
 * @param data the data to be encoded using an encoding algorithm. The data
 *        represents an array of items specified by the encoding algorithm
 *        identifier
 * @param offset the offset into the array of bytes.
 * @param length the length of bytes.
 */
protected final void encodeCIIBuiltInAlgorithmData(int id, Object data, int offset, int length) throws FastInfosetException, IOException {
    // Encode identification and top two bits of encoding algorithm id
    write (EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_ENCODING_ALGORITHM_FLAG |
            ((id & 0xC0) >> 6));

    // Encode bottom 6 bits of enoding algorithm id
    _b = (id & 0x3F) << 2;

    final int octetLength = BuiltInEncodingAlgorithmFactory.getAlgorithm(id).
                getOctetLengthFromPrimitiveLength(length);

    encodeNonZeroOctetStringLengthOnSenventhBit(octetLength);

    ensureSize(octetLength);
    BuiltInEncodingAlgorithmFactory.getAlgorithm(id).
            encodeToBytes(data, offset, length, _octetBuffer, _octetBufferIndex);
    _octetBufferIndex += octetLength;
}
 
Example #6
Source File: Encoder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected final void encodeNonEmptyFourBitCharacterString(int[] table, char[] ch, int offset,
        int octetPairLength, int octetSingleLength) throws FastInfosetException, IOException {
    ensureSize(octetPairLength + octetSingleLength);
    // Encode all pairs
    int v = 0;
    for (int i = 0; i < octetPairLength; i++) {
        v = (table[ch[offset++]] << 4) | table[ch[offset++]];
        if (v < 0) {
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.characterOutofAlphabetRange"));
        }
        _octetBuffer[_octetBufferIndex++] = (byte)v;
    }
    // Encode single character at end with termination bits
    if (octetSingleLength == 1) {
        v = (table[ch[offset]] << 4) | 0x0F;
        if (v < 0) {
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.characterOutofAlphabetRange"));
        }
        _octetBuffer[_octetBufferIndex++] = (byte)v;
    }
}
 
Example #7
Source File: Decoder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected final int decodeIntegerIndexOnSecondBit() throws FastInfosetException, IOException {
    final int b = read() | 0x80;
    switch(DecoderStateTables.ISTRING(b)) {
        case DecoderStateTables.ISTRING_INDEX_SMALL:
            return b & EncodingConstants.INTEGER_2ND_BIT_SMALL_MASK;
        case DecoderStateTables.ISTRING_INDEX_MEDIUM:
            return (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read())
            + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT;
        case DecoderStateTables.ISTRING_INDEX_LARGE:
            return (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read())
            + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT;
        case DecoderStateTables.ISTRING_SMALL_LENGTH:
        case DecoderStateTables.ISTRING_MEDIUM_LENGTH:
        case DecoderStateTables.ISTRING_LARGE_LENGTH:
        default:
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingIndexOnSecondBit"));
    }
}
 
Example #8
Source File: StAXDocumentParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected final void processCIIEncodingAlgorithm(boolean addToTable) throws FastInfosetException, IOException {
    _algorithmData = _octetBuffer;
    _algorithmDataOffset = _octetBufferStart;
    _algorithmDataLength = _octetBufferLength;
    _isAlgorithmDataCloned = false;

    if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        _algorithmURI = _v.encodingAlgorithm.get(_algorithmId - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
        if (_algorithmURI == null) {
            throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent", new Object[]{Integer.valueOf(_identifier)}));
        }
    } else if (_algorithmId > EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        // Reserved built-in algorithms for future use
        // TODO should use sax property to decide if event will be
        // reported, allows for support through handler if required.
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved"));
    }

    if (addToTable) {
        convertEncodingAlgorithmDataToCharacters();
        _characterContentChunkTable.add(_characters, _characters.length);
    }
}
 
Example #9
Source File: Decoder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected final void decodeNonEmptyOctetStringLengthOnSecondBit() throws FastInfosetException, IOException {
    final int b = read();
    switch(DecoderStateTables.ISTRING(b)) {
        case DecoderStateTables.ISTRING_SMALL_LENGTH:
            _octetBufferLength = b + 1;
            break;
        case DecoderStateTables.ISTRING_MEDIUM_LENGTH:
            _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_2ND_BIT_SMALL_LIMIT;
            break;
        case DecoderStateTables.ISTRING_LARGE_LENGTH:
        {
            final int length = (read() << 24) |
                    (read() << 16) |
                    (read() << 8) |
                    read();
            _octetBufferLength = length + EncodingConstants.OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_LIMIT;
            break;
        }
        case DecoderStateTables.ISTRING_INDEX_SMALL:
        case DecoderStateTables.ISTRING_INDEX_MEDIUM:
        case DecoderStateTables.ISTRING_INDEX_LARGE:
        default:
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingNonEmptyOctet"));
    }
}
 
Example #10
Source File: Decoder.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected final int decodeIntegerIndexOnSecondBit() throws FastInfosetException, IOException {
    final int b = read() | 0x80;
    switch(DecoderStateTables.ISTRING(b)) {
        case DecoderStateTables.ISTRING_INDEX_SMALL:
            return b & EncodingConstants.INTEGER_2ND_BIT_SMALL_MASK;
        case DecoderStateTables.ISTRING_INDEX_MEDIUM:
            return (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read())
            + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT;
        case DecoderStateTables.ISTRING_INDEX_LARGE:
            return (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read())
            + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT;
        case DecoderStateTables.ISTRING_SMALL_LENGTH:
        case DecoderStateTables.ISTRING_MEDIUM_LENGTH:
        case DecoderStateTables.ISTRING_LARGE_LENGTH:
        default:
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingIndexOnSecondBit"));
    }
}
 
Example #11
Source File: SAXDocumentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void parse(InputSource input) throws IOException, SAXException {
    try {
        InputStream s = input.getByteStream();
        if (s == null) {
            String systemId = input.getSystemId();
            if (systemId == null) {
                throw new SAXException(CommonResourceBundle.getInstance().getString("message.inputSource"));
            }
            parse(systemId);
        } else {
            parse(s);
        }
    } catch (FastInfosetException e) {
        logger.log(Level.FINE, "parsing error", e);
        throw new SAXException(e);
    }
}
 
Example #12
Source File: Decoder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected final String decodeVersion() throws FastInfosetException, IOException {
    switch(decodeNonIdentifyingStringOnFirstBit()) {
        case NISTRING_STRING:
            final String data = new String(_charBuffer, 0, _charBufferLength);
            if (_addToTable) {
                _v.otherString.add(new CharArrayString(data));
            }
            return data;
        case NISTRING_ENCODING_ALGORITHM:
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingNotSupported"));
        case NISTRING_INDEX:
            return _v.otherString.get(_integer).toString();
        case NISTRING_EMPTY_STRING:
        default:
            return "";
    }
}
 
Example #13
Source File: Decoder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected final void decodeFourBitAlphabetOctetsAsCharBuffer(char[] restrictedAlphabet) throws FastInfosetException, IOException {
    _charBufferLength = 0;
    final int characters = _octetBufferLength * 2;
    if (_charBuffer.length < characters) {
        _charBuffer = new char[characters];
    }

    int v = 0;
    for (int i = 0; i < _octetBufferLength - 1; i++) {
        v = _octetBuffer[_octetBufferStart++] & 0xFF;
        _charBuffer[_charBufferLength++] = restrictedAlphabet[v >> 4];
        _charBuffer[_charBufferLength++] = restrictedAlphabet[v & 0x0F];
    }
    v = _octetBuffer[_octetBufferStart++] & 0xFF;
    _charBuffer[_charBufferLength++] = restrictedAlphabet[v >> 4];
    v &= 0x0F;
    if (v != 0x0F) {
        _charBuffer[_charBufferLength++] = restrictedAlphabet[v & 0x0F];
    }
}
 
Example #14
Source File: DOMDocumentSerializer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected final void serializeCDATA(Node t) throws IOException {
    final String text = t.getNodeValue();

    final int length = (text != null) ? text.length() : 0;
    if (length == 0) {
        return;
    } else {
        final char ch[] = text.toCharArray();
        if (getIgnoreWhiteSpaceTextContent() &&
                isWhiteSpace(ch, 0, length)) return;

        encodeTermination();
        try {
            encodeCIIBuiltInAlgorithmDataAsCDATA(ch, 0, length);
        } catch (FastInfosetException e) {
            throw new IOException("");
        }
    }
}
 
Example #15
Source File: SAXDocumentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected final void processBuiltInEncodingAlgorithmAsCharacters(StringBuffer buffer) throws FastInfosetException, IOException {
    // TODO not very efficient, need to reuse buffers
    Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).
            decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);

    BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array,  buffer);
}
 
Example #16
Source File: DOMDocumentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected final QualifiedName processLiteralQualifiedName(int state)
throws FastInfosetException, IOException {
    switch (state) {
        // no prefix, no namespace
        case 0:
            return new QualifiedName(
                    null,
                    null,
                    decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
                    -1,
                    -1,
                    _identifier,
                    null);
            // no prefix, namespace
        case 1:
            return new QualifiedName(
                    null,
                    decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(false),
                    decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
                    -1,
                    _namespaceNameIndex,
                    _identifier,
                    null);
            // prefix, no namespace
        case 2:
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qNameMissingNamespaceName"));
            // prefix, namespace
        case 3:
            return new QualifiedName(
                    decodeIdentifyingNonEmptyStringIndexOnFirstBitAsPrefix(true),
                    decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(true),
                    decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
                    _prefixIndex,
                    _namespaceNameIndex,
                    _identifier,
                    _charBuffer);
        default:
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingEII"));
    }
}
 
Example #17
Source File: DOMDocumentParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private final String processUtf8CharacterString() throws FastInfosetException, IOException {
    if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
        _characterContentChunkTable.ensureSize(_octetBufferLength);
        final int charactersOffset = _characterContentChunkTable._arrayIndex;
        decodeUtf8StringAsCharBuffer(_characterContentChunkTable._array, charactersOffset);
        _characterContentChunkTable.add(_charBufferLength);
        return _characterContentChunkTable.getString(_characterContentChunkTable._cachedIndex);
    } else {
        decodeUtf8StringAsCharBuffer();
        return new String(_charBuffer, 0, _charBufferLength);
    }
}
 
Example #18
Source File: Decoder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void decodeTableItems(PrefixArray array) throws FastInfosetException, IOException {
    final int noOfItems = decodeNumberOfItemsOfSequence();

    for (int i = 0; i < noOfItems; i++) {
        array.add(decodeNonEmptyOctetStringOnSecondBitAsUtf8String());
    }
}
 
Example #19
Source File: DuplicateAttributeVerifier.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public final void checkForDuplicateAttribute(int hash, int value) throws FastInfosetException {
    if (_poolCurrent == null) {
        increasePool(16);
    }

    // Get next free entry
    final Entry newEntry = _poolCurrent;
    _poolCurrent = _poolCurrent.poolNext;

    final Entry head = _map[hash];
    if (head == null || head.iteration < _currentIteration) {
        newEntry.hashNext = null;
        _map[hash] = newEntry;
        newEntry.iteration = _currentIteration;
        newEntry.value = value;
    } else {
        Entry e = head;
        do {
            if (e.value == value) {
                reset();
                throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.duplicateAttribute"));
            }
        } while ((e = e.hashNext) != null);

        newEntry.hashNext = head;
        _map[hash] = newEntry;
        newEntry.iteration = _currentIteration;
        newEntry.value = value;
    }
}
 
Example #20
Source File: SAXDocumentParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected final void processBuiltInEncodingAlgorithmAsCharacters(StringBuffer buffer) throws FastInfosetException, IOException {
    // TODO not very efficient, need to reuse buffers
    Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).
            decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);

    BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array,  buffer);
}
 
Example #21
Source File: StAXDocumentParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected final void processEII(QualifiedName name, boolean hasAttributes) throws FastInfosetException, IOException {
    if (_prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) {
        throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qnameOfEIINotInScope"));
    }

    _eventType = START_ELEMENT;
    _qualifiedName = name;

    if (_clearAttributes) {
        _attributes.clear();
        _clearAttributes = false;
    }

    if (hasAttributes) {
        processAIIs();
    }

    // Push element holder onto the stack
    _stackCount++;
    if (_stackCount == _qNameStack.length) {
        QualifiedName[] qNameStack = new QualifiedName[_qNameStack.length * 2];
        System.arraycopy(_qNameStack, 0, qNameStack, 0, _qNameStack.length);
        _qNameStack = qNameStack;

        int[] namespaceAIIsStartStack = new int[_namespaceAIIsStartStack.length * 2];
        System.arraycopy(_namespaceAIIsStartStack, 0, namespaceAIIsStartStack, 0, _namespaceAIIsStartStack.length);
        _namespaceAIIsStartStack = namespaceAIIsStartStack;

        int[] namespaceAIIsEndStack = new int[_namespaceAIIsEndStack.length * 2];
        System.arraycopy(_namespaceAIIsEndStack, 0, namespaceAIIsEndStack, 0, _namespaceAIIsEndStack.length);
        _namespaceAIIsEndStack = namespaceAIIsEndStack;
    }
    _qNameStack[_stackCount] = _qualifiedName;
    _namespaceAIIsStartStack[_stackCount] = _currentNamespaceAIIsStart;
    _namespaceAIIsEndStack[_stackCount] = _currentNamespaceAIIsEnd;
}
 
Example #22
Source File: StAXDocumentParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected final QualifiedName processEIIIndexLarge(int b) throws FastInfosetException, IOException {
    int i;
    if ((b & EncodingConstants.INTEGER_3RD_BIT_LARGE_LARGE_FLAG) == 0x20) {
        // EII large index
        i = (((b & EncodingConstants.INTEGER_3RD_BIT_LARGE_MASK) << 16) | (read() << 8) | read())
        + EncodingConstants.INTEGER_3RD_BIT_MEDIUM_LIMIT;
    } else {
        // EII large large index
        i = (((read() & EncodingConstants.INTEGER_3RD_BIT_LARGE_LARGE_MASK) << 16) | (read() << 8) | read())
        + EncodingConstants.INTEGER_3RD_BIT_LARGE_LIMIT;
    }
    return _elementNameTable._array[i];
}
 
Example #23
Source File: StAXDocumentParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected final void processCommentII() throws FastInfosetException, IOException {
    _eventType = COMMENT;

    switch(decodeNonIdentifyingStringOnFirstBit()) {
        case NISTRING_STRING:
            if (_addToTable) {
                _v.otherString.add(new CharArray(_charBuffer, 0, _charBufferLength, true));
            }

            _characters = _charBuffer;
            _charactersOffset = 0;
            break;
        case NISTRING_ENCODING_ALGORITHM:
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.commentIIAlgorithmNotSupported"));
        case NISTRING_INDEX:
            final CharArray ca = _v.otherString.get(_integer);

            _characters = ca.ch;
            _charactersOffset = ca.start;
            _charBufferLength = ca.length;
            break;
        case NISTRING_EMPTY_STRING:
            _characters = _charBuffer;
            _charactersOffset = 0;
            _charBufferLength = 0;
            break;
    }
}
 
Example #24
Source File: Decoder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void decodeExternalVocabularyURI() throws FastInfosetException, IOException {
    if (_externalVocabularies == null) {
        throw new IOException(CommonResourceBundle.
                getInstance().getString("message.noExternalVocabularies"));
    }

    String externalVocabularyURI =
            decodeNonEmptyOctetStringOnSecondBitAsUtf8String();

    Object o = _externalVocabularies.get(externalVocabularyURI);
    if (o instanceof ParserVocabulary) {
        _v.setReferencedVocabulary(externalVocabularyURI,
                (ParserVocabulary)o, false);
    } else if (o instanceof com.sun.xml.internal.org.jvnet.fastinfoset.ExternalVocabulary) {
        com.sun.xml.internal.org.jvnet.fastinfoset.ExternalVocabulary v =
                (com.sun.xml.internal.org.jvnet.fastinfoset.ExternalVocabulary)o;
        ParserVocabulary pv = new ParserVocabulary(v.vocabulary);

        _externalVocabularies.put(externalVocabularyURI, pv);
        _v.setReferencedVocabulary(externalVocabularyURI,
                pv, false);
    } else {
        throw new FastInfosetException(CommonResourceBundle.getInstance().
                getString("message.externalVocabularyNotRegistered",
                new Object[]{externalVocabularyURI}));
    }
}
 
Example #25
Source File: Decoder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void decodeTableItems(QualifiedNameArray array, boolean isAttribute) throws FastInfosetException, IOException {
    final int noOfItems = decodeNumberOfItemsOfSequence();

    for (int i = 0; i < noOfItems; i++) {
        final int b = read();

        String prefix = "";
        int prefixIndex = -1;
        if ((b & EncodingConstants.NAME_SURROGATE_PREFIX_FLAG) > 0) {
            prefixIndex = decodeIntegerIndexOnSecondBit();
            prefix = _v.prefix.get(prefixIndex);
        }

        String namespaceName = "";
        int namespaceNameIndex = -1;
        if ((b & EncodingConstants.NAME_SURROGATE_NAME_FLAG) > 0) {
            namespaceNameIndex = decodeIntegerIndexOnSecondBit();
            namespaceName = _v.namespaceName.get(namespaceNameIndex);
        }

        if (namespaceName == "" && prefix != "") {
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.missingNamespace"));
        }

        final int localNameIndex = decodeIntegerIndexOnSecondBit();
        final String localName = _v.localName.get(localNameIndex);

        QualifiedName qualifiedName = new QualifiedName(prefix, namespaceName, localName,
                prefixIndex, namespaceNameIndex, localNameIndex,
                _charBuffer);
        if (isAttribute) {
            qualifiedName.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE);
        }
        array.add(qualifiedName);
    }
}
 
Example #26
Source File: Decoder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void decodeTableItems(QualifiedNameArray array, boolean isAttribute) throws FastInfosetException, IOException {
    final int noOfItems = decodeNumberOfItemsOfSequence();

    for (int i = 0; i < noOfItems; i++) {
        final int b = read();

        String prefix = "";
        int prefixIndex = -1;
        if ((b & EncodingConstants.NAME_SURROGATE_PREFIX_FLAG) > 0) {
            prefixIndex = decodeIntegerIndexOnSecondBit();
            prefix = _v.prefix.get(prefixIndex);
        }

        String namespaceName = "";
        int namespaceNameIndex = -1;
        if ((b & EncodingConstants.NAME_SURROGATE_NAME_FLAG) > 0) {
            namespaceNameIndex = decodeIntegerIndexOnSecondBit();
            namespaceName = _v.namespaceName.get(namespaceNameIndex);
        }

        if (namespaceName == "" && prefix != "") {
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.missingNamespace"));
        }

        final int localNameIndex = decodeIntegerIndexOnSecondBit();
        final String localName = _v.localName.get(localNameIndex);

        QualifiedName qualifiedName = new QualifiedName(prefix, namespaceName, localName,
                prefixIndex, namespaceNameIndex, localNameIndex,
                _charBuffer);
        if (isAttribute) {
            qualifiedName.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE);
        }
        array.add(qualifiedName);
    }
}
 
Example #27
Source File: StAXDocumentParser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected final void convertEncodingAlgorithmDataToCharacters() throws FastInfosetException, IOException {
    StringBuffer buffer = new StringBuffer();
    if (_algorithmId == EncodingAlgorithmIndexes.BASE64) {
        convertBase64AlorithmDataToCharacters(buffer);
    } else if (_algorithmId < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
        Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_algorithmId).
                decodeFromBytes(_algorithmData, _algorithmDataOffset, _algorithmDataLength);
        BuiltInEncodingAlgorithmFactory.getAlgorithm(_algorithmId).convertToCharacters(array,  buffer);
    } else if (_algorithmId == EncodingAlgorithmIndexes.CDATA) {
        _octetBufferOffset -= _octetBufferLength;
        decodeUtf8StringIntoCharBuffer();

        _characters = _charBuffer;
        _charactersOffset = 0;
        return;
    } else if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
        final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(_algorithmURI);
        if (ea != null) {
            final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
            ea.convertToCharacters(data, buffer);
        } else {
            throw new EncodingAlgorithmException(
                    CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
        }
    }

    _characters = new char[buffer.length()];
    buffer.getChars(0, buffer.length(), _characters, 0);
    _charactersOffset = 0;
    _charBufferLength = _characters.length;
}
 
Example #28
Source File: Encoder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Encode a chunk of Character Information Items using
 * using the CDATA built in encoding algorithm.
 * Implementation of clause C.15 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
 *
 * @param ch the array of characters.
 * @param offset the offset into the array of characters.
 * @param length the length of characters.
 */
protected final void encodeCIIBuiltInAlgorithmDataAsCDATA(char[] ch, int offset, int length) throws FastInfosetException, IOException {
    // Encode identification and top two bits of encoding algorithm id
    write (EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_ENCODING_ALGORITHM_FLAG);

    // Encode bottom 6 bits of enoding algorithm id
    _b = EncodingAlgorithmIndexes.CDATA << 2;


    length = encodeUTF8String(ch, offset, length);
    encodeNonZeroOctetStringLengthOnSenventhBit(length);
    write(_encodingBuffer, length);
}
 
Example #29
Source File: Encoder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected final void encodeDateTimeNonIdentifyingStringOnFirstBit(
        String s, boolean addToTable, boolean mustBeAddedToTable)
        throws IOException, FastInfosetException {
    encodeNonIdentifyingStringOnFirstBit(
                                RestrictedAlphabet.DATE_TIME_CHARACTERS_INDEX,
                                DATE_TIME_CHARACTERS_TABLE, s, addToTable,
                                mustBeAddedToTable);
}
 
Example #30
Source File: Decoder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected final void decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(int b) throws FastInfosetException, IOException {
    // Remove top 6 bits of restricted alphabet or encoding algorithm integer
    switch (b & 0x03) {
        // Small length
        case 0:
            _octetBufferLength = 1;
            break;
            // Small length
        case 1:
            _octetBufferLength = 2;
            break;
            // Medium length
        case 2:
            _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
            break;
            // Large length
        case 3:
            _octetBufferLength = (read() << 24) |
                    (read() << 16) |
                    (read() << 8) |
                    read();
            _octetBufferLength += EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
            break;
    }

    ensureOctetBufferSize();
    _octetBufferStart = _octetBufferOffset;
    _octetBufferOffset += _octetBufferLength;
}