Java源码示例:com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException

示例1
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();
}
 
示例2
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"));
    }
}
 
示例3
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("");
        }
    }
}
 
示例4
/**
 * 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;
}
 
示例5
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;
    }
}
 
示例6
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);
    }
}
 
示例7
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 "";
    }
}
 
示例8
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"));
    }
}
 
示例9
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();
}
 
示例10
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];
    }
}
 
示例11
/**
 * 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;
}
 
示例12
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"));
    }
}
 
示例13
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];
    }
}
 
示例14
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);
    }
}
 
示例15
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);
}
 
示例16
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;
}
 
示例17
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;
}
 
示例18
protected final void decodeDII() throws FastInfosetException, IOException {
    final int b = read();
    if (b == EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) {
        decodeInitialVocabulary();
    } else if (b != 0) {
        throw new IOException(CommonResourceBundle.getInstance().
                getString("message.optinalValues"));
    }
}
 
示例19
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;
    }
}
 
示例20
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;
}
 
示例21
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;
}
 
示例22
/**
 * Encode a chunk of Character Information Items using a restricted
 * alphabet that results in the encoding of a character in 4 bits
 * (or two characters per octet).
 *
 * @param id the restricted alphabet identifier.
 * @param table the table mapping characters to 4 bit values.
 * @param ch the array of characters.
 * @param offset the offset into the array of characters.
 * @param length the length of characters.
 * @param addToTable if characters should be added to table.
 * @throws ArrayIndexOutOfBoundsException.
 */
protected final void encodeFourBitCharacters(int id, int[] table, char[] ch, int offset, int length,
        boolean addToTable) throws FastInfosetException, IOException {
    if (addToTable) {
        // if char array could be added to table
        boolean canAddCharacterContentToTable =
                canAddCharacterContentToTable(length, _v.characterContentChunk);

        // obtain/get index
        int index = canAddCharacterContentToTable ?
            _v.characterContentChunk.obtainIndex(ch, offset, length, true) :
            _v.characterContentChunk.get(ch, offset, length);

        if (index != KeyIntMap.NOT_PRESENT) {
            // if char array is in table
            _b = EncodingConstants.CHARACTER_CHUNK | 0x20;
            encodeNonZeroIntegerOnFourthBit(index);
            return;
        } else if (canAddCharacterContentToTable) {
            // if char array is not in table, but could be added
            _b = EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG | EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG;
        } else {
            // if char array is not in table and could not be added
            _b = EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG;
        }
    } else {
        _b = EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG;
    }

    write (_b);

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

    encodeNonEmptyFourBitCharacterStringOnSeventhBit(table, ch, offset, length);
}
 
示例23
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);
}
 
示例24
/**
 * Encode a chunk of Character Information Items using a restricted
 * alphabet that results in the encoding of a character in 4 bits
 * (or two characters per octet).
 *
 * @param id the restricted alphabet identifier.
 * @param table the table mapping characters to 4 bit values.
 * @param ch the array of characters.
 * @param offset the offset into the array of characters.
 * @param length the length of characters.
 * @param addToTable if characters should be added to table.
 * @throws ArrayIndexOutOfBoundsException.
 */
protected final void encodeFourBitCharacters(int id, int[] table, char[] ch, int offset, int length,
        boolean addToTable) throws FastInfosetException, IOException {
    if (addToTable) {
        // if char array could be added to table
        boolean canAddCharacterContentToTable =
                canAddCharacterContentToTable(length, _v.characterContentChunk);

        // obtain/get index
        int index = canAddCharacterContentToTable ?
            _v.characterContentChunk.obtainIndex(ch, offset, length, true) :
            _v.characterContentChunk.get(ch, offset, length);

        if (index != KeyIntMap.NOT_PRESENT) {
            // if char array is in table
            _b = EncodingConstants.CHARACTER_CHUNK | 0x20;
            encodeNonZeroIntegerOnFourthBit(index);
            return;
        } else if (canAddCharacterContentToTable) {
            // if char array is not in table, but could be added
            _b = EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG | EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG;
        } else {
            // if char array is not in table and could not be added
            _b = EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG;
        }
    } else {
        _b = EncodingConstants.CHARACTER_CHUNK | EncodingConstants.CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG;
    }

    write (_b);

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

    encodeNonEmptyFourBitCharacterStringOnSeventhBit(table, ch, offset, length);
}
 
示例25
private void decodeTableItems(ContiguousCharArrayArray array) throws FastInfosetException, IOException {
    final int noOfItems = decodeNumberOfItemsOfSequence();

    for (int i = 0; i < noOfItems; i++) {
        switch(decodeNonIdentifyingStringOnFirstBit()) {
            case NISTRING_STRING:
                array.add(_charBuffer, _charBufferLength);
                break;
            default:
                throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.illegalState"));
        }
    }
}
 
示例26
/**
 * 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 encoding algorithm identifier.
 * @param data the data to be encoded using an encoding algorithm.
 * @param ea the encoding algorithm to use to encode the data into an
 *           array of bytes.
 */
protected final void encodeCIIObjectAlgorithmData(int id, Object data, EncodingAlgorithm ea) 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;

    _encodingBufferOutputStream.reset();
    ea.encodeToOutputStream(data, _encodingBufferOutputStream);
    encodeNonZeroOctetStringLengthOnSenventhBit(_encodingBufferIndex);
    write(_encodingBuffer, _encodingBufferIndex);
}
 
示例27
/**
 * 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);
}
 
示例28
/**
 * Encode a non empty string on the seventh bit of an octet using a restricted
 * alphabet table.
 * Implementation of clause C.24 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
 *
 * @param alphabet the alphabet defining the mapping between characters and
 *        integer values.
 * @param ch the array of characters.
 * @param offset the offset into the array of characters.
 * @param length the length of characters.
 */
protected final void encodeNonEmptyNBitCharacterStringOnSeventhBit(String alphabet, char[] ch, int offset, int length) throws FastInfosetException, IOException {
    int bitsPerCharacter = 1;
    while ((1 << bitsPerCharacter) <= alphabet.length()) {
        bitsPerCharacter++;
    }

    final int bits = length * bitsPerCharacter;
    final int octets = bits / 8;
    final int bitsOfLastOctet = bits % 8;
    final int totalOctets = octets + ((bitsOfLastOctet > 0) ? 1 : 0);

    // Encode the length
    encodeNonZeroOctetStringLengthOnSenventhBit(totalOctets);

    resetBits();
    ensureSize(totalOctets);
    int v = 0;
    for (int i = 0; i < length; i++) {
        final char c = ch[offset + i];
        // This is grotesquely slow, need to use hash table of character to int value
        for (v = 0; v < alphabet.length(); v++) {
            if (c == alphabet.charAt(v)) {
                break;
            }
        }
        if (v == alphabet.length()) {
            throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.characterOutofAlphabetRange"));
        }
        writeBits(bitsPerCharacter, v);
    }

    if (bitsOfLastOctet > 0) {
        _b |= (1 << (8 - bitsOfLastOctet)) - 1;
        write(_b);
    }
}
 
示例29
/**
 * Encode the [normalized value] of an Attribute Information Item using
 * using an encoding algorithm.
 * Implementation of clause C.14 of ITU-T Rec. X.891 | ISO/IEC 24824-1.
 *
 * @param id the encoding algorithm identifier.
 * @param data the data to be encoded using an encoding algorithm.
 * @param ea the encoding algorithm to use to encode the data into an
 *           array of bytes.
 */
protected final void encodeAIIObjectAlgorithmData(int id, Object data, EncodingAlgorithm ea) throws FastInfosetException, IOException {
    // Encode identification and top four bits of encoding algorithm id
    write (EncodingConstants.NISTRING_ENCODING_ALGORITHM_FLAG |
            ((id & 0xF0) >> 4));

    // Encode bottom 4 bits of enoding algorithm id
    _b = (id & 0x0F) << 4;

    _encodingBufferOutputStream.reset();
    ea.encodeToOutputStream(data, _encodingBufferOutputStream);
    encodeNonZeroOctetStringLengthOnFifthBit(_encodingBufferIndex);
    write(_encodingBuffer, _encodingBufferIndex);
}
 
示例30
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}));
    }
}