System.util.Properties.Load C# (CSharp) Method

Load() public method

public Load ( Stream inStream ) : void
inStream Stream
return void
        public void Load(Stream inStream)
        {
            StreamReader inp = new StreamReader(inStream, Encoding.GetEncoding(1252));
            while (true) {
                // Get next line
                String line = inp.ReadLine();
                if (line == null)
                    return;

                if (line.Length > 0) {

                    // Find start of key
                    int len = line.Length;
                    int keyStart;
                    for (keyStart=0; keyStart<len; keyStart++)
                        if (whiteSpaceChars.IndexOf(line[keyStart]) == -1)
                            break;

                    // Blank lines are ignored
                    if (keyStart == len)
                        continue;

                    // Continue lines that end in slashes if they are not comments
                    char firstChar = line[keyStart];
                    if ((firstChar != '#') && (firstChar != '!')) {
                        while (ContinueLine(line)) {
                            String nextLine = inp.ReadLine();
                            if (nextLine == null)
                                nextLine = "";
                            String loppedLine = line.Substring(0, len-1);
                            // Advance beyond whitespace on new line
                            int startIndex;
                            for (startIndex=0; startIndex<nextLine.Length; startIndex++)
                                if (whiteSpaceChars.IndexOf(nextLine[startIndex]) == -1)
                                    break;
                            nextLine = nextLine.Substring(startIndex,nextLine.Length - startIndex);
                            line = loppedLine+nextLine;
                            len = line.Length;
                        }

                        // Find separation between key and value
                        int separatorIndex;
                        for (separatorIndex=keyStart; separatorIndex<len; separatorIndex++) {
                            char currentChar = line[separatorIndex];
                            if (currentChar == '\\')
                                separatorIndex++;
                            else if (keyValueSeparators.IndexOf(currentChar) != -1)
                                break;
                        }

                        // Skip over whitespace after key if any
                        int valueIndex;
                        for (valueIndex=separatorIndex; valueIndex<len; valueIndex++)
                            if (whiteSpaceChars.IndexOf(line[valueIndex]) == -1)
                                break;

                        // Skip over one non whitespace key value separators if any
                        if (valueIndex < len)
                            if (strictKeyValueSeparators.IndexOf(line[valueIndex]) != -1)
                                valueIndex++;

                        // Skip over white space after other separators if any
                        while (valueIndex < len) {
                            if (whiteSpaceChars.IndexOf(line[valueIndex]) == -1)
                                break;
                            valueIndex++;
                        }
                        String key = line.Substring(keyStart, separatorIndex - keyStart);
                        String value = (separatorIndex < len) ? line.Substring(valueIndex, len - valueIndex) : "";

                        // Convert then store key and value
                        key = LoadConvert(key);
                        value = LoadConvert(value);
                        Add(key, value);
                    }
                }
            }
        }

Usage Example

Esempio n. 1
0
        public static void Main(String[] args) {
            Properties properties = new Properties();
            properties.Load(new FileStream("c:/home/blowagie/key.properties", FileMode.Open));
            String path = properties["PRIVATE"];
            char[] pass = properties["PASSWORD"].ToCharArray();

            Pkcs12Store ks = new Pkcs12Store();
            ks.Load(new FileStream(path, FileMode.Open), pass);
            String alias = "";
            foreach (string al in ks.Aliases) {
                if (ks.IsKeyEntry(al) && ks.GetKey(al).Key.IsPrivate) {
                    alias = al;
                    break;
                }
            }
            AsymmetricKeyParameter pk = ks.GetKey(alias).Key;
            ICollection<X509Certificate> chain = new List<X509Certificate>();
            foreach (X509CertificateEntry entry in ks.GetCertificateChain(alias)) {
                chain.Add(entry.Certificate);
            }
            IOcspClient ocspClient = new OcspClientBouncyCastle();
            C3_01_SignWithCAcert.Sign(DEST, chain, pk, DigestAlgorithms.SHA256, CryptoStandard.CMS, "Test", "Ghent",
                     null, ocspClient, null, 0);
        }
All Usage Examples Of System.util.Properties::Load