Class StringPrep


  • public final class StringPrep
    extends java.lang.Object
    StringPrep API implements the StingPrep framework as described by RFC 3454. StringPrep prepares Unicode strings for use in network protocols. Profiles of StingPrep are set of rules and data according to which the Unicode Strings are prepared. Each profiles contains tables which describe how a code point should be treated. The tables are broadly classied into
    • Unassigned Table: Contains code points that are unassigned in the Unicode Version supported by StringPrep. Currently RFC 3454 supports Unicode 3.2.
    • Prohibited Table: Contains code points that are prohibited from the output of the StringPrep processing function.
    • Mapping Table: Contains code points that are deleted from the output or case mapped.
    The procedure for preparing Unicode strings:
    1. Map: For each character in the input, check if it has a mapping and, if so, replace it with its mapping.
    2. Normalize: Possibly normalize the result of step 1 using Unicode normalization.
    3. Prohibit: Check for any characters that are not allowed in the output. If any are found, return an error.
    4. Check bidi: Possibly check for right-to-left characters, and if any are found, make sure that the whole string satisfies the requirements for bidirectional strings. If the string does not satisfy the requirements for bidirectional strings, return an error.
    • Constructor Detail

      • StringPrep

        public StringPrep​(java.io.InputStream inputStream)
                   throws java.io.IOException
        Creates an StringPrep object after reading the input stream. The object does not hold a reference to the input steam, so the stream can be closed after the method returns.
        Parameters:
        inputStream - The stream for reading the StringPrep profile binarySun
        Throws:
        java.io.IOException - An exception occurs when I/O of the inputstream is invalid
      • StringPrep

        private StringPrep​(java.nio.ByteBuffer bytes)
                    throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getCodePointValue

        private char getCodePointValue​(int ch)
      • getVersionInfo

        private static VersionInfo getVersionInfo​(int comp)
      • getVersionInfo

        private static VersionInfo getVersionInfo​(byte[] version)
      • getInstance

        public static StringPrep getInstance​(int profile)
        Gets a StringPrep instance for the specified profile
        Parameters:
        profile - The profile passed to find the StringPrep instance.
      • getValues

        private static final void getValues​(char trieWord,
                                            StringPrep.Values values)
      • normalize

        private java.lang.StringBuffer normalize​(java.lang.StringBuffer src)
      • prepare

        public java.lang.StringBuffer prepare​(UCharacterIterator src,
                                              int options)
                                       throws StringPrepParseException
        Prepare the input buffer for use in applications with the given profile. This operation maps, normalizes(NFKC), checks for prohibited and BiDi characters in the order defined by RFC 3454 depending on the options specified in the profile.
        Parameters:
        src - A UCharacterIterator object containing the source string
        options - A bit set of options:
        • DEFAULT Prohibit processing of unassigned code points in the input
        • ALLOW_UNASSIGNED Treat the unassigned code points are in the input as normal Unicode code points.
        Returns:
        StringBuffer A StringBuffer containing the output
        Throws:
        StringPrepParseException - An exception occurs when parsing a string is invalid.
      • prepare

        public java.lang.String prepare​(java.lang.String src,
                                        int options)
                                 throws StringPrepParseException
        Prepare the input String for use in applications with the given profile. This operation maps, normalizes(NFKC), checks for prohibited and BiDi characters in the order defined by RFC 3454 depending on the options specified in the profile.
        Parameters:
        src - A string
        options - A bit set of options:
        • DEFAULT Prohibit processing of unassigned code points in the input
        • ALLOW_UNASSIGNED Treat the unassigned code points are in the input as normal Unicode code points.
        Returns:
        String A String containing the output
        Throws:
        StringPrepParseException - An exception when parsing or preparing a string is invalid.