Search in sources :

Example 1 with Encoding

use of ezvcard.parameter.Encoding in project ez-vcard by mangstadt.

the class BinaryPropertyScribe method parse.

private T parse(String value, VCardDataType dataType, VCardParameters parameters, VCardVersion version) {
    U contentType = parseContentType(value, parameters, version);
    switch(version) {
        case V2_1:
        case V3_0:
            // parse as URL
            if (dataType == VCardDataType.URL || dataType == VCardDataType.URI) {
                return _newInstance(value, contentType);
            }
            // parse as binary
            Encoding encodingSubType = parameters.getEncoding();
            if (encodingSubType == Encoding.BASE64 || encodingSubType == Encoding.B) {
                return _newInstance(Base64.decodeBase64(value), contentType);
            }
            break;
        case V4_0:
            try {
                // parse as data URI
                DataUri uri = DataUri.parse(value);
                contentType = _mediaTypeFromMediaTypeParameter(uri.getContentType());
                return _newInstance(uri.getData(), contentType);
            } catch (IllegalArgumentException e) {
            // not a data URI
            }
            break;
    }
    return cannotUnmarshalValue(value, version, contentType);
}
Also used : Encoding(ezvcard.parameter.Encoding) DataUri(ezvcard.util.DataUri)

Aggregations

Encoding (ezvcard.parameter.Encoding)1 DataUri (ezvcard.util.DataUri)1