Example #1
0
 public _frinfo2(_frinfo info)
 {
     _blockStart = info._blockStart;
     if (_blockStart == -1)
     {
         throw new InvalidOperationException(IOResources.ERR_FRecordStream_Empty);
     }
     _currPosition = info._currPosition;
     _blockLen     = info._blockLen;
 }
Example #2
0
 /// <summary>
 /// Loads necessary information before further operations.
 /// <para>!!! Note that <see cref="FRecordStream"/> remembers its previous position when the last time <c>UnloadInfo</c> is called.
 /// Always call <c>Reset</c> before reading from the beginning. </para>
 /// </summary>
 public void LoadInfo()
 {
     if (_info == null)
     {
         lock (_base)
         {
             _base.SeekTo(_startPosition);
             _info = new _frinfo(_base);
         }
     }
 }
Example #3
0
        /// <summary>
        /// Initializes a new instance of <see cref="FRecordStream"/> that represents either a new record (when <paramref name="startPosition"/> is assigned -1) or an existing record.
        /// <para>!!! If this instance represents an existing record (<paramref name="startPosition"/> not set -1), invoking <c>LoadInfo</c> method is necessary before many operations. </para>
        /// <para>!!! Also note its initial position is the previously saved position rather than 0, and call <c>Reset</c> method if reading from the beginning is intended.</para>
        /// </summary>
        /// <param name="baseStream">A <see cref="System.IO.Stream"/> where data are actually stored.</param>
        /// <param name="startPosition">Specifies a non-negative integer to indicate the location of an existing record in <paramref name="baseStream"/>, or -1 to create a new record.</param>
        /// <param name="minimumBlockSize">Specifies the minimum size in bytes of a data block.</param>
        /// <param name="bytesForLength">Specifies how many bytes are enough to describe the size of a data block. For example, if the maximum size of a data block is 64KB, then 2 bytes are sufficient.</param>
        /// <param name="bytesForPosition">Specifies how many bytes are enough to describe the total size of data. For example, if the maximum size of all data is 4GB, then 4 bytes are sufficient.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="baseStream"/> is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentException"><paramref name="baseStream"/> must be seekable, readable and writable.</exception>
        public FRecordStream(Stream baseStream, Int64 startPosition, ushort minimumBlockSize, byte bytesForLength, byte bytesForPosition)
        {
            if (baseStream == null)
            {
                throw new ArgumentNullException("baseStream");
            }
            if (!baseStream.CanSeek && !baseStream.CanRead && !baseStream.CanWrite)
            {
                throw new ArgumentException(IOResources.ERR_FRecordStream_InvalidBaseStream);
            }
            _base = baseStream;

            _startPosition = startPosition;
            if (_startPosition == -1)
            {
                _info = new _frinfo()
                {
                    _bytesFor   = (byte)((byte)bytesForLength | (byte)(bytesForPosition << 4)),
                    _blockStart = -1,
                    _autoalloc  = minimumBlockSize
                };
            }
        }
Example #4
0
 public _frinfo21(_frinfo info) : base(info)
 {
     _prevStatus = info._prevStatus;
 }
Example #5
0
 /// <summary>
 /// Clears all data stored in this <see cref="FRecordStream"/>.
 /// </summary>
 public void Clear()
 {
     _info          = null;
     _startPosition = -1;
 }
Example #6
0
 /// <summary>
 /// Permanently preserves the current status of this <see cref="FRecordStream"/> and unloads some information to save memory.
 /// This method put this <see cref="FRecordStream"/> into a status where most operations are invalid. You need to call <c>LoadInfo</c> again.
 /// <para>!!! All temporary status stored by <c>SaveStatus</c> method will be discarded.</para>
 /// </summary>
 public void UnloadInfo()
 {
     SaveInfo();
     _info = null;
 }