Java Code Examples for sun.net.idn.Punycode#encode()

The following examples show how to use sun.net.idn.Punycode#encode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PunycodeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 2
Source File: PunycodeTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 3
Source File: PunycodeTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 4
Source File: PunycodeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 5
Source File: PunycodeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 6
Source File: PunycodeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 7
Source File: PunycodeTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 8
Source File: PunycodeTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 9
Source File: PunycodeTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 10
Source File: PunycodeTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 11
Source File: PunycodeTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 12
Source File: PunycodeTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}
 
Example 13
Source File: PunycodeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public String testEncoding(String inputS) {
    char input[] = new char[unicode_max_length];
    int codept = 0;
    char uplus[] = new char[2];
    StringBuffer output;
    int c;

    /* Read the input code points: */

    input_length = 0;

    Scanner sc = new Scanner(inputS);

    while (sc.hasNext()) {  // need to stop at end of line
        try {
            String next = sc.next();
            uplus[0] = next.charAt(0);
            uplus[1] = next.charAt(1);
            codept = Integer.parseInt(next.substring(2), 16);
        } catch (Exception ex) {
            fail(invalid_input, inputS);
        }

        if (uplus[1] != '+' || codept > Integer.MAX_VALUE) {
            fail(invalid_input, inputS);
        }

        if (input_length == unicode_max_length) fail(too_big, inputS);

        if (uplus[0] == 'u') case_flags[input_length] = false;
        else if (uplus[0] == 'U') case_flags[input_length] = true;
        else fail(invalid_input, inputS);

        input[input_length++] = (char)codept;
    }

    /* Encode: */

    output_length[0] = ace_max_length;
    try {
        output = Punycode.encode((new StringBuffer()).append(input, 0, input_length), case_flags);
    } catch (Exception e) {
        fail(invalid_input, inputS);
        // never reach here, just to make compiler happy
        return null;
    }

    testCount++;
    return output.toString();
}