コード例 #1
0
        internal void WriteShortStreamData(int startSID, byte[] data)
        {
            int prev_sid = SID.EOC;
            int sid      = startSID;
            int index    = 0;

            while (index < data.Length)
            {
                if (sid == SID.EOC)
                {
                    if (prev_sid == SID.EOC)
                    {
                        sid = this.ShortSectorAllocation.AllocateSector();
                    }
                    else
                    {
                        sid = this.ShortSectorAllocation.AllocateSectorAfter(prev_sid);
                    }
                }
                int offset = GetShortSectorOffset(sid);
                ShortStreamContainer.Position = offset;
                if (index + ShortSectorSize < data.Length)
                {
                    ShortStreamContainer.Write(data, index, ShortSectorSize);
                }
                else
                {
                    ShortStreamContainer.Write(data, index, data.Length - index);
                }
                index   += ShortSectorSize;
                prev_sid = sid;
                sid      = this.ShortSectorAllocation.GetNextSectorID(prev_sid);
            }
            if (sid != SID.EOC && prev_sid != SID.EOC)
            {
                ShortSectorAllocation.LinkSectorID(prev_sid, SID.EOC);
                while (sid != SID.EOC)
                {
                    int next_sid = ShortSectorAllocation.GetNextSectorID(sid);
                    ShortSectorAllocation.LinkSectorID(sid, SID.Free);
                    sid = next_sid;
                }
            }
        }
コード例 #2
0
        internal CompoundDocument(Stream stream, FileHeader header)
        {
            this.FileStorage = stream;
            this.Reader      = new BinaryReader(this.FileStorage);
            if (stream.CanWrite)
            {
                this.Writer = new BinaryWriter(this.FileStorage, Encoding.Unicode);
            }

            this.Header          = header;
            this.SectorSize      = (int)Math.Pow(2, Header.SectorSizeInPot);
            this.ShortSectorSize = (int)Math.Pow(2, Header.ShortSectorSizeInPot);
            this.TotalSectors    = stream.Length == 0 ? 0
                : (int)(stream.Length - 512) / this.SectorSize;

            this.MasterSectorAllocation = new MasterSectorAllocation(this);
            this.SectorAllocation       = new SectorAllocation(this);
            this.ShortSectorAllocation  = new ShortSectorAllocation(this);
        }