public void TestIsBinaryUtfInput() { var src = "Hello\u00A9 World\u2122"; byte[] input = Encoding.Unicode.GetBytes(src); Assert.IsFalse(TextFileUtility.IsBinary(input)); }
public string ReadString(bool readBinaryFiles) { string result = cachedText != null ? cachedText.Target as string : null; if (result != null) { return(result); } if (buffer != null) { result = buffer.ToString(); } else { Document doc = null; var task = SearchDocument(); if (task.Wait(1000)) { doc = task.Result; } if (doc != null && doc.Editor != null) { result = doc.Editor.Text; encoding = doc.Editor.Encoding; hadBom = doc.Editor.UseBOM; } else { try { if (!File.Exists(FileName)) { return(null); } var content = File.ReadAllBytes(FileName); if (!readBinaryFiles && TextFileUtility.IsBinary(content)) { return(null); } result = TextFileUtility.GetText(content, out encoding, out hadBom); } catch (Exception e) { LoggingService.LogError("Error while opening " + FileName, e); return(null); } } } cachedText = new WeakReference(result); return(result); }
internal TextReader GetReaderForFileName(bool readBinaryFiles = false) { try { if (!File.Exists(FileName)) { return(null); } if (!readBinaryFiles && TextFileUtility.IsBinary(FileName)) { return(null); } return(TextFileUtility.OpenStream(FileName)); } catch (Exception e) { LoggingService.LogError("Error while opening " + FileName, e); return(null); } }
public TextReader ReadString(bool readBinaryFiles) { if (buffer != null) { return(new StringReader(buffer.ToString())); } else { Document doc = null; var task = SearchDocument(); if (task.Wait(1000)) { doc = task.Result; } if (doc != null && doc.Editor != null) { return(doc.Editor.CreateReader()); } else { try { if (!File.Exists(FileName)) { return(null); } if (!readBinaryFiles && TextFileUtility.IsBinary(FileName)) { return(null); } return(TextFileUtility.OpenStream(FileName)); } catch (Exception e) { LoggingService.LogError("Error while opening " + FileName, e); return(null); } } } }
public void TestIsBinaryBinaryInput() { Assert.IsTrue(TextFileUtility.IsBinary(typeof(TextFileReaderTests).Assembly.Location)); }