示例#1
0
 public static AbstractTag ReadFromGzippedFile(String filename)
 {
     using (FileStream input = File.OpenRead(filename))
     {
         using (GZipStream gzipStream = new GZipStream(input, CompressionMode.Decompress))
         {
             return(AbstractTag.Read(gzipStream));
         }
     }
 }
示例#2
0
        public static AbstractTag ReadFromFile(String filename)
        {
            AbstractTag tag = null;

            //Check if gzipped stream
            try
            {
                using (FileStream input = File.OpenRead(filename))
                {
                    using (GZipStream gzipStream = new GZipStream(input, CompressionMode.Decompress))
                    {
                        tag = AbstractTag.Read(gzipStream);
                    }
                }
            }
            catch (Exception)
            {
                tag = null;
            }

            if (tag != null)
            {
                return(tag);
            }

            //Try Deflate stream
            try
            {
                using (FileStream input = File.OpenRead(filename))
                {
                    using (DeflateStream deflateStream = new DeflateStream(input, CompressionMode.Decompress))
                    {
                        tag = AbstractTag.Read(deflateStream);
                    }
                }
            }
            catch (Exception)
            {
                tag = null;
            }

            if (tag != null)
            {
                return(tag);
            }

            //Assume uncompressed stream
            using (FileStream input = File.OpenRead(filename))
            {
                tag = AbstractTag.Read(input);
            }

            return(tag);
        }
示例#3
0
        internal static Dictionary <String, AbstractTag> ReadDictionary(Stream input)
        {
            Dictionary <String, AbstractTag> dict = new Dictionary <String, AbstractTag>();
            AbstractTag tag = AbstractTag.Read(input);

            while (tag.Type != TagType.End)
            {
                dict[tag.Name] = tag;
                tag            = AbstractTag.Read(input);
            }

            return(dict);
        }
示例#4
0
        internal static List <AbstractTag> ReadTagList(Stream input)
        {
            TagType tagType = (TagType)TagByte.ReadByte(input);
            int     length  = TagInt.ReadInt(input);

            List <AbstractTag> tags = new List <AbstractTag>();

            for (int i = 0; i < length; i++)
            {
                AbstractTag tag = null;

                switch (tagType)
                {
                case TagType.Byte:
                    tag = TagByte.ReadUnnamedTagByte(input);
                    break;

                case TagType.ByteArray:
                    tag = TagByteArray.ReadUnnamedTagByteArray(input);
                    break;

                case TagType.Compound:
                    tag = TagCompound.ReadUnnamedTagCompound(input);
                    break;

                case TagType.Double:
                    tag = TagDouble.ReadUnnamedTagDouble(input);
                    break;

                case TagType.End:
                    tag = new TagEnd();
                    break;

                case TagType.Float:
                    tag = TagFloat.ReadUnnamedTagFloat(input);
                    break;

                case TagType.Int:
                    tag = TagInt.ReadUnnamedTagInt(input);
                    break;

                case TagType.IntArray:
                    tag = TagIntArray.ReadUnnamedTagIntArray(input);
                    break;

                case TagType.List:
                    tag = TagList.ReadUnnamedTagList(input);
                    break;

                case TagType.Long:
                    tag = TagLong.ReadUnnamedTagLong(input);
                    break;

                case TagType.Short:
                    tag = TagShort.ReadUnnamedTagShort(input);
                    break;

                case TagType.String:
                    tag = TagString.ReadUnnamedTagString(input);
                    break;

                default:
                    tag = null;
                    break;
                }

                if (tag != null)
                {
                    tags.Add(tag);
                }
            }

            return(tags);
        }
示例#5
0
 public void SetTag(String name, AbstractTag tag)
 {
     tag.Name          = name;
     _dictionary[name] = tag;
 }