aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/IO/SharpCifs/Util/Sharpen/Properties.cs
blob: 3d886ea87a4959968fb3761a78ffb35bc042c961 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.IO;

namespace SharpCifs.Util.Sharpen
{
    public class Properties
    {
        protected Hashtable _properties;

        public Properties()
        {
            _properties = new Hashtable();
        }

        public Properties(Properties defaultProp): this()
        {
            PutAll(defaultProp._properties);
        }

        public void PutAll(Hashtable properties)
        {
            foreach (var key in properties.Keys)
            {
                //_properties.Add(key, properties[key]);
                _properties.Put(key, properties[key]);
            }
        }

        public void SetProperty(object key, object value)
        {
            //_properties.Add(key, value);
            _properties.Put(key, value);
        }

        public object GetProperty(object key)
        {
            return _properties.Keys.Contains(key) ? _properties[key] : null;
        }

        public object GetProperty(object key, object def)
        {
            /*if (_properties.ContainsKey(key))
            {
                return _properties[key];
            }
            return def;*/
            object value = _properties.Get(key);

            return value ?? def;            
        }

        public void Load(InputStream input)
        {
            StreamReader sr = new StreamReader(input);
            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();

                if (!string.IsNullOrEmpty(line))
                {
                    string[] tokens = line.Split('=');
                    //_properties.Add(tokens[0], tokens[1]);
                    _properties.Put(tokens[0], tokens[1]);
                }
            }
        }

        public void Store(OutputStream output)
        {
            StreamWriter sw = new StreamWriter(output);
            foreach (var key in _properties.Keys)
            {
                string line = string.Format("{0}={1}", key, _properties[key]);
                sw.WriteLine(line);
            }
        }

        public void Store(TextWriter output)
        {            
            foreach (var key in _properties.Keys)
            {
                string line = string.Format("{0}={1}", key, _properties[key]);
                output.WriteLine(line);
            }
        }
    }
}