/// <summary> /// Appends all blocks from a block array to this array. /// </summary> /// <param name="blocks">The source array.</param> public void Append(BlockArray blocks) { for (int i = 0; i < blocks.Count; i++) { Append(blocks.GetBlock(i)); } }
/// <summary> /// Appends blocks from a block array to this array. /// </summary> /// <param name="blocks">The source array.</param> /// <param name="index">Index of the first block to append.</param> /// <param name="count">Number of blocks to append.</param> public void Append(BlockArray blocks, int index, int count) { for (int i = index; i < count + index; i++) { Append(blocks.GetBlock(i)); } }
/// <summary> /// Appends a block array to the end of the underlying BlockArray. /// </summary> /// <param name="blocks">The array to append.</param> /// <remarks> /// The underyling block array's SetExactSize() method will be /// called before appending the block. The stream position will /// be set to the end of the stream before the method returns. /// /// This method is a performance improvement over writing the /// a buffer to the stream via one of the write methods. /// </remarks> public void Append(BlockArray blocks) { this.blocks.SetExactSize(length); for (int i = 0; i < blocks.Count; i++) { this.blocks.Append(blocks.GetBlock(i)); } length += blocks.Size; pos = length; }
/// <summary> /// Constructs a stream from the blocks passed. /// </summary> /// <param name="blocks">The blocks.</param> /// <remarks> /// The stream size will be set to the size of the blocks. /// </remarks> public EnhancedBlockStream(BlockArray blocks) : base(new BlockStream(blocks)) { innerStream = (BlockStream)base.InnerStream; }
/// <summary> /// Appends a block array to the end of the underlying BlockArray. /// </summary> /// <param name="blocks">The array to append.</param> /// <remarks> /// <para> /// The underyling block array's S<see cref="BlockArray.SetExactSize" /> /// method will be called before appending the block. The stream /// position will be set to the end of the stream before the method /// returns. /// </para> /// <para> /// This method is a performance improvement over writing the /// a buffer to the stream via one of the write methods. /// </para> /// </remarks> public void Append(BlockArray blocks) { innerStream.Append(blocks); }
/// <summary> /// Extracts a range of bytes from the array into newly /// created block array. /// </summary> /// <param name="index">Logical index of the first byte.</param> /// <param name="length">Number of bytes to extract.</param> /// <returns>A new block array referencing the bytes.</returns> /// <remarks> /// <note> /// Although this method does create a new BlockArray /// and Block objects, it does not copy the underlying buffers. /// Instead, it adjusts the new Block objects to reference the /// requested portions of the original underlying buffers. /// </note> /// </remarks> public BlockArray Extract(int index, int length) { BlockArray extracted = new BlockArray(); int cbRemain; int blockIndex; int pos; int cb; Block srcBlock; Block dstBlock; if (length <= 0) { return(extracted); } if (index + length > size) { throw new IndexOutOfRangeException(); } if (index == 0 && length == size) { // Return a clone of this instance. for (int i = 0; i < list.Count; i++) { srcBlock = list[i]; extracted.Append(new Block(srcBlock.Buffer, srcBlock.Offset, srcBlock.Length)); } return(extracted); } CalcPos(index); cbRemain = length; blockIndex = lastBlockIndex; srcBlock = list[blockIndex]; pos = lastBlockPos + srcBlock.Offset; while (true) { cb = srcBlock.Length + srcBlock.Offset - pos; if (cb > cbRemain) { cb = cbRemain; } dstBlock = new Block(srcBlock.Buffer, pos, cb); extracted.Append(dstBlock); cbRemain -= cb; if (cbRemain <= 0) { break; } srcBlock = list[++blockIndex]; pos = srcBlock.Offset; } return(extracted); }
/// <summary> /// Constructs a stream from the blocks passed. /// </summary> /// <param name="blocks">The blocks.</param> /// <remarks> /// The stream size will be set to the size of the blocks. /// </remarks> public BlockStream(BlockArray blocks) { this.pos = 0; this.length = blocks.Size; this.blocks = blocks; }
/// <summary> /// Constructs a stream of the specified size using the /// specified block size and offset. /// </summary> /// <param name="size">The stream size in bytes.</param> /// <param name="blockSize">The block size in bytes.</param> /// <param name="blockOffset">Bytes to be reserved at the beginning of each new block.</param> /// <remarks> /// See <see cref="LillTek.Common.BlockArray"/> for more information on /// the value and use of the blockOffset prarmeter. /// </remarks> public BlockStream(int size, int blockSize, int blockOffset) { this.pos = 0; this.length = 0; this.blocks = new BlockArray(size, blockSize, blockOffset); }
/// <summary> /// Constructs a stream of the specified size using the default /// block size. /// </summary> /// <param name="size">The stream size in bytes.</param> public BlockStream(int size) { this.pos = 0; this.length = 0; this.blocks = new BlockArray(size); }
private int length; // Current logical string length /// <summary> /// Constructs a zero length stream with default block size. /// </summary> public BlockStream() { this.pos = 0; this.length = 0; this.blocks = new BlockArray(); }
/// <summary> /// Constructs a stream from a byte array. /// </summary> /// <param name="buffer">The byte array.</param> public BlockStream(byte[] buffer) { this.pos = 0; this.blocks = new BlockArray(buffer); this.length = this.blocks.Size; }
/// <summary> /// Constructs a stream from the blocks passed. /// </summary> /// <param name="blocks">The blocks.</param> /// <remarks> /// The stream size will be set to the size of the blocks. /// </remarks> public BlockStream(params Block[] blocks) { this.pos = 0; this.blocks = new BlockArray(blocks); this.length = this.blocks.Size; }