/// <summary> /// Load the properties from the given input stream /// and using the specified encoding. /// </summary> /// <param name="input">An InputStream. /// </param> /// <param name="encoding">An encoding. /// </param> /// <exception cref="IOException" /> public void Load(Stream input, String encoding) { lock(this) { PropertiesReader reader = null; if (encoding != null) { try { reader = new PropertiesReader(new StreamReader(input, Encoding.GetEncoding(encoding))); } catch(IOException) { // Get one with the default encoding... } } if (reader == null) { reader = new PropertiesReader(new StreamReader(input)); } try { while(true) { String line = reader.ReadProperty(); if (line == null) { break; } int equalSignIndex = line.IndexOf('='); if (equalSignIndex > 0) { String key = line.Substring(0, (equalSignIndex) - (0)).Trim(); String value = line.Substring(equalSignIndex + 1).Trim(); /* * Configure produces lines like this ... just * ignore them. */ if (String.Empty.Equals(value)) { continue; } if (Include != null && key.ToUpper().Equals(Include.ToUpper())) { /* * Recursively load properties files. */ FileInfo file; if (value.StartsWith(fileSeparator)) { /* * We have an absolute path so we'll * use this. */ file = new FileInfo(value); } else { /* * We have a relative path, and we have * two possible forms here. If we have the * "./" form then just strip that off first * before continuing. */ if (value.StartsWith(string.Format(".{0}", fileSeparator))) { value = value.Substring(2); } file = new FileInfo(basePath + value); } bool tmpBool; if (File.Exists(file.FullName)) { tmpBool = true; } else { tmpBool = Directory.Exists(file.FullName); } // TODO: make sure file is readable or handle exception appropriately //if (file != null && tmpBool && file.canRead()) { if (tmpBool) { Load(new FileStream(file.FullName, FileMode.Open, FileAccess.Read)); } } else { AddProperty(key, value); } } } } catch(NullReferenceException) { /* * Should happen only when EOF is reached. */ return; } reader.Close(); } }
public void Load(Stream input, string enc) { lock (this) { PropertiesReader propertiesReader = null; if (enc != null) { try { propertiesReader = new PropertiesReader(new StreamReader(input, Encoding.GetEncoding(enc))); } catch { } } if (propertiesReader == null) { propertiesReader = new PropertiesReader(new StreamReader(input)); } try { while (true) { string text = propertiesReader.ReadProperty(); if (text == null) { break; } int num = text.IndexOf('='); if (num > 0) { string text2 = text.Substring(0, num).Trim(); string text3 = text.Substring(num + 1).Trim(); if (!string.Empty.Equals(text3)) { if (this.Include != null && text2.ToUpper().Equals(this.Include.ToUpper())) { FileInfo fileInfo; if (text3.StartsWith(this.fileSeparator)) { fileInfo = new FileInfo(text3); } else { if (text3.StartsWith("." + this.fileSeparator)) { text3 = text3.Substring(2); } fileInfo = new FileInfo(this.basePath + text3); } bool flag = File.Exists(fileInfo.FullName) || Directory.Exists(fileInfo.FullName); if (fileInfo != null && flag) { this.Load(new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read)); } } else { this.AddProperty(text2, text3); } } } } } #pragma warning disable CS0168 // 声明了变量,但从未使用过 catch (NullReferenceException var_8_1CD) #pragma warning restore CS0168 // 声明了变量,但从未使用过 { return; } propertiesReader.Close(); } }
public virtual void Load(Stream input, string enc) { lock (this) { PropertiesReader reader = null; if (enc != null) { try { reader = new PropertiesReader(new StreamReader(input, Encoding.GetEncoding(enc))); } catch (IOException) { } } if (reader == null) { reader = new PropertiesReader(new StreamReader(input)); } try { string str; Label_0039: str = reader.ReadProperty(); int index = str.IndexOf('='); if (index > 0) { string key = str.Substring(0, index).Trim(); string str3 = str.Substring(index + 1).Trim(); if (!string.Empty.Equals(str3)) { if ((this.Include != null) && key.ToUpper().Equals(this.Include.ToUpper())) { bool flag; FileInfo info = null; if (str3.StartsWith(this.fileSeparator)) { info = new FileInfo(str3); } else { if (str3.StartsWith("." + this.fileSeparator)) { str3 = str3.Substring(2); } info = new FileInfo(this.basePath + str3); } if (File.Exists(info.FullName)) { flag = true; } else { flag = Directory.Exists(info.FullName); } if ((info != null) && flag) { this.Load(new FileStream(info.FullName, FileMode.Open, FileAccess.Read)); } } else { this.AddProperty(key, str3); } } } goto Label_0039; } catch (NullReferenceException) { } } }