예제 #1
0
        public JarIndividualEntry(string entryText)
        {
            Attributes = JarAttributes.From(entryText);

            // Set up some properties to simplify tasks
            string name = null;

            if (Attributes.TryGetValue("Name", out name))
            {
                Name = name;
            }

            RawText = entryText;

            // Only look for xxx-DIGEST for now.
            // There are also xxx-DIGEST-yyy attributes for language specific files we need to deal with later
            string digestAttributeKey = Attributes.Keys.FirstOrDefault(key => key.EndsWith("-Digest", StringComparison.OrdinalIgnoreCase));

            if (!String.IsNullOrEmpty(digestAttributeKey))
            {
                string manifestDigest = Attributes[digestAttributeKey];
                HashAlgorithmName = JarUtils.GetHashAlgorithmFromDigest(digestAttributeKey, "-Digest");
                DigestValue       = Attributes[digestAttributeKey];
            }
        }
예제 #2
0
        /// <summary>
        /// Creates an instance of JarAttributes using the raw section from a manifest file.
        /// </summary>
        /// <param name="rawText">A string containing the raw section (main, individual) text.</param>
        /// <returns></returns>
        public static JarAttributes From(string rawText)
        {
            var jarAttributes = new JarAttributes(rawText);

            if (String.IsNullOrEmpty(rawText))
            {
                return(jarAttributes);
            }

            // We need to deal with continuations (multi-line attributes), so convert the raw text to a stream
            // and then parse it.
            using (Stream s = JarUtils.ToStream(rawText))
                using (StreamReader reader = new StreamReader(s))
                {
                    string line = reader.ReadLine();

                    while (!reader.EndOfStream)
                    {
                        if (line.Contains(':'))
                        {
                            string[] attributeParts = line.Split(':');

                            string attributeName  = attributeParts[0];
                            string attributeValue = attributeParts[1].TrimStart(' ');

                            line = reader.ReadLine();

                            // Continuation values start with SPACE
                            while (line.StartsWith(" "))
                            {
                                line            = line.TrimStart(' ').TrimEnd(JarUtils.NewLine);
                                attributeValue += line;
                            }

                            jarAttributes[attributeName] = attributeValue;
                        }
                        else
                        {
                            line = reader.ReadLine();
                        }
                    }
                }

            return(jarAttributes);
        }