2017-04-02 00:36:06 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace SharpCifs.Util.Sharpen
|
|
|
|
|
{
|
|
|
|
|
public class Properties
|
|
|
|
|
{
|
|
|
|
|
protected Hashtable _properties;
|
|
|
|
|
|
2017-06-21 06:46:57 +00:00
|
|
|
|
|
2017-04-02 00:36:06 +00:00
|
|
|
|
public Properties()
|
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
this._properties = new Hashtable();
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-21 06:46:57 +00:00
|
|
|
|
public Properties(Properties defaultProp) : this()
|
2017-04-02 00:36:06 +00:00
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
this.PutAll(defaultProp._properties);
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PutAll(Hashtable properties)
|
|
|
|
|
{
|
|
|
|
|
foreach (var key in properties.Keys)
|
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
this._properties.Put(key, properties[key]);
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetProperty(object key, object value)
|
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
this._properties.Put(key, value);
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object GetProperty(object key)
|
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
return this._properties.Keys.Contains(key)
|
|
|
|
|
? this._properties[key]
|
|
|
|
|
: null;
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object GetProperty(object key, object def)
|
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
return this._properties.Get(key) ?? def;
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Load(InputStream input)
|
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
using (var reader = new StreamReader(input))
|
2017-04-02 00:36:06 +00:00
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
while (!reader.EndOfStream)
|
2017-04-02 00:36:06 +00:00
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
var line = reader.ReadLine();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(line))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var tokens = line.Split('=');
|
|
|
|
|
|
|
|
|
|
if (tokens.Length < 2)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
this._properties.Put(tokens[0], tokens[1]);
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Store(OutputStream output)
|
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
using (var writer = new StreamWriter(output))
|
2017-04-02 00:36:06 +00:00
|
|
|
|
{
|
2017-06-21 06:46:57 +00:00
|
|
|
|
foreach (var pair in this._properties)
|
|
|
|
|
writer.WriteLine($"{pair.Key}={pair.Value}");
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Store(TextWriter output)
|
2017-06-21 06:46:57 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var pair in this._properties)
|
|
|
|
|
output.WriteLine($"{pair.Key}={pair.Value}");
|
2017-04-02 00:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|