コード例 #1
0
        public void TestUTF8()
        {
            String s = "This is a string with some non-ascii characters that will "
                       + "be converted to UTF-8, then shoved through the detection process.  "
                       + "\u0391\u0392\u0393\u0394\u0395"
                       + "Sure would be nice if our source could contain Unicode directly!";

            byte[]          bytes = ILOG.J2CsMapping.Util.StringUtil.GetBytes(s, "UTF-8");
            CharsetDetector det   = new CharsetDetector();
            String          retrievedS;
            TextReader      reader;

            retrievedS = det.GetString(bytes, "UTF-8");
            CheckAssert(s.Equals(retrievedS));

            reader = det.GetReader(new MemoryStream(bytes), "UTF-8");
            CheckAssert(s.Equals(StringFromReader(reader)));
            det.SetDeclaredEncoding("UTF-8");     // Jitterbug 4451, for coverage
        }