sun.text.normalizer.UCharacterIterator Java Examples

The following examples show how to use sun.text.normalizer.UCharacterIterator. 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: TestStringPrep.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #2
Source File: TestStringPrep.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #3
Source File: TestStringPrep.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #4
Source File: TestStringPrep.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #5
Source File: NFS4StringPrep.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #6
Source File: NFS4StringPrep.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #7
Source File: NFS4StringPrep.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #8
Source File: NFS4StringPrep.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #9
Source File: NFS4StringPrep.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #10
Source File: TestStringPrep.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #11
Source File: NFS4StringPrep.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #12
Source File: TestStringPrep.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #13
Source File: NFS4StringPrep.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #14
Source File: TestStringPrep.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #15
Source File: TestStringPrep.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getModule()
                                         .getResourceAsStream("sun/net/idn/uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #16
Source File: TestStringPrep.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #17
Source File: NFS4StringPrep.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #18
Source File: TestStringPrep.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #19
Source File: NFS4StringPrep.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #20
Source File: TestStringPrep.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #21
Source File: NFS4StringPrep.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #22
Source File: TestStringPrep.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #23
Source File: NFS4StringPrep.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #24
Source File: TestStringPrep.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void TestNamePrepConformance() throws Exception {
    InputStream stream = StringPrep.class.getResourceAsStream("uidna.spp");
    StringPrep namePrep = new StringPrep(stream);
    stream.close();
    int i;
    for(i=0; i<TestData.conformanceTestCases.length;i++){
        TestData.ConformanceTestCase testCase = TestData.conformanceTestCases[i];
        try{
            UCharacterIterator iter = UCharacterIterator.getInstance(testCase.input);
            StringBuffer output = namePrep.prepare(iter, testCase.flags);
            if(testCase.output !=null && output!=null && !testCase.output.equals(output.toString())){
                fail("Did not get the expected output. Expected: " + prettify(testCase.output)+
                        " Got: "+ prettify(output.toString()) );
            }
        } catch(ParseException ex) {
            if (testCase.expected == null) {
                fail("get the unexpected exception for source: " +testCase.input +" Got:  "+ ex.toString());
            }
        }
    }
    System.out.println("Nameprep test count: " + i);
}
 
Example #25
Source File: NFS4StringPrep.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #26
Source File: NFS4StringPrep.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static byte[] mixed_prepare(byte[] src)
                     throws IOException, ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    int index = s.indexOf(AT_SIGN);
    StringBuffer out = new StringBuffer();

    if(index > -1){
        /* special prefixes must not be followed by suffixes! */
        String prefixString = s.substring(0,index);
        int i= findStringIndex(special_prefixes, prefixString);
        String suffixString = s.substring(index+1, s.length());
        if(i>-1 && !suffixString.equals("")){
            throw new ParseException("Suffix following a special index", -1);
        }
        UCharacterIterator prefix = UCharacterIterator.getInstance(prefixString);
        UCharacterIterator suffix = UCharacterIterator.getInstance(suffixString);
        out.append(prep.nfsmxp.prepare(prefix,StringPrep.DEFAULT));
        out.append(AT_SIGN); // add the delimiter
        out.append(prep.nfsmxs.prepare(suffix, StringPrep.DEFAULT));
    }else{
        UCharacterIterator iter = UCharacterIterator.getInstance(s);
        out.append(prep.nfsmxp.prepare(iter,StringPrep.DEFAULT));

    }
   return out.toString().getBytes("UTF-8");
}
 
Example #27
Source File: NFS4StringPrep.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static byte[] prepare(byte[] src, StringPrep prep)
            throws ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    UCharacterIterator iter =  UCharacterIterator.getInstance(s);
    StringBuffer out = prep.prepare(iter,StringPrep.DEFAULT);
    return out.toString().getBytes("UTF-8");
}
 
Example #28
Source File: NFS4StringPrep.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static byte[] prepare(byte[] src, StringPrep prep)
            throws ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    UCharacterIterator iter =  UCharacterIterator.getInstance(s);
    StringBuffer out = prep.prepare(iter,StringPrep.DEFAULT);
    return out.toString().getBytes("UTF-8");
}
 
Example #29
Source File: NFS4StringPrep.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static byte[] prepare(byte[] src, StringPrep prep)
            throws ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    UCharacterIterator iter =  UCharacterIterator.getInstance(s);
    StringBuffer out = prep.prepare(iter,StringPrep.DEFAULT);
    return out.toString().getBytes("UTF-8");
}
 
Example #30
Source File: NFS4StringPrep.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static byte[] prepare(byte[] src, StringPrep prep)
            throws ParseException, UnsupportedEncodingException{
    String s = new String(src, "UTF-8");
    UCharacterIterator iter =  UCharacterIterator.getInstance(s);
    StringBuffer out = prep.prepare(iter,StringPrep.DEFAULT);
    return out.toString().getBytes("UTF-8");
}