public override void Parse(ExtendedBinaryReader br)
        {
            base.Parse(br);

            //Because the box size is not a reliable metric. So useful.
            Payload = br.ReadToEnd();
        }
 public static SegmentRunEntry Parse(ExtendedBinaryReader br)
 {
     return new SegmentRunEntry
     {
         FirstSegment = br.ReadUInt32(),
         FragmentsPerSegment = br.ReadUInt32()
     };
 }
Example #3
0
 public virtual void Parse(ExtendedBinaryReader br)
 {
     if (BoxHeader == null)
     {
         BoxHeader = new F4VBoxHeader();
         BoxHeader.Parse(br);
     }
 }
 public void Parse(ExtendedBinaryReader br)
 {
     TotalSize = br.ReadUInt32();
     BoxType = br.ReadUInt32();
     if (TotalSize == 1)
         ExtendedSize = br.ReadUInt64();
     else
         ExtendedSize = null;
 }
 public static FragmentRunEntry Parse(ExtendedBinaryReader br)
 {
     var entry = new FragmentRunEntry();
         entry.FirstFragment= br.ReadUInt32();
         entry.FirstFragmentTimestamp = br.ReadUInt64();
         entry.FragmentDuration = br.ReadUInt32();
     if(entry.FragmentDuration == 0)
         entry.DiscontinuityIndicator = br.ReadByte();
     else
         entry.DiscontinuityIndicator = null;
     return entry;
 }
        public override void Parse(ExtendedBinaryReader br)
        {
            base.Parse(br);

            if (BoxHeader.TotalSize == 0)
                br.ReadToEnd();
            else if (BoxHeader.TotalSize == 1)
            {
                br.ReadChunkedBytes(BoxHeader.ExtendedSize.Value - (ulong)BoxHeader.HeaderSize).Select(s => s);
            }
            else
            {
                foreach (var s in br.ReadChunkedBytes((ulong)BoxHeader.TotalSize - (ulong)BoxHeader.HeaderSize)) ;
            }
        }
Example #7
0
        protected virtual TF.Core.TranslationEntities.Subtitle ReadSubtitle(ExtendedBinaryReader input, long offset, bool returnToPos)
        {
            var pos = input.Position;

            input.Seek(offset, SeekOrigin.Begin);

            var text = input.ReadString();

            var subtitle = new TF.Core.TranslationEntities.Subtitle
            {
                Offset      = offset,
                Text        = text,
                Translation = text,
                Loaded      = text,
            };

            if (returnToPos)
            {
                input.Seek(pos, SeekOrigin.Begin);
            }

            return(subtitle);
        }
Example #8
0
        public void Serialization()
        {
            var expectedMetadata = new ReferenceMetadata("chr1", "1");
            ReferenceMetadata observedMetadata;

            using (var ms = new MemoryStream())
            {
                using (var writer = new ExtendedBinaryWriter(ms, Encoding.UTF8, true))
                {
                    expectedMetadata.Write(writer);
                }

                ms.Position = 0;

                using (var reader = new ExtendedBinaryReader(ms))
                {
                    observedMetadata = ReferenceMetadata.Read(reader);
                }
            }

            Assert.Equal(expectedMetadata.EnsemblName, observedMetadata.EnsemblName);
            Assert.Equal(expectedMetadata.UcscName, observedMetadata.UcscName);
        }
Example #9
0
        protected override IList <Subtitle> GetSubtitles()
        {
            var result = new List <Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding, Endianness.BigEndian))
                {
                    input.Skip(4);
                    var tableEnd = input.ReadInt32();
                    input.Skip(4);

                    while (input.Position < tableEnd)
                    {
                        var subtitle = ReadSubtitle(input);
                        subtitle.PropertyChanged += SubtitlePropertyChanged;
                        result.Add(subtitle);
                    }
                }

            LoadChanges(result);

            return(result);
        }
Example #10
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding))
                        {
                            var  tableEnd     = input.PeekUInt16();
                            long outputOffset = tableEnd;

                            while (input.Position < tableEnd)
                            {
                                var inputSubtitle = ReadSubtitle(input);
                                outputOffset = WriteSubtitle(output, subtitles, inputSubtitle.Offset, outputOffset);
                            }
                        }
        }
Example #11
0
        public NinjaNodeNameList ReadNinjaNodeNameList(ExtendedBinaryReader reader, long pos)
        {
            NinjaNodeNameList = new NinjaNodeNameList()
            {
                NodeName = new string(reader.ReadChars(4))
            };
            uint NodeLength = reader.ReadUInt32();

            pos = reader.BaseStream.Position; //Save Position
            uint NodeOffset = reader.ReadUInt32();

            reader.JumpTo(NodeOffset, false);

            uint Unknown1        = reader.ReadUInt32(); //Padding?
            uint NodeTableCount  = reader.ReadUInt32();
            uint NodeTableOffset = reader.ReadUInt32();

            reader.JumpTo(NodeTableOffset, false);

            for (int i = 0; i < NodeTableCount; i++)
            {
                NinjaNodeName NodeName = new NinjaNodeName()
                {
                    ID = reader.ReadUInt32()
                };
                uint NodeNameIndex = reader.ReadUInt32();
                long currentPos    = reader.BaseStream.Position; //Save Position
                reader.JumpTo(NodeNameIndex, false);
                NodeName.Name = reader.ReadNullTerminatedString();
                reader.JumpTo(currentPos, true);
                NinjaNodeNameList.NinjaNodeNames.Add(NodeName);
            }

            reader.JumpTo(pos, true);
            reader.JumpAhead(NodeLength);
            return(NinjaNodeNameList);
        }
Example #12
0
        public static NsiReader Read(Stream stream)
        {
            (IDataSourceVersion version, GenomeAssembly assembly, string jsonKey, ReportFor reportFor, int schemaVersion) = ReadHeader(stream);
            if (schemaVersion != SaCommon.SchemaVersion)
            {
                throw new UserErrorException($"Schema version mismatch!! Expected {SaCommon.SchemaVersion}, observed {schemaVersion} for {jsonKey}");
            }

            using (var blockStream = new BlockStream(new Zstandard(), stream, CompressionMode.Decompress))
                using (var reader = new ExtendedBinaryReader(blockStream))
                {
                    int count         = reader.ReadOptInt32();
                    var suppIntervals = new Dictionary <ushort, List <Interval <string> > >();
                    for (var i = 0; i < count; i++)
                    {
                        var saInterval = SuppInterval.Read(reader);
                        if (suppIntervals.TryGetValue(saInterval.Chromosome.Index, out var intervals))
                        {
                            intervals.Add(new Interval <string>(saInterval.Start, saInterval.End, saInterval.GetJsonString()));
                        }
                        else
                        {
                            suppIntervals[saInterval.Chromosome.Index] = new List <Interval <string> > {
                                new Interval <string>(saInterval.Start, saInterval.End, saInterval.GetJsonString())
                            }
                        };
                    }

                    var intervalArrays = new Dictionary <ushort, IntervalArray <string> >(suppIntervals.Count);
                    foreach ((ushort chromIndex, List <Interval <string> > intervals) in suppIntervals)
                    {
                        intervalArrays[chromIndex] = new IntervalArray <string>(intervals.ToArray());
                    }

                    return(new NsiReader(assembly, version, jsonKey, reportFor, intervalArrays));
                }
        }
Example #13
0
        public JasixIndex(Stream stream) : this()
        {
            _stream = stream;
            using (var reader = new ExtendedBinaryReader(stream))
            {
                int version = reader.ReadOptInt32();
                if (version != JasixCommons.Version)
                {
                    throw new InvalidDataException($"Invalid Jasix version: Observed {version}, expected{JasixCommons.Version}");
                }

                int count = reader.ReadOptInt32();

                for (var i = 0; i < count; i++)
                {
                    var chrIndex = new JasixChrIndex(reader);
                    _chrIndices[chrIndex.ReferenceSequence] = chrIndex;
                }

                int synonymCount = reader.ReadOptInt32();
                for (var i = 0; i < synonymCount; i++)
                {
                    string synonym   = reader.ReadAsciiString();
                    string indexName = reader.ReadAsciiString();
                    _synonymToChrName[synonym] = indexName;
                }

                int sectionCount = reader.ReadOptInt32();
                for (var i = 0; i < sectionCount; i++)
                {
                    string sectionName = reader.ReadAsciiString();
                    long   begin       = reader.ReadOptInt64();
                    long   end         = reader.ReadOptInt64();
                    _sectionRanges[sectionName] = new FileRange(begin, end);
                }
            }
        }
Example #14
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            var encryptedInputData = System.IO.File.ReadAllBytes(Path);
            var inputData          = EncryptionManager.DecryptData(encryptedInputData);

            byte[] outputData;

            using (var msInput = new MemoryStream(inputData))
                using (var input = new ExtendedBinaryReader(msInput, FileEncoding))
                    using (var msOutput = new MemoryStream())
                        using (var output = new ExtendedBinaryWriter(msOutput, FileEncoding))
                        {
                            while (input.Position + 2 <= input.Length)
                            {
                                var offset    = input.Position;
                                var id        = input.ReadUInt16();
                                var inputText = input.ReadString();

                                var subtitle   = subtitles.First(x => x.Offset == offset);
                                var outputText = subtitle.Translation.ToFullWidthChars();
                                output.Write(id);
                                output.WriteString(outputText);
                            }

                            outputData = msOutput.ToArray();
                        }

            var encryptedOutputData = EncryptionManager.EncryptData(outputData);

            System.IO.File.WriteAllBytes(outputPath, encryptedOutputData);
        }
Example #15
0
        public static void LoadLight(string filePath)
        {
            using (var fileStream = File.OpenRead(filePath))
            {
                var  reader              = new ExtendedBinaryReader(fileStream, true);
                uint fileSize            = reader.ReadUInt32();
                uint rootNodeType        = reader.ReadUInt32();
                uint finalTableOffset    = reader.ReadUInt32();
                uint rootNodeOffset      = reader.ReadUInt32();
                uint finalTableOffsetAbs = reader.ReadUInt32();
                uint padding             = reader.ReadUInt32();
                lightType = (LightType)reader.ReadUInt32();
                XPos      = reader.ReadSingle();
                YPos      = reader.ReadSingle();
                ZPos      = reader.ReadSingle();
                ColorR    = reader.ReadSingle();
                ColorG    = reader.ReadSingle();
                ColorB    = reader.ReadSingle();

                // Print out Light information
                Console.WriteLine($"Light type: {lightType}");
                Console.WriteLine("");
                Console.WriteLine($"ColorR is {ColorR}," + $" It should Be {ColorR/10000} after re-saving");
                Console.WriteLine($"ColorG is {ColorG}," + $" It should Be {ColorG/10000} after re-saving");
                Console.WriteLine($"ColorB is {ColorB}," + $" It should Be {ColorB/10000} after re-saving");
                Console.WriteLine("");
                // Read Omni-Specific Values if present.
                if (lightType == LightType.Omni)
                {
                    Unknown1       = reader.ReadUInt32();
                    Unknown2       = reader.ReadUInt32();
                    Unknown3       = reader.ReadUInt32();
                    OmniInnerRange = reader.ReadSingle();
                    OmniOuterRange = reader.ReadSingle();
                }
            }
        }
Example #16
0
        public override void Load(ExtendedBinaryReader reader, bool keepOpen = false)
        {
            // Height of the character in pixels
            CharacterHeight = reader.ReadInt32();
            // The amount of characters defined
            int characterCount = reader.ReadInt32();

            // Unknown
            WidthScale  = reader.ReadSingle();
            HeightScale = reader.ReadSingle();

            for (int i = 0; i < characterCount; ++i)
            {
                var fontEntry = new FontEntry
                {
                    Character = ReadReversedUTF8Char(reader),   // The read UTF8 character
                    XScale    = reader.ReadSingle(),            // X position on the texture (Multiply by the textures width to get pixels)
                    YScale    = reader.ReadSingle(),            // Y position on the texture (Multiply by the textures height to get pixels)
                    Kerning   = reader.ReadInt32(),             // -X offset for positioning when rendering
                    Width     = reader.ReadInt32()              // The width of the character in pixels
                };
                Characters.Add(fontEntry);
            }
        }
Example #17
0
    public WriteToSinkEvent ReadWriteToSinkEvent(ExtendedBinaryReader reader)
    {
        var evt = new WriteToSinkEvent
        {
            RowUid = reader.Read7BitEncodedInt(),
            ProcessInvocationUID = reader.Read7BitEncodedInt(),
            SinkUID = reader.Read7BitEncodedInt()
        };

        var columnCount = reader.Read7BitEncodedInt();

        if (columnCount > 0)
        {
            evt.Values = new KeyValuePair <string, object> [columnCount];
            for (var i = 0; i < columnCount; i++)
            {
                var column = GetTextById(reader.Read7BitEncodedInt());
                var value  = reader.ReadObject();
                evt.Values[i] = new KeyValuePair <string, object>(column, value);
            }
        }

        return(evt);
    }
        protected override IList <Subtitle> GetSubtitles()
        {
            var result = new List <Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding))
                {
                    var tableEnd = input.PeekUInt16();
                    while (input.Position < tableEnd)
                    {
                        var item = ReadItem(input);

                        item.Title.PropertyChanged       += SubtitlePropertyChanged;
                        item.Description.PropertyChanged += SubtitlePropertyChanged;

                        result.Add(item.Title);
                        result.Add(item.Description);
                    }
                }

            LoadChanges(result);

            return(result);
        }
Example #19
0
        public NgaReader(Stream stream)
        {
            _nsaStream = stream;
            // read the whole file. Currently they are well under 2MB
            var compressedBytes   = new byte[2 * 1024 * 1024];
            var decompressedBytes = new byte[20 * 1024 * 1024];
            var compressedSize    = _nsaStream.Read(compressedBytes, 0, compressedBytes.Length);

            var zstd             = new Zstandard();
            var decompressedSize = zstd.Decompress(compressedBytes, compressedSize, decompressedBytes, decompressedBytes.Length);

            _memStream = new MemoryStream(decompressedBytes, 0, decompressedSize);
            _reader    = new ExtendedBinaryReader(_memStream);

            Version  = DataSourceVersion.Read(_reader);
            JsonKey  = _reader.ReadAsciiString();
            _isArray = _reader.ReadBoolean();
            ushort schemaVersion = _reader.ReadOptUInt16();

            if (schemaVersion != SaCommon.SchemaVersion)
            {
                throw new UserErrorException($"Expected schema version: {SaCommon.SchemaVersion}, observed: {schemaVersion} for {JsonKey}");
            }
        }
        public void TranscriptRegion_EndToEnd()
        {
            var expectedResults = new ITranscriptRegion[]
            {
                new TranscriptRegion(TranscriptRegionType.Exon, 13, 100, 200, 300, 400),
                new TranscriptRegion(TranscriptRegionType.Gap, 0, 120, 230, 10, 20),
                new TranscriptRegion(TranscriptRegionType.Intron, 14, 130, 230, 330, 430)
            };

            var observedResults = new ITranscriptRegion[expectedResults.Length];

            using (var ms = new MemoryStream())
            {
                using (var writer = new ExtendedBinaryWriter(ms, Encoding.UTF8, true))
                {
                    foreach (var region in expectedResults)
                    {
                        region.Write(writer);
                    }
                }

                ms.Position = 0;

                using (var reader = new ExtendedBinaryReader(ms))
                {
                    for (int i = 0; i < expectedResults.Length; i++)
                    {
                        observedResults[i] = TranscriptRegion.Read(reader);
                    }
                }
            }

            var comparer = new TranscriptRegionComparer();

            Assert.Equal(expectedResults, observedResults, comparer);
        }
Example #21
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles  = GetSubtitles();
            var subs       = subtitles.Select(subtitle => subtitle as SubtitleWithId).ToList();
            var dictionary = new Dictionary <string, SubtitleWithId>(subs.Count);

            foreach (SubtitleWithId subtitle in subs)
            {
                dictionary.Add(subtitle.Id, subtitle);
            }

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding))
                        {
                            var count = input.ReadInt32();
                            output.Write(count);
                            for (int i = 0; i < count; i++)
                            {
                                // UILabel
                                output.Write(input.ReadBytes(0x04));
                                output.Write(input.ReadBytes(0x08));

                                var strJap = input.ReadStringSerialized(0x04);
                                var strEng = input.ReadStringSerialized(0x04);

                                output.WriteStringSerialized(strJap, 0x04);
                                output.WriteStringSerialized(dictionary.TryGetValue((i + 1).ToString(), out SubtitleWithId subtitle) ? subtitle.Translation : strEng, 0x04);
                            }
                        }
        }
        protected override IList <Subtitle> GetSubtitles()
        {
            var result = new List <Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding, Endianness.BigEndian))
                {
                    input.Seek(0x20, SeekOrigin.Begin);

                    var pointer = input.ReadInt32();
                    if (pointer > -1)
                    {
                        input.Seek(pointer, SeekOrigin.Begin);

                        var subtitle = ReadSubtitle(input);
                        subtitle.PropertyChanged += SubtitlePropertyChanged;
                        result.Add(subtitle);
                    }

                    input.Seek(0x24, SeekOrigin.Begin);

                    pointer = input.ReadInt32();
                    if (pointer > -1)
                    {
                        input.Seek(pointer, SeekOrigin.Begin);

                        var subtitle = ReadSubtitle(input);
                        subtitle.PropertyChanged += SubtitlePropertyChanged;
                        result.Add(subtitle);
                    }
                }

            LoadChanges(result);

            return(result);
        }
Example #23
0
        public void ReadWriteTests()
        {
            var randomPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            var regulatoryFeature1 = new RegulatoryElement(2, 100, 200, CompactId.Convert("1"), RegulatoryElementType.promoter);
            var regulatoryFeature2 = new RegulatoryElement(3, 100, 200, CompactId.Convert("2"), RegulatoryElementType.enhancer);
            var regulatoryFeature3 = new RegulatoryElement(4, 105, 201, CompactId.Convert("3"), RegulatoryElementType.CTCF_binding_site);

            using (var writer = new ExtendedBinaryWriter(FileUtilities.GetCreateStream(randomPath)))
            {
                regulatoryFeature1.Write(writer);
                regulatoryFeature2.Write(writer);
                regulatoryFeature3.Write(writer);
            }

            using (var reader = new ExtendedBinaryReader(FileUtilities.GetReadStream(randomPath)))
            {
                Assert.Equal(regulatoryFeature1, RegulatoryElement.Read(reader));
                Assert.Equal(regulatoryFeature2, RegulatoryElement.Read(reader));
                Assert.Equal(regulatoryFeature3, RegulatoryElement.Read(reader));
            }

            File.Delete(randomPath);
        }
Example #24
0
        protected virtual void LoadChanges(TableData data)
        {
            if (HasChanges)
            {
                using (var fs = new FileStream(ChangesFile, FileMode.Open))
                    using (var input = new ExtendedBinaryReader(fs, Encoding.Unicode))
                    {
                        var version = input.ReadInt32();

                        if (version != ChangesFileVersion)
                        {
                            //System.IO.File.Delete(ChangesFile);
                            return;
                        }

                        foreach (var column in data.Columns)
                        {
                            column.PropertyChanged -= SubtitlePropertyChanged;
                            column.LoadChanges(input);
                            column.PropertyChanged += SubtitlePropertyChanged;
                        }
                    }
            }
        }
Example #25
0
        public void LoadChromosome(string ucscReferenceName)
        {
            IsInitialized = false;
            if (_saDirectory == null || ucscReferenceName == _currentReferenceName)
            {
                return;
            }
            _currentReferenceName = ucscReferenceName;

            _currentIntervalIndex = -1;
            _phylopIntervals.Clear();

            // load the appropriate phyloP file
            var stream = PhylopCommon.GetStream(_saDirectory, ucscReferenceName);

            if (stream == null)
            {
                _reader = null;
                return;
            }

            _reader = new ExtendedBinaryReader(stream);
            LoadHeader();
        }
Example #26
0
        private static SetObjectTransform ReadTransform(
            ExtendedBinaryReader reader, bool readLocalSpace)
        {
            var transform = new SetObjectTransform();

            // World Space
            transform.Position = reader.ReadVector3();
            transform.Rotation = new Quaternion(reader.ReadVector3(), true);

            // Local Space
            if (readLocalSpace)
            {
                transform.Position += reader.ReadVector3();

                // TODO: Convert euler angles rotation to quaternion and multiply.
                var localRotation = reader.ReadVector3();
                if (localRotation.X != 0 || localRotation.Y != 0 || localRotation.Z != 0)
                {
                    Console.WriteLine("Local rotation {0} is not zero!", localRotation);
                }
            }

            return(transform);
        }
Example #27
0
        public static ISaDataSource Read(ExtendedBinaryReader reader)
        {
            var keyName       = reader.ReadString();
            var vcfkeyName    = reader.ReadString();
            var altAllele     = reader.ReadString();
            var flags         = reader.ReadByte();
            var matchByAllele = (flags & 1) != 0;
            var isArray       = (flags & 2) != 0;
            var vcfString     = reader.ReadString();

            var numJsonStrings = reader.ReadOptInt32();

            string[] jsonStrings = null;
            if (numJsonStrings > 0)
            {
                jsonStrings = new string[numJsonStrings];
                for (int i = 0; i < numJsonStrings; i++)
                {
                    jsonStrings[i] = reader.ReadString();
                }
            }

            return(new SaDataSource(keyName, vcfkeyName, altAllele, matchByAllele, isArray, vcfString, jsonStrings));
        }
Example #28
0
        // ReSharper disable once UnusedParameter.Local
        private static void ReadFromBlockStream(ICompressionAlgorithm compressionAlgorithm, Stream ms, string expectedRandomString)
        {
            // grab the header
            var header = DemoHeader.Read(ms);

            Assert.Equal(ExpectedAssembly, header.Assembly);

            using (var blockStream = new BlockStream(compressionAlgorithm, ms, CompressionMode.Decompress))
                using (var reader = new ExtendedBinaryReader(blockStream))
                {
                    CheckWriteException(blockStream);

                    // sequential string check
                    CheckString(reader, expectedRandomString);
                    CheckString(reader, SmallString);
                    CheckString(reader, FinalString);

                    // random access string check
                    blockStream.SetBlockPosition(header.Custom.FileOffset, header.Custom.InternalOffset);
                    //reader.Reset();

                    CheckString(reader, SmallString);
                }
        }
Example #29
0
        protected override void LoadChanges(IList <Subtitle> subtitles)
        {
            if (HasChanges)
            {
                using (var fs = new FileStream(ChangesFile, FileMode.Open))
                    using (var input = new ExtendedBinaryReader(fs, System.Text.Encoding.Unicode))
                    {
                        var version = input.ReadInt32();

                        if (version != ChangesFileVersion)
                        {
                            //System.IO.File.Delete(ChangesFile);
                            return;
                        }

                        input.Skip(128 * 4);

                        var subtitleCount = input.ReadInt32();

                        for (var i = 0; i < subtitleCount; i++)
                        {
                            var offset = input.ReadInt64();
                            var text   = input.ReadString();

                            var subtitle = subtitles.FirstOrDefault(x => x.Offset == offset);
                            if (subtitle != null)
                            {
                                subtitle.PropertyChanged -= SubtitlePropertyChanged;
                                subtitle.Translation      = text;
                                subtitle.Loaded           = subtitle.Translation;
                                subtitle.PropertyChanged += SubtitlePropertyChanged;
                            }
                        }
                    }
            }
        }
Example #30
0
        public void ExonReadWriteTests()
        {
            var randomPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            var exon1 = new CdnaCoordinateMap(100, 200, 10, 20);
            var exon2 = new CdnaCoordinateMap(100, 200, 11, 21);
            var exon3 = new CdnaCoordinateMap(105, 201, 12, 15);

            using (var writer = new ExtendedBinaryWriter(FileUtilities.GetCreateStream(randomPath)))
            {
                exon1.Write(writer);
                exon2.Write(writer);
                exon3.Write(writer);
            }

            using (var reader = new ExtendedBinaryReader(FileUtilities.GetReadStream(randomPath)))
            {
                Assert.Equal(exon1, CdnaCoordinateMap.Read(reader));
                Assert.Equal(exon2, CdnaCoordinateMap.Read(reader));
                Assert.Equal(exon3, CdnaCoordinateMap.Read(reader));
            }

            File.Delete(randomPath);
        }
Example #31
0
        public JasixChrIndex(ExtendedBinaryReader reader) : this("")
        {
            ReferenceSequence = reader.ReadAsciiString();
            int count = reader.ReadOptInt32();

            for (var i = 0; i < count; i++)
            {
                _nodes.Add(new JasixNode(reader));
            }

            int intervalCount = reader.ReadOptInt32();

            if (intervalCount == 0)
            {
                return;
            }

            for (var i = 0; i < intervalCount; i++)
            {
                _largeVariants.Add(ReadInterval(reader));
            }

            _intervalArray = new IntervalArray <long>(_largeVariants.ToArray());
        }
 public static BootstrapInfoBox FromBase64String(string s)
 {
     var stream = new MemoryStream(System.Convert.FromBase64String(s));
     using (var br = new ExtendedBinaryReader(stream))
     {
         BootstrapInfoBox bib = new BootstrapInfoBox();
         bib.Parse(br);
         return bib;
     }
 }
        public override void Parse(ExtendedBinaryReader br)
        {
            base.Parse(br);

            Version = br.ReadByte();
            Flags = br.ReadUInt24();
            BootstrapinfoVersion = br.ReadUInt32();
            var b = br.ReadByte();
            Profile = (new byte[] { 0x80, 0x40 }).Select(i => (i & b) != 0).ToArray();
            Live = (0x02 & b) != 0;
            Update = (0x01 & b) != 0;
            Reserved = (new byte[] { 0x08, 0x04, 0x02, 0x01 }).Select(i => (i & b) != 0).ToArray();
            TimeScale = br.ReadUInt32();
            CurrentMediaTime = br.ReadUInt64();
            SmpteTimeCodeOffset = br.ReadUInt64();
            MovieIdentifier = br.ReadNullTerminatedString();
            ServerEntryCount = br.ReadByte();
            ServerEntryTable = new ServerEntry[ServerEntryCount];
            for (int i = 0; i < ServerEntryCount; i++)
                ServerEntryTable[i] = ServerEntry.Parse(br);
            QualityEntryCount = br.ReadByte();
            QualityEntryTable = new QualityEntry[QualityEntryCount];
            for (int i = 0; i < QualityEntryCount; i++)
                QualityEntryTable[i] = QualityEntry.Parse(br);
            DrmData = br.ReadNullTerminatedString();
            MetaData = br.ReadNullTerminatedString();
            SegmentRunTableCount = br.ReadByte();
            SegmentRunTableEntries = new SegmentRunTableBox[SegmentRunTableCount];
            for (int i = 0; i < SegmentRunTableCount; i++)
            {
                SegmentRunTableEntries[i] = new SegmentRunTableBox();
                SegmentRunTableEntries[i].Parse(br);
            }
            FragmentRunTableCount = br.ReadByte();
            FragmentRunTableEntries = new FragmentRunTableBox[FragmentRunTableCount];
            for (int i = 0; i < FragmentRunTableCount; i++)
            {
                FragmentRunTableEntries[i] = new FragmentRunTableBox();
                FragmentRunTableEntries[i].Parse(br);
            }
        }
		/// <summary>
		/// returns a collection of bytes from a Url
		/// </summary>
		/// <param name="url">The URL to retrieve</param>
		public void GetUrlData(string url)
		{
			Uri uri = new Uri(url);
			if (!uri.IsFile)
				throw new UriFormatException("url is not a local file");

			FileWebRequest request = WebRequest.Create(url) as FileWebRequest;
			if (request == null)
			{
				this.Clear();
				return;
			}
			
			request.Method = "GET";
			
			// download the target URL
			FileWebResponse response = (FileWebResponse) request.GetResponse();

			// convert response stream to byte array
			using (Stream stream = response.GetResponseStream())
			{
				ExtendedBinaryReader extReader = new ExtendedBinaryReader(stream);
				_ResponseBytes = extReader.ReadToEnd();
			}
			
			// For local operations, we consider the data are never compressed. Else, the "Content-Encoding" field
			// in the headers would be "gzip" or "deflate". This could be handled quite easily with SharpZipLib for instance.

			// sometimes URL is indeterminate, eg, "http://website.com/myfolder"
			// in that case the folder and file resolution MUST be done on 
			// the server, and returned to the client as ContentLocation
			_ContentLocation = response.Headers["Content-Location"];
			if (_ContentLocation == null)
				_ContentLocation = "";
			
			// if we have string content, determine encoding type
			// (must cast to prevent null)
			// HACK We determine the content type based on the uri extension, 
			// as the header returned by the FileWebResponse is always "application/octet-stream" (hard coded in .NET!!)
			// text/html
			string ext = Path.GetExtension(uri.LocalPath).TrimStart(new char[]{'.'});
			switch (ext)
			{
					// What's important here is to identify TEXT mime types. Because, the default will resort to binary file.
				case "htm":		
				case "html":	_DetectedContentType = "text/html";			break;
				case "css":		_DetectedContentType = "text/css";			break;
				case "csv":		_DetectedContentType = "text/csv";			break;
				case "rtf":		_DetectedContentType = "text/rtf";			break;
				case "aspx":
				case "xsl":
				case "xml":		_DetectedContentType = "text/xml";			break;

				case "bmp":		_DetectedContentType = "image/bmp";			break;
				case "gif":		_DetectedContentType = "image/gif";			break;
				case "ico":		_DetectedContentType = "image/x-icon";		break;
				case "jpg":
				case "jpeg":	_DetectedContentType = "image/jpeg";		break;
				case "png":		_DetectedContentType = "image/png";			break;
				case "tif":
				case "tiff":	_DetectedContentType = "image/tiff";		break;

				case "js":		_DetectedContentType = "application/x-javascript";			break;
				default:		
					// Line commented: we don't change it
					_DetectedContentType = response.Headers["Content-Type"];	// Always "application/octet-stream" ...
					break;
			}
			if (_DetectedContentType == null)
				_DetectedContentType = "";
			if (ResponseIsBinary)
				_DetectedEncoding = null;
			else if (_ForcedEncoding == null)
				_DetectedEncoding = DetectEncoding(_DetectedContentType, _ResponseBytes);
		}
 public static ServerEntry Parse(ExtendedBinaryReader br)
 {
     return new ServerEntry
     {
         ServerBaseURL = br.ReadNullTerminatedString()
     };
 }
Example #36
0
 /// <param name="valueFixup">
 ///     Because reference types may not be read yet, the deserialization is fixed up when it becomes
 ///     available
 /// </param>
 public abstract void Deserialize(ExtendedBinaryReader reader, Action <T> valueFixup);
Example #37
0
        public object Deserialize(Type classType, ExtendedBinaryReader br, object obj = null)
        {
            if (!Attribute.IsDefined(classType, typeof(UnitySerializableAttribute)))
            {
                throw new UnitySerializationException("Not deserializable type : " + classType.FullName);
            }

            if (obj == null)
            {
                obj = Activator.CreateInstance(classType);
            }

            // Deserialize base type first because Type.GetFields() returns base fields last
            if (Attribute.IsDefined(classType.BaseType, typeof(UnitySerializableAttribute)))
            {
                Deserialize(classType.BaseType, br, obj);
            }

            var fieldArray = classType.GetFields();

            foreach (var field in fieldArray)
            {
                if (!field.DeclaringType.Equals(classType))
                {
                    continue;
                }

                if (field.IsLiteral || field.IsInitOnly)
                {
                    continue;
                }

                Type fieldType = field.FieldType;

                if (Attribute.IsDefined(field, typeof(UnityMinVersionAttribute)))
                {
                    var minAttrib = Attribute.GetCustomAttribute(field, typeof(UnityMinVersionAttribute)) as UnityMinVersionAttribute;
                    if (minAttrib.version > version)
                    {
                        field.SetValue(obj, GetDefault(fieldType));
                        continue;
                    }
                }

                if (Attribute.IsDefined(field, typeof(UnityMaxVersionAttribute)))
                {
                    var maxAttrib = Attribute.GetCustomAttribute(field, typeof(UnityMaxVersionAttribute)) as UnityMaxVersionAttribute;
                    if (maxAttrib.version < version)
                    {
                        field.SetValue(obj, GetDefault(fieldType));
                        continue;
                    }
                }

                object value      = null;
                bool   doNotAlign = Attribute.IsDefined(field, typeof(UnityDoNotAlignAttribute));
                if (!doNotAlign)
                {
                    br.AlignStream();
                }

                if (fieldType.IsEnum)
                {
                    var enumType = Enum.GetUnderlyingType(fieldType);
                    value = ReadValueType(enumType, br);
                }
                else if (fieldType.IsValueType)
                {
                    value = ReadValueType(fieldType, br);
                }
                else if (fieldType.IsArray && fieldType.GetElementType().IsValueType) // Value type array
                {
                    value = ReadValueArray(fieldType.GetElementType(), br);
                }
                else if (fieldType == typeof(string))
                {
                    value = br.ReadAlignedString();
                }
                else if (fieldType.IsClass || Attribute.IsDefined(fieldType, typeof(UnitySerializableAttribute)))
                {
                    if (fieldType.IsArray)
                    {
                        var elementType = fieldType.GetElementType();

                        value = ReadArray(elementType, br);
                    }
                    else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List <>))
                    {
                        var elementType = fieldType.GetGenericArguments()[0];

                        object array;
                        if (elementType.IsValueType)
                        {
                            array = ReadValueArray(elementType, br);
                        }
                        else
                        {
                            array = ReadArray(elementType, br);
                        }

                        value = Activator.CreateInstance(fieldType, (IEnumerable)array);
                    }
                    else
                    {
                        value = Deserialize(fieldType, br);
                    }
                }
                else
                {
                    throw new IOException("Failed to deserialize, unknown type : " + fieldType.ToString());
                }

                field.SetValue(obj, value);
            }

            return(obj);
        }
 public BoxParser(ExtendedBinaryReader br)
 {
     this.br = br;
     currentHeader = null;
 }
        private static byte[] GetTwoBitBuffer(ExtendedBinaryReader reader)
        {
            int numBytes = reader.ReadOptInt32();

            return(reader.ReadBytes(numBytes));
        }
        public override void Parse(ExtendedBinaryReader br)
        {
            base.Parse(br);

            Version = br.ReadByte();
            Flags = br.ReadUInt24();
            TimeScale = br.ReadUInt32();
            QualityEntryCount = br.ReadByte();
            QualitySegmentUrlModifiers = Enumerable.Range(0, QualityEntryCount).Select(i => br.ReadNullTerminatedString()).ToArray();
            FragmentRunEntryCount = br.ReadUInt32();
            FragmentRunEntryTable = new FragmentRunEntry[FragmentRunEntryCount];
            for (uint i = 0; i < FragmentRunEntryCount; i++)
                FragmentRunEntryTable[i] = FragmentRunEntry.Parse(br);
        }
Example #41
0
        /// <summary>
        /// returns a collection of bytes from a Url
        /// </summary>
        /// <param name="Url">URL to retrieve</param>
        public void GetUrlData(string Url, DateTime ifModifiedSince)
        {
            if (!string.IsNullOrEmpty(Url))
            {
                HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create(Url);

                //-- do we need to use a proxy to get to the web?
                if (!string.IsNullOrEmpty(_ProxyUrl))
                {
                    WebProxy wp = new WebProxy(_ProxyUrl);

                    if (_ProxyAuthenticationRequired)
                    {
                        if (!string.IsNullOrEmpty(_ProxyUser) & !string.IsNullOrEmpty(_ProxyPassword))
                        {
                            wp.Credentials = new NetworkCredential(_ProxyUser, _ProxyPassword);
                        }
                        else
                        {
                            wp.Credentials = CredentialCache.DefaultCredentials;
                        }
                        wreq.Proxy = wp;
                    }
                }

                //-- does the target website require credentials?
                if (_AuthenticationRequired)
                {
                    if (!string.IsNullOrEmpty(_AuthenticationUser) & !string.IsNullOrEmpty(_AuthenticationPassword))
                    {
                        wreq.Credentials = new NetworkCredential(_AuthenticationUser, _AuthenticationPassword);
                    }
                    else
                    {
                        wreq.Credentials = CredentialCache.DefaultCredentials;
                    }
                }

                wreq.Method = "GET";
                wreq.Timeout = _RequestTimeoutMilliseconds;
                wreq.UserAgent = _HttpUserAgent;
                wreq.Headers.Add("Accept-Encoding", _AcceptedEncodings);

                //-- note that, if present, this will trigger a 304 exception
                //-- if the URL being retrieved is not newer than the specified
                //-- date/time
                if (ifModifiedSince != DateTime.MinValue)
                {
                    wreq.IfModifiedSince = ifModifiedSince;
                }

                //-- sometimes we need to transfer cookies to another URL; 
                //-- this keeps them around in the object
                if (KeepCookies)
                {
                    if (_PersistedCookies == null)
                    {
                        _PersistedCookies = new CookieContainer();
                    }
                    wreq.CookieContainer = _PersistedCookies;
                }

                //-- download the target URL into a byte array
                HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();

                //-- convert response stream to byte array
                ExtendedBinaryReader ebr = new ExtendedBinaryReader(wresp.GetResponseStream());
                _ResponseBytes = ebr.ReadToEnd();

                //-- determine if body bytes are compressed, and if so, 
                //-- decompress the bytes
                HttpContentEncoding ContentEncoding = default(HttpContentEncoding);

                if (wresp.Headers["Content-Encoding"] == null)
                {
                    ContentEncoding = HttpContentEncoding.None;
                }
                else
                {
                    switch (wresp.Headers["Content-Encoding"].ToLower())
                    {
                        case "gzip":
                            ContentEncoding = HttpContentEncoding.Gzip;
                            break;
                        case "deflate":
                            ContentEncoding = HttpContentEncoding.Deflate;
                            break;
                        default:
                            ContentEncoding = HttpContentEncoding.Unknown;
                            break;
                    }
                    _ResponseBytes = Decompress(_ResponseBytes, ContentEncoding);
                }

                //-- sometimes URL is indeterminate, eg, "http://website.com/myfolder"
                //-- in that case the folder and file resolution MUST be done on 
                //-- the server, and returned to the client as ContentLocation
                _ContentLocation = wresp.Headers["Content-Location"];

                if (_ContentLocation == null)
                {
                    _ContentLocation = "";
                }

                //-- if we have string content, determine encoding type
                //-- (must cast to prevent Nothing)
                _DetectedContentType = wresp.Headers["Content-Type"];

                if (_DetectedContentType == null)
                {
                    _DetectedContentType = "";
                }

                if (ResponseIsBinary)
                {
                    _DetectedEncoding = null;
                }
                else
                {
                    if (_ForcedEncoding == null)
                    {
                        _DetectedEncoding = DetectEncoding(_DetectedContentType, _ResponseBytes);
                    }
                }
            }
        }
Example #42
0
 public virtual void Deserialize(ExtendedBinaryReader reader, Action <object> valueFixup)
 {
     Deserialize(reader, (Action <T>)(value => valueFixup(value)));
 }
 public static QualityEntry Parse(ExtendedBinaryReader br)
 {
     return new QualityEntry
     {
         QualitySegmentUrlModifier = br.ReadNullTerminatedString()
     };
 }
Example #44
0
 public override object Read(ExtendedBinaryReader reader) => Lookup(reader.ReadSByte());
Example #45
0
 public static FLVTag Parse(ExtendedBinaryReader br)
 {
     var b = br.ReadByte();
     var tag = new FLVTag
     {
         Reserved = (byte)(b & 0xc0),
         Filter = (b & 0x20) == 0,
         TagType = (TagType)(b & 0x1f),
         DataSize = br.ReadUInt24(),
         TimeStamp = br.ReadUInt24(),
         TimestampExtended = br.ReadByte(),
         StreamID = br.ReadUInt24()
     };
     tag.HeaderAndBody = br.ReadBytes((tag.TimestampExtended << 24) + (int)tag.TimeStamp);
     return tag;
 }