Class Base64EncodingStrategy

    • 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.
    • 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 the DEFAULT 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 the StaticUtils.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 the StaticUtils.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 the encodeDisplayableNonASCIICharacters and encodeNonDisplayableNonASCIICharacters 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, or false if not.
      • encodeDisplayableNonASCIICharacters

        public boolean encodeDisplayableNonASCIICharacters()
        Indicates whether the presence of one or more displayable non-ASCII characters (as determined by the StaticUtils.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 the encodeNonUTF8Data 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, or false if not.
      • encodeNonDisplayableNonASCIICharacters

        public boolean encodeNonDisplayableNonASCIICharacters()
        Indicates whether the presence of one or more non-displayable non-ASCII characters (as determined by the StaticUtils.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 the encodeNonUTF8Data 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, or false if not.
      • encodeNonUTF8Data

        public boolean encodeNonUTF8Data()
        Indicates whether values that do not represent valid UTF-8 strings (as determined by the StaticUtils.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, or false 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 be null.
        Returns:
        true if the provided value should be base64-encoded in accordance with this strategy, or false 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 be null.
        Returns:
        true if the provided value should be base64-encoded in accordance with this strategy, or false 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 be null.
        Returns:
        true if the provided value should be base64-encoded in accordance with this strategy, or false if not.
      • toString

        @NotNull
        public java.lang.String toString()
        Retrieves a string representation of this base64 encoding strategy.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this base64 encoding strategy.
      • toString

        public void toString​(@NotNull
                             java.lang.StringBuilder buffer)
        Appends a string representation of this base64 encoding strategy to the provided buffer.
        Parameters:
        buffer - The buffer to which the string representation should be appended.