Class Base64Variants
- java.lang.Object
-
- com.fasterxml.jackson.core.Base64Variants
-
public final class Base64Variants extends java.lang.Object
Container for commonly used Base64 variants: See entries for full description of differences.Note that for default
Base64Variant
instances listed above, configuration is such that if padding is written on output, it will also be required on reading. This behavior may be changed by using methods:
-
-
Field Summary
Fields Modifier and Type Field Description static Base64Variant
MIME
This variant is what most people would think of "the standard" Base64 encoding.static Base64Variant
MIME_NO_LINEFEEDS
Slightly non-standard modification ofMIME
which does not use linefeeds (max line length set to infinite).static Base64Variant
MODIFIED_FOR_URL
This non-standard variant is usually used when encoded data needs to be passed via URLs (such as part of GET request).static Base64Variant
PEM
This variant is the one that predatesMIME
: it is otherwise identical, except that it mandates shorter line length.
-
Constructor Summary
Constructors Constructor Description Base64Variants()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Base64Variant
getDefaultVariant()
Method used to get the default variant --MIME_NO_LINEFEEDS
-- for cases where caller does not explicitly specify the variant.static Base64Variant
valueOf(java.lang.String name)
Lookup method for finding one of standard variants by name.
-
-
-
Field Detail
-
MIME
public static final Base64Variant MIME
This variant is what most people would think of "the standard" Base64 encoding.See wikipedia Base64 entry for details.
Note that although this can be thought of as the standard variant, it is not the default for Jackson: no-linefeeds alternative is instead used because of JSON requirement of escaping all linefeeds.
Writes padding on output; requires padding when reading (may change later with a call to
Base64Variant.withWritePadding(boolean)
)
-
MIME_NO_LINEFEEDS
public static final Base64Variant MIME_NO_LINEFEEDS
Slightly non-standard modification ofMIME
which does not use linefeeds (max line length set to infinite). Useful when linefeeds wouldn't work well (possibly in attributes), or for minor space savings (save 1 linefeed per 76 data chars, ie. ~1.4% savings).Writes padding on output; requires padding when reading (may change later with a call to
Base64Variant.withWritePadding(boolean)
)
-
PEM
public static final Base64Variant PEM
This variant is the one that predatesMIME
: it is otherwise identical, except that it mandates shorter line length.Writes padding on output; requires padding when reading (may change later with a call to
Base64Variant.withWritePadding(boolean)
)
-
MODIFIED_FOR_URL
public static final Base64Variant MODIFIED_FOR_URL
This non-standard variant is usually used when encoded data needs to be passed via URLs (such as part of GET request). It differs from the baseMIME
variant in multiple ways. First, no padding is used: this also means that it generally can not be written in multiple separate but adjacent chunks (which would not be the usual use case in any case). Also, no linefeeds are used (max line length set to infinite). And finally, two characters (plus and slash) that would need quoting in URLs are replaced with more optimal alternatives (hyphen and underscore, respectively).Does not write padding on output; does not accept padding when reading (may change later with a call to
Base64Variant.withWritePadding(boolean)
)
-
-
Method Detail
-
getDefaultVariant
public static Base64Variant getDefaultVariant()
Method used to get the default variant --MIME_NO_LINEFEEDS
-- for cases where caller does not explicitly specify the variant. We will prefer no-linefeed version because linefeeds in JSON values must be escaped, making linefeed-containing variants sub-optimal.- Returns:
- Default variant (
MIME_NO_LINEFEEDS
)
-
valueOf
public static Base64Variant valueOf(java.lang.String name) throws java.lang.IllegalArgumentException
Lookup method for finding one of standard variants by name. If name does not match any of standard variant names, aIllegalArgumentException
is thrown.- Parameters:
name
- Name of base64 variant to return- Returns:
- Standard base64 variant that matches given
name
- Throws:
java.lang.IllegalArgumentException
- if no standard variant with given name exists
-
-