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

The following examples show how to use com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException. 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 openjdk-jdk8u-backup 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: StAXDocumentParser.java    From openjdk-jdk8u 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 #3
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 #4
Source File: StAXDocumentParser.java    From openjdk-jdk9 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 #5
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 #6
Source File: FloatEncodingAlgorithm.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % FLOAT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfFloat", new Object[]{Integer.valueOf(FLOAT_SIZE)}));
    }

    return octetLength / FLOAT_SIZE;
}
 
Example #7
Source File: LongEncodingAlgorithm.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % LONG_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfLong", new Object[]{Integer.valueOf(LONG_SIZE)}));
    }

    return octetLength / LONG_SIZE;
}
 
Example #8
Source File: StAXDocumentParser.java    From TencentKona-8 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 #9
Source File: StAXDocumentParser.java    From openjdk-jdk9 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 #10
Source File: FloatEncodingAlgorithm.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % FLOAT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfFloat", new Object[]{Integer.valueOf(FLOAT_SIZE)}));
    }

    return octetLength / FLOAT_SIZE;
}
 
Example #11
Source File: UUIDEncodingAlgorithm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % (LONG_SIZE * 2) != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfUUID",new Object[]{Integer.valueOf(LONG_SIZE * 2)}));
    }

    return octetLength / LONG_SIZE;
}
 
Example #12
Source File: ShortEncodingAlgorithm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % SHORT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfShort", new Object[]{Integer.valueOf(SHORT_SIZE)}));
    }

    return octetLength / SHORT_SIZE;
}
 
Example #13
Source File: DoubleEncodingAlgorithm.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % DOUBLE_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthIsNotMultipleOfDouble", new Object[]{Integer.valueOf(DOUBLE_SIZE)}));
    }

    return octetLength / DOUBLE_SIZE;
}
 
Example #14
Source File: BooleanEncodingAlgorithm.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
    final int blength = getPrimtiveLengthFromOctetLength(length, b[start]);
    boolean[] data = new boolean[blength];

    decodeFromBytesToBooleanArray(data, 0, blength, b, start, length);
    return data;
}
 
Example #15
Source File: ShortEncodingAlgorithm.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % SHORT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfShort", new Object[]{Integer.valueOf(SHORT_SIZE)}));
    }

    return octetLength / SHORT_SIZE;
}
 
Example #16
Source File: DoubleEncodingAlgorithm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % DOUBLE_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthIsNotMultipleOfDouble", new Object[]{Integer.valueOf(DOUBLE_SIZE)}));
    }

    return octetLength / DOUBLE_SIZE;
}
 
Example #17
Source File: UUIDEncodingAlgorithm.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % (LONG_SIZE * 2) != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfUUID",new Object[]{Integer.valueOf(LONG_SIZE * 2)}));
    }

    return octetLength / LONG_SIZE;
}
 
Example #18
Source File: StAXDocumentParser.java    From openjdk-jdk8u 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 #19
Source File: StAXDocumentParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected void convertBase64AlorithmDataToCharacters(StringBuffer buffer) throws EncodingAlgorithmException, IOException {
    // How much new came data was serialized with prev. tale
    int afterTaleOffset = 0;

    if (base64TaleLength > 0) {
        // Serialize tale left from prev. chunk
        int bytesToCopy = Math.min(3 - base64TaleLength, _algorithmDataLength);
        System.arraycopy(_algorithmData, _algorithmDataOffset, base64TaleBytes, base64TaleLength, bytesToCopy);
        if (base64TaleLength + bytesToCopy == 3) {
            base64DecodeWithCloning(buffer, base64TaleBytes, 0, 3);
        } else if (!isBase64Follows()) {
            // End of text was read to temp array
            base64DecodeWithCloning(buffer, base64TaleBytes, 0, base64TaleLength + bytesToCopy);
            return;
        } else {
            // If the end of chunk fit to tmp array, but next chunk is expected
            base64TaleLength += bytesToCopy;
            return;
        }

        afterTaleOffset = bytesToCopy;
        base64TaleLength = 0;
    }

    int taleBytesRemaining = isBase64Follows() ? (_algorithmDataLength - afterTaleOffset) % 3 : 0;

    if (_isAlgorithmDataCloned) {
        base64DecodeWithoutCloning(buffer, _algorithmData, _algorithmDataOffset + afterTaleOffset,
                _algorithmDataLength - afterTaleOffset - taleBytesRemaining);
    } else {
        base64DecodeWithCloning(buffer, _algorithmData, _algorithmDataOffset + afterTaleOffset,
                _algorithmDataLength - afterTaleOffset - taleBytesRemaining);
    }

    if (taleBytesRemaining > 0) {
        System.arraycopy(_algorithmData, _algorithmDataOffset + _algorithmDataLength - taleBytesRemaining,
                base64TaleBytes, 0, taleBytesRemaining);
        base64TaleLength = taleBytesRemaining;
    }
}
 
Example #20
Source File: FloatEncodingAlgorithm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % FLOAT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfFloat", new Object[]{Integer.valueOf(FLOAT_SIZE)}));
    }

    return octetLength / FLOAT_SIZE;
}
 
Example #21
Source File: LongEncodingAlgorithm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % LONG_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfLong", new Object[]{Integer.valueOf(LONG_SIZE)}));
    }

    return octetLength / LONG_SIZE;
}
 
Example #22
Source File: FloatEncodingAlgorithm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % FLOAT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfFloat", new Object[]{Integer.valueOf(FLOAT_SIZE)}));
    }

    return octetLength / FLOAT_SIZE;
}
 
Example #23
Source File: UUIDEncodingAlgorithm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % (LONG_SIZE * 2) != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfUUID",new Object[]{Integer.valueOf(LONG_SIZE * 2)}));
    }

    return octetLength / LONG_SIZE;
}
 
Example #24
Source File: LongEncodingAlgorithm.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % LONG_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfLong", new Object[]{Integer.valueOf(LONG_SIZE)}));
    }

    return octetLength / LONG_SIZE;
}
 
Example #25
Source File: IntEncodingAlgorithm.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % INT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfInt", new Object[]{Integer.valueOf(INT_SIZE)}));
    }

    return octetLength / INT_SIZE;
}
 
Example #26
Source File: BooleanEncodingAlgorithm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public final Object decodeFromBytes(byte[] b, int start, int length) throws EncodingAlgorithmException {
    final int blength = getPrimtiveLengthFromOctetLength(length, b[start]);
    boolean[] data = new boolean[blength];

    decodeFromBytesToBooleanArray(data, 0, blength, b, start, length);
    return data;
}
 
Example #27
Source File: BooleanEncodingAlgorithm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public int getPrimtiveLengthFromOctetLength(int octetLength, int firstOctet) throws EncodingAlgorithmException {
    final int unusedBits = (firstOctet >> 4) & 0xFF;
    if (octetLength == 1) {
       if (unusedBits > 3) {
           throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.unusedBits4"));
       }
       return 4 - unusedBits;
    } else {
       if (unusedBits > 7) {
           throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.unusedBits8"));
       }
       return octetLength * 8 - 4 - unusedBits;
    }
}
 
Example #28
Source File: ShortEncodingAlgorithm.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % SHORT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfShort", new Object[]{Integer.valueOf(SHORT_SIZE)}));
    }

    return octetLength / SHORT_SIZE;
}
 
Example #29
Source File: IntEncodingAlgorithm.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public final int getPrimtiveLengthFromOctetLength(int octetLength) throws EncodingAlgorithmException {
    if (octetLength % INT_SIZE != 0) {
        throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().
                getString("message.lengthNotMultipleOfInt", new Object[]{Integer.valueOf(INT_SIZE)}));
    }

    return octetLength / INT_SIZE;
}
 
Example #30
Source File: StAXDocumentParser.java    From openjdk-jdk8u-backup 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;
}