Package com.ibm.icu.charset

Examples of com.ibm.icu.charset.CharsetICU


            (byte)0xea, 0x06,(byte) 0xd3,(byte) 0xe6, 0x0f,(byte) 0x8a, 0x00, 0x30, 0x44, 0x65,(byte) 0xb9, (byte)0xe4, (byte)0xfe,(byte) 0xe7,(byte) 0xc2, 0x06,
            (byte)0xcb, (byte)0x82
        };
       
        CharsetProviderICU cs = new CharsetProviderICU();
        CharsetICU charset = (CharsetICU)cs.charsetForName("scsu");
        CharsetDecoder decode = charset.newDecoder();
        CharsetEncoder encode = charset.newEncoder();
       
        //String[] codePoints = {"allFeatures", "german","russian","japanese"};
        byte[][] fromUnicode={allFeaturesSCSU,germanSCSU,russianSCSU,japaneseSCSU};
        char[][] toUnicode = {allFeaturesUTF16, germanUTF16,russianUTF16,japaneseUTF16};
       
        for(int i=0;i<4;i++){
            ByteBuffer decoderBuffer = ByteBuffer.wrap(fromUnicode[i]);
            CharBuffer encoderBuffer = CharBuffer.wrap(toUnicode[i]);
                          
            try{
                // Decoding
                CharBuffer decoderResult = decode.decode(decoderBuffer);
                encoderBuffer.position(0);
                if(!decoderResult.equals(encoderBuffer)){
                    errln("Error occured while decoding "+ charset.name());
                }
                // Encoding
                ByteBuffer encoderResult = encode.encode(encoderBuffer);
                // RoundTrip Test
                ByteBuffer roundTrip = encoderResult;
                CharBuffer roundTripResult = decode.decode(roundTrip);
                encoderBuffer.position(0);
                if(!roundTripResult.equals(encoderBuffer)){
                    errln("Error occured while encoding "+ charset.name());
                }
            }catch(Exception e){
                errln("Exception while converting SCSU thrown: " + e);
            }
        }
View Full Code Here


            0x01, /// from 41
            (byte) 0xDE, (byte) 0x83, 0x20, 0x09
        };
       
        CharsetProviderICU cs = new CharsetProviderICU();
        CharsetICU charset = (CharsetICU)cs.charsetForName("BOCU-1");
        CharsetDecoder decode = charset.newDecoder();
        CharsetEncoder encode = charset.newEncoder();
      
        ByteBuffer decoderBuffer = ByteBuffer.wrap(sampleText);
        CharBuffer encoderBuffer = CharBuffer.wrap(expected);
        try{
            // Decoding
            CharBuffer decoderResult = decode.decode(decoderBuffer);
           
            encoderBuffer.position(0);
            if(!decoderResult.equals(encoderBuffer)){
                errln("Error occured while decoding "+ charset.name());
            }
            // Encoding
            ByteBuffer encoderResult = encode.encode(encoderBuffer);
            // RoundTrip Test
            ByteBuffer roundTrip = encoderResult;
            CharBuffer roundTripResult = decode.decode(roundTrip);
           
            encoderBuffer.position(0);
            if(!roundTripResult.equals(encoderBuffer)){
                errln("Error occured while encoding "+ charset.name());
            }
        }catch(Exception e){
            errln("Exception while converting BOCU-1 thrown: " + e);
        }
    }
View Full Code Here

      
       
        // retrieve test case data
        ConversionCase cc = new ConversionCase();
        CharsetProviderICU provider = new CharsetProviderICU();
        CharsetICU charset  ;
      
            
        UnicodeSet mapset = new UnicodeSet();
        UnicodeSet mapnotset = new UnicodeSet();
        UnicodeSet unicodeset = new UnicodeSet();
        String ellipsis = "0x2e";
        cc.charset = ((ICUResourceBundle) testcase.getObject("charset"))
                .getString();
        cc.map = ((ICUResourceBundle) testcase.getObject("map")).getString();
        cc.mapnot = ((ICUResourceBundle) testcase.getObject("mapnot"))
                .getString();
       
    
        int which = ((ICUResourceBundle) testcase.getObject("which")).getInt(); // only checking for ROUNDTRIP_SET
       
        // ----for debugging only
        logln("");
        logln("TestGetUnicodeSet[" + cc.charset + "] ");
        logln("...............................................");
       
        try{
           // if cc.charset starts with '*', obtain it from com/ibm/icu/dev/data/testdata
           charset = (cc.charset != null && cc.charset.length() > 0 && cc.charset.charAt(0) == '*')
                    ? (CharsetICU) provider.charsetForName(cc.charset.substring(1),
                        "com/ibm/icu/dev/data/testdata", this.getClass().getClassLoader())
                    : (CharsetICU) provider.charsetForName(cc.charset);
          
           //checking for converter that are not supported at this point       
           try{
               if(charset.name()=="BOCU-1" ||charset.name()== "SCSU"|| charset.name()=="lmbcs1" || charset.name()== "lmbcs2" ||
                      charset.name()== "lmbcs3" || charset.name()== "lmbcs4" || charset.name()=="lmbcs5" || charset.name()=="lmbcs6" ||
                      charset.name()== "lmbcs8" || charset.name()=="lmbcs11" || charset.name()=="lmbcs16" || charset.name()=="lmbcs17" ||
                      charset.name()=="lmbcs18"|| charset.name()=="lmbcs19"){
                  
                   logln("Converter not supported at this point :" +charset.displayName());
                   return;
               }
                            
               if(which==1){
                   logln("Fallback set not supported at this point for converter : "+charset.displayName());
                  return;
               }
              
           }catch(Exception e){
               return;
           }
          
           mapset.clear();
           mapnotset.clear();
                  
           mapset.applyPattern(cc.map,false);
           mapnotset.applyPattern(cc.mapnot,false);
          
           charset.getUnicodeSet(unicodeset, which);
           UnicodeSet diffset = new UnicodeSet();
          
           //are there items that must be in unicodeset but are not?          
           (diffset = mapset).removeAll(unicodeset);
           if(!diffset.isEmpty()){
View Full Code Here

TOP

Related Classes of com.ibm.icu.charset.CharsetICU

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.