本文整理汇总了Java中sun.net.idn.StringPrep类的典型用法代码示例。如果您正苦于以下问题:Java StringPrep类的具体用法?Java StringPrep怎么用?Java StringPrep使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringPrep类属于sun.net.idn包,在下文中一共展示了StringPrep类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mixed_prepare
import sun.net.idn.StringPrep; //导入依赖的package包/类
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");
}
示例2: NFS4StringPrep
import sun.net.idn.StringPrep; //导入依赖的package包/类
private NFS4StringPrep (){
ClassLoader loader = NFS4StringPrep.class.getClassLoader();
try{
InputStream nfscsiFile = loader.getResourceAsStream("nfscsi.spp");
nfscsi = new StringPrep(nfscsiFile);
nfscsiFile.close();
InputStream nfscssFile = loader.getResourceAsStream("nfscss.spp");
nfscss = new StringPrep(nfscssFile);
nfscssFile.close();
InputStream nfscisFile = loader.getResourceAsStream("nfscis.spp");
nfscis = new StringPrep(nfscisFile);
nfscisFile.close();
InputStream nfsmxpFile = loader.getResourceAsStream("nfsmxp.spp");
nfsmxp = new StringPrep(nfsmxpFile);
nfsmxpFile.close();
InputStream nfsmxsFile = loader.getResourceAsStream("nfsmxs.spp");
nfsmxs = new StringPrep(nfsmxsFile);
nfsmxsFile.close();
}catch(IOException e){
throw new RuntimeException(e.toString());
}
}
示例3: TestNamePrepConformance
import sun.net.idn.StringPrep; //导入依赖的package包/类
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);
}
示例4: TestNamePrepConformance
import sun.net.idn.StringPrep; //导入依赖的package包/类
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);
}
示例5: prepare
import sun.net.idn.StringPrep; //导入依赖的package包/类
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");
}