Example #1
0
        /// <summary>
        /// Reads one entry of the indexTable and return it's values in a SFOIndexTableEntry-object
        /// </summary>
        public static SFOIndexTableEntry ReadEntry(Stream fIn)
        {
            SFOIndexTableEntry sfoIndexTableEntry = new SFOIndexTableEntry();

            byte[] tempByteArray1 = new byte[1];
            byte[] tempByteArray2 = new byte[2];
            byte[] tempByteArray4 = new byte[4];

            // read offsetKeyNameInKeyTable
            fIn.Read(tempByteArray2, 0, 2);
            sfoIndexTableEntry.OffsetKeyNameInKeyTable = tempByteArray2;

            // read dataAlignmentRequirements
            fIn.Read(tempByteArray1, 0, 1);
            sfoIndexTableEntry.DataAlignmentRequirements = tempByteArray1[0];

            // read dataTypeValue
            fIn.Read(tempByteArray1, 0, 1);
            sfoIndexTableEntry.DataTypeValue = tempByteArray1[0];

            // read sizeValueData
            fIn.Read(tempByteArray4, 0, 4);
            sfoIndexTableEntry.SizeValueData = SFOReaderUtilities.ByteArrayReverseToInt(tempByteArray4);

            // read sizeValueDataAndPadding
            fIn.Read(tempByteArray4, 0, 4);
            sfoIndexTableEntry.SizeValueDataAndPadding = SFOReaderUtilities.ByteArrayReverseToInt(tempByteArray4);

            // read offsetDataValueInDataTable
            fIn.Read(tempByteArray4, 0, 4);
            sfoIndexTableEntry.OffsetDataValueInDataTable = SFOReaderUtilities.ByteArrayReverseToInt(tempByteArray4);

            return(sfoIndexTableEntry);
        }
Example #2
0
        /**
         * Reads an entry of the dataValueTable an return it as String
         *
         * @param fIn
         * @param sfoIndexTableEntry
         * @return String
         * @throws IOException
         */
        public string ReadEntry(Stream sfoFile, SFOIndexTableEntry sfoIndexTableEntry)
        {
            byte[] entryByteArray = new byte[sfoIndexTableEntry.SizeValueData];

            sfoFile.Read(entryByteArray, 0, sfoIndexTableEntry.SizeValueData);
            this.valueBytesReaded += sfoIndexTableEntry.SizeValueData;

            long offsetNextValue = sfoIndexTableEntry.OffsetDataValueInDataTable +
                                   sfoIndexTableEntry.SizeValueDataAndPadding; // korrekt!
            long skipBytes = offsetNextValue - this.valueBytesReaded;

            sfoFile.Seek(skipBytes, SeekOrigin.Current);
            this.valueBytesReaded += Convert.ToInt32(skipBytes);

            return(SFOReaderUtilities.ByteArrayToString(entryByteArray, true));
        }
Example #3
0
        private void Parse(Stream sfoFile)
        {
            // sfoHeader lesen
            this.sfoHeader = SFOHeader.Read(sfoFile);

            for (int i = 0; i < this.sfoHeader.NumberDataItems; i++)
            {
                this.IndexTableEntries.Add(SFOIndexTableEntry.ReadEntry(sfoFile));
            }

            // Zum KeyTable Anfang springen
            // (offset der KeyTabelle - Header-Lהnge - Anzahl * IndexEntry Lהnge = restl. zu ignorierende Bytes)
            int skipBytesToKeyTable = this.sfoHeader.OffsetKeyTable - SFOReader.headerSize -
                                      (this.sfoHeader.NumberDataItems * SFOIndexTableEntry.IndexTableEntryLength);

            sfoFile.Seek(skipBytesToKeyTable, SeekOrigin.Current);

            // read KeyTable
            var sfoKeyTableEntry = new SFOKeyTableEntry();
            var keyTableEntries  = new List <string>();

            for (int i = 0; i < this.sfoHeader.NumberDataItems; i++)
            {
                keyTableEntries.Add(sfoKeyTableEntry.ReadEntry(sfoFile));
            }

            long skipBytesToValueTable = this.sfoHeader.OffsetValueTable - this.sfoHeader.OffsetKeyTable -
                                         sfoKeyTableEntry.KeyTableLength;

            sfoFile.Seek(skipBytesToValueTable, SeekOrigin.Current);

            // read ValueTable
            SFOValueTableEntry sfoValueTableEntry = new SFOValueTableEntry();
            var valueTableEntries = new List <string>();

            for (int i = 0; i < this.sfoHeader.NumberDataItems; i++)
            {
                valueTableEntries.Add(sfoValueTableEntry.ReadEntry(sfoFile, this.IndexTableEntries[i])
                                      .Replace("\0", string.Empty));
            }

            for (int i = 0; i < keyTableEntries.Count; i++)
            {
                this.KeyValues.Add(keyTableEntries[i], valueTableEntries[i]);
            }
        }