private static string GetFileText(ICharsetDetector cdet, byte[] buffer, string fullFileName) { try { var fi = new FileInfo(fullFileName); if (fi.Length < Config.Inst.MAX_FILE_SIZE_IN_BYTES) { using (var fs = File.OpenRead(fullFileName)) { var length = fs.Read(buffer, 0, Math.Min(buffer.Length, (int)fs.Length)); cdet.Reset(); cdet.Feed(buffer, 0, length); cdet.DataEnd(); fs.Position = 0; return(new StreamReader(fs, GetEncodingByCharsetName(cdet.Charset)).ReadToEnd()); } } } catch (Exception ex) { Debug.WriteLine(ex.GetType().Name + ": '" + ex.Message + '\''); } return(null); }
public void TestBomUTF16_BE() { byte[] buf = { 0xFE, 0xFF, 0x00, 0x68, 0x00, 0x65 }; detector = new CharsetDetector(); detector.Feed(buf, 0, buf.Length); detector.DataEnd(); Assert.AreEqual(Charsets.UTF16_BE, detector.Charset); Assert.AreEqual(1.0f, detector.Confidence); }
public void TearDown() { detector = null; }
public void SetUp() { detector = new CharsetDetector(); }
public CharsetDetectorTestBatch() { detector = new CharsetDetector(); }