Package com.unboundid.ldif
Class Base64EncodingStrategy
- java.lang.Object
-
- com.unboundid.ldif.Base64EncodingStrategy
-
- All Implemented Interfaces:
java.io.Serializable
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class Base64EncodingStrategy extends java.lang.Object implements java.io.Serializable
This class defines a set of properties that can be used to indicate which types of optional base64-encoding should be performed by the LDAP SDK.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Base64EncodingStrategy
DEFAULT
A base64-encoding strategy that represents a safe default configuration.static Base64EncodingStrategy
MAXIMAL
A base64-encoding strategy that indicates that the LDAP SDK should perform the maximum amount of base64 encoding that it considers necessary.static Base64EncodingStrategy
MINIMAL_COMPLIANT
A base64-encoding strategy that indicates that the LDAP SDK should perform the minimum amount of encoding required by the specification.static Base64EncodingStrategy
USER_FRIENDLY_NON_COMPLIANT
A base64-encoding strategy that indicates that the presence of non-ASCII characters that the LDAP SDK considers displayable should not cause a value to be encoded.
-
Constructor Summary
Constructors Constructor Description Base64EncodingStrategy(boolean encodeASCIIControlCharacters, boolean encodeDisplayableNonASCIICharacters, boolean encodeNonDisplayableNonASCIICharacters, boolean encodeNonUTF8Data)
Creates a new base64 encoding strategy with the specified settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
encodeASCIIControlCharacters()
Indicates whether the presence of one or more ASCII control characters should cause a value to be base64-encoded.boolean
encodeDisplayableNonASCIICharacters()
Indicates whether the presence of one or more displayable non-ASCII characters (as determined by theStaticUtils.isLikelyDisplayableCharacter(int)
method) should cause a value to be base64-encoded.boolean
encodeNonDisplayableNonASCIICharacters()
Indicates whether the presence of one or more non-displayable non-ASCII characters (as determined by theStaticUtils.isLikelyDisplayableCharacter(int)
method) should cause a value to be base64-encoded.boolean
encodeNonUTF8Data()
Indicates whether values that do not represent valid UTF-8 strings (as determined by theStaticUtils.isValidUTF8(byte[])
method) should be base64-encoded.boolean
shouldBase64Encode(byte[] value)
Indicates whether the provided value should be base64-encoded in accordance with this strategy.boolean
shouldBase64Encode(ByteString value)
Indicates whether the provided value should be base64-encoded in accordance with this strategy.boolean
shouldBase64Encode(java.lang.String value)
Indicates whether the provided value should be base64-encoded in accordance with this strategy.java.lang.String
toString()
Retrieves a string representation of this base64 encoding strategy.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this base64 encoding strategy to the provided buffer.
-
-
-
Field Detail
-
DEFAULT
@NotNull public static final Base64EncodingStrategy DEFAULT
A base64-encoding strategy that represents a safe default configuration. This includes:- The presence of ASCII control characters will cause a value to be base64-encoded. This is not required by the LDIF specification, but is recommended.
- The presence of any non-ASCII characters (whether they may be displayable or not) will cause a value to be base64-encoded as required by the LDIF specification.
- The presence of non-UTF-8 data will cause a value to be base64-encoded as required by the LDIF specification.
-
MINIMAL_COMPLIANT
@NotNull public static final Base64EncodingStrategy MINIMAL_COMPLIANT
A base64-encoding strategy that indicates that the LDAP SDK should perform the minimum amount of encoding required by the specification. The presence of ASCII control characters (other than NUL, LF, and CR, which must always be base64-encoded) will not cause values to be encoded. However, the presence of any non-ASCII characters or non-UTF-8 data will cause a value to be base64-=encoded as required by the LDIF specification.
-
USER_FRIENDLY_NON_COMPLIANT
@NotNull public static final Base64EncodingStrategy USER_FRIENDLY_NON_COMPLIANT
A base64-encoding strategy that indicates that the presence of non-ASCII characters that the LDAP SDK considers displayable should not cause a value to be encoded. ASCII control characters, non-displayable non-ASCII characters, and non-UTF-8 data will cause a value to be base64-encoded. Note that this NOT compliant with the LDIF specification (which technically requires base64 encoding for all non-ASCII data), but it may be user friendly in some cases.
-
MAXIMAL
@NotNull public static final Base64EncodingStrategy MAXIMAL
A base64-encoding strategy that indicates that the LDAP SDK should perform the maximum amount of base64 encoding that it considers necessary. Any ASCII control characters, any non-ASCII data, and any non-UTF-8 data will cause a value to be base64 encoded. This is equivalent to theDEFAULT
strategy.
-
-
Constructor Detail
-
Base64EncodingStrategy
public Base64EncodingStrategy(boolean encodeASCIIControlCharacters, boolean encodeDisplayableNonASCIICharacters, boolean encodeNonDisplayableNonASCIICharacters, boolean encodeNonUTF8Data)
Creates a new base64 encoding strategy with the specified settings.- Parameters:
encodeASCIIControlCharacters
- Indicates whether the presence of one or more ASCII control characters (characters whose Unicode code point is less than or equal to 0x01F, or is equal to 0x7F) should cause a value to be base64-encoded. Note that as per RFC 2849, the presence of the null (0x00), line feed (0x0A), and carriage return (0x0D) ASCII control characters will always cause a value to be base64-encoded.encodeDisplayableNonASCIICharacters
- Indicates whether the presence of one or more non-ASCII characters (characters whose Unicode code point is greater than 0x7F) that are believed to be displayable (as determined by theStaticUtils.isLikelyDisplayableCharacter(int)
method) should cause a value to be base64-encoded.encodeNonDisplayableNonASCIICharacters
- Indicates whether the presence of one or more non-ASCII characters (characters whose Unicode code point is greater than 0x7F) that are not believed to be displayable (as determined by theStaticUtils.isLikelyDisplayableCharacter(int)
method) should cause a value to be base64-encoded.encodeNonUTF8Data
- Indicates whether non-UTF-8-encoded data should be base64-encoded. Note that if a value does not represent a valid UTF-8 string, then theencodeDisplayableNonASCIICharacters
andencodeNonDisplayableNonASCIICharacters
arguments will not be used.
-
-
Method Detail
-
encodeASCIIControlCharacters
public boolean encodeASCIIControlCharacters()
Indicates whether the presence of one or more ASCII control characters should cause a value to be base64-encoded. ASCII control characters other than NUL, LF, and CR are not required to be base64-encoded by the LDIF specification, but it is generally recommended that they be encoded.- Returns:
true
if the presence of one or more ASCII control characters should cause a value to be base64-encoded, orfalse
if not.
-
encodeDisplayableNonASCIICharacters
public boolean encodeDisplayableNonASCIICharacters()
Indicates whether the presence of one or more displayable non-ASCII characters (as determined by theStaticUtils.isLikelyDisplayableCharacter(int)
method) should cause a value to be base64-encoded. Note that this only applies to values that represent valid UTF-8 strings. Values that are not valid UTF-8 strings will use the setting represented by theencodeNonUTF8Data
method. Also note that all non-ASCII characters are required to be base64 encoded by the LDIF specification, but there may be cases in which it may be desirable to relax this behavior when displaying to an end user.- Returns:
true
if the presence of one or more displayable non-ASCII characters should cause a value to be base64-encoded, orfalse
if not.
-
encodeNonDisplayableNonASCIICharacters
public boolean encodeNonDisplayableNonASCIICharacters()
Indicates whether the presence of one or more non-displayable non-ASCII characters (as determined by theStaticUtils.isLikelyDisplayableCharacter(int)
method) should cause a value to be base64-encoded. Note that this only applies to values that represent valid UTF-8 strings. Values that are not valid UTF-8 strings will use the setting represented by theencodeNonUTF8Data
method. Also note that all non-ASCII characters are required to be base64 encoded by the LDIF specification, but there may be cases in which it may be desirable to relax this behavior when displaying to an end user.- Returns:
true
if the presence of one or more non-displayable non-ASCII characters should cause a value to be base64-encoded, orfalse
if not.
-
encodeNonUTF8Data
public boolean encodeNonUTF8Data()
Indicates whether values that do not represent valid UTF-8 strings (as determined by theStaticUtils.isValidUTF8(byte[])
method) should be base64-encoded. Note that all non-ASCII data (which includes all non-UTF-8 data) is required to be base64 encoded, but there may be cases in which it may be desirable to relax this behavior when displaying to an end user, especially when using non-UTF-8 character sets.- Returns:
true
if values that do not represent valid UTF-8 strings should be base64-encoded, orfalse
if not.
-
shouldBase64Encode
public boolean shouldBase64Encode(@NotNull byte[] value)
Indicates whether the provided value should be base64-encoded in accordance with this strategy.- Parameters:
value
- The value for which to make the determination. It must not benull
.- Returns:
true
if the provided value should be base64-encoded in accordance with this strategy, orfalse
if not.
-
shouldBase64Encode
public boolean shouldBase64Encode(@NotNull java.lang.String value)
Indicates whether the provided value should be base64-encoded in accordance with this strategy.- Parameters:
value
- The value for which to make the determination. It must not benull
.- Returns:
true
if the provided value should be base64-encoded in accordance with this strategy, orfalse
if not.
-
shouldBase64Encode
public boolean shouldBase64Encode(@NotNull ByteString value)
Indicates whether the provided value should be base64-encoded in accordance with this strategy.- Parameters:
value
- The value for which to make the determination. It must not benull
.- Returns:
true
if the provided value should be base64-encoded in accordance with this strategy, orfalse
if not.
-
toString
@NotNull public java.lang.String toString()
Retrieves a string representation of this base64 encoding strategy.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of this base64 encoding strategy.
-
-