public static void main(String[] pArgs) throws IOException {
        int iterations = 1000000;

        byte[] bytes = "������ klashf lkash ljah lhaaklhghdfgu ksd".getBytes("UTF-8");

        Decoder d;
        long start;
        long time;
        Writer sink = new PrintWriter(new NullOutputStream());
        StringWriter writer;
        String str;

        d = new StringDecoder("UTF-8");
        for (int i = 0; i < 10000; i++) {
            d.decodeTo(sink, bytes, 0, bytes.length);
        }
        start = System.currentTimeMillis();
        for (int i = 0; i < iterations; i++) {
            d.decodeTo(sink, bytes, 0, bytes.length);
        }
        time = DateUtil.delta(start);
        System.out.println("StringDecoder");
        System.out.println("time: " + time);

        writer = new StringWriter();
        d.decodeTo(writer, bytes, 0, bytes.length);
        str = writer.toString();
        System.out.println("str: \"" + str + "\"");
        System.out.println("chars.length: " + str.length());
        System.out.println();

        if (NIO_AVAILABLE) {
            d = new CharsetDecoder("UTF-8");
            for (int i = 0; i < 10000; i++) {
                d.decodeTo(sink, bytes, 0, bytes.length);
            }
            start = System.currentTimeMillis();
            for (int i = 0; i < iterations; i++) {
                d.decodeTo(sink, bytes, 0, bytes.length);
            }
            time = DateUtil.delta(start);
            System.out.println("CharsetDecoder");
            System.out.println("time: " + time);
            writer = new StringWriter();
            d.decodeTo(writer, bytes, 0, bytes.length);
            str = writer.toString();
            System.out.println("str: \"" + str + "\"");
            System.out.println("chars.length: " + str.length());
            System.out.println();
        }

        OutputStream os = new WriterOutputStream(new PrintWriter(System.out), "UTF-8");
        os.write(bytes);
        os.flush();
        System.out.println();

        for (byte b : bytes) {
            os.write(b & 0xff);
        }
        os.flush();
    }
public static void main ( String [ ] pArgs ) throws IOException { int iterations = 1000000 ; byte [ ] bytes = "������ klashf lkash ljah lhaaklhghdfgu ksd" . getBytes ( "UTF-8" ) ; Decoder d ; long start ; long time ; Writer sink = new PrintWriter ( new NullOutputStream ( ) ) ; StringWriter writer ; String str ; d = new StringDecoder ( "UTF-8" ) ; for ( int i = 0 ; i < 10000 ; i ++ ) { d . decodeTo ( sink , bytes , 0 , bytes . length ) ; } start = System . currentTimeMillis ( ) ; for ( int i = 0 ; i < iterations ; i ++ ) { d . decodeTo ( sink , bytes , 0 , bytes . length ) ; } time = DateUtil . delta ( start ) ; System . out . println ( "StringDecoder" ) ; System . out . println ( "time: " + time ) ; writer = new StringWriter ( ) ; d . decodeTo ( writer , bytes , 0 , bytes . length ) ; str = writer . toString ( ) ; System . out . println ( "str: \"" + str + "\"" ) ; System . out . println ( "chars.length: " + str . length ( ) ) ; System . out . println ( ) ; if ( NIO_AVAILABLE ) { d = new CharsetDecoder ( "UTF-8" ) ; for ( int i = 0 ; i < 10000 ; i ++ ) { d . decodeTo ( sink , bytes , 0 , bytes . length ) ; } start = System . currentTimeMillis ( ) ; for ( int i = 0 ; i < iterations ; i ++ ) { d . decodeTo ( sink , bytes , 0 , bytes . length ) ; } time = DateUtil . delta ( start ) ; System . out . println ( "CharsetDecoder" ) ; System . out . println ( "time: " + time ) ; writer = new StringWriter ( ) ; d . decodeTo ( writer , bytes , 0 , bytes . length ) ; str = writer . toString ( ) ; System . out . println ( "str: \"" + str + "\"" ) ; System . out . println ( "chars.length: " + str . length ( ) ) ; System . out . println ( ) ; } OutputStream os = new WriterOutputStream ( new PrintWriter ( System . out ) , "UTF-8" ) ; os . write ( bytes ) ; os . flush ( ) ; System . out . println ( ) ; for ( byte b : bytes ) { os . write ( b & 0xff ) ; } os . flush ( ) ; }
/////////////////////////////////////////////////////////////////////////