Пример #1
0
 /// <exception cref="System.IO.IOException"></exception>
 public override void Write(byte[] b, int off, int len)
 {
     if (overflow == null)
     {
         while (len > 0)
         {
             TemporaryBuffer.Block s = Last();
             if (s.IsFull())
             {
                 if (ReachedInCoreLimit())
                 {
                     break;
                 }
                 s = new TemporaryBuffer.Block();
                 blocks.AddItem(s);
             }
             int n = Math.Min(s.buffer.Length - s.count, len);
             System.Array.Copy(b, off, s.buffer, s.count, n);
             s.count += n;
             len     -= n;
             off     += n;
         }
     }
     if (len > 0)
     {
         overflow.Write(b, off, len);
     }
 }
Пример #2
0
        /// <summary>Copy all bytes remaining on the input stream into this buffer.</summary>
        /// <remarks>Copy all bytes remaining on the input stream into this buffer.</remarks>
        /// <param name="in">the stream to read from, until EOF is reached.</param>
        /// <exception cref="System.IO.IOException">
        /// an error occurred reading from the input stream, or while
        /// writing to a local temporary file.
        /// </exception>
        public virtual void Copy(InputStream @in)
        {
            if (blocks != null)
            {
                for (; ;)
                {
                    TemporaryBuffer.Block s = Last();
                    if (s.IsFull())
                    {
                        if (ReachedInCoreLimit())
                        {
                            break;
                        }
                        s = new TemporaryBuffer.Block();
                        blocks.AddItem(s);
                    }
                    int n = @in.Read(s.buffer, s.count, s.buffer.Length - s.count);
                    if (n < 1)
                    {
                        return;
                    }
                    s.count += n;
                }
            }
            byte[] tmp = new byte[TemporaryBuffer.Block.SZ];
            int    n_1;

            while ((n_1 = @in.Read(tmp)) > 0)
            {
                overflow.Write(tmp, 0, n_1);
            }
        }
Пример #3
0
 private bool NextBlock()
 {
     if (++this.blockIndex < this._enclosing.blocks.Count)
     {
         this.block    = this._enclosing.blocks[this.blockIndex];
         this.blockPos = 0;
         return(true);
     }
     return(false);
 }
Пример #4
0
 /// <exception cref="System.IO.IOException"></exception>
 private void SwitchToOverflow()
 {
     overflow = Overflow();
     TemporaryBuffer.Block last = blocks.Remove(blocks.Count - 1);
     foreach (TemporaryBuffer.Block b in blocks)
     {
         overflow.Write(b.buffer, 0, b.count);
     }
     blocks   = null;
     overflow = new SafeBufferedOutputStream(overflow, TemporaryBuffer.Block.SZ);
     overflow.Write(last.buffer, 0, last.count);
 }
Пример #5
0
 /// <exception cref="System.IO.IOException"></exception>
 public override void Write(int b)
 {
     if (overflow != null)
     {
         overflow.Write(b);
         return;
     }
     TemporaryBuffer.Block s = Last();
     if (s.IsFull())
     {
         if (ReachedInCoreLimit())
         {
             overflow.Write(b);
             return;
         }
         s = new TemporaryBuffer.Block();
         blocks.AddItem(s);
     }
     s.buffer[s.count++] = unchecked ((byte)b);
 }
Пример #6
0
 public BlockInputStream(TemporaryBuffer _enclosing)
 {
     this._enclosing = _enclosing;
     this.block      = this._enclosing.blocks[this.blockIndex];
 }
Пример #7
0
 private long InCoreLength()
 {
     TemporaryBuffer.Block last = Last();
     return(((long)blocks.Count - 1) * TemporaryBuffer.Block.SZ + last.count);
 }
Пример #8
0
		/// <exception cref="System.IO.IOException"></exception>
		public override void Write(int b)
		{
			if (overflow != null)
			{
				overflow.Write(b);
				return;
			}
			TemporaryBuffer.Block s = Last();
			if (s.IsFull())
			{
				if (ReachedInCoreLimit())
				{
					overflow.Write(b);
					return;
				}
				s = new TemporaryBuffer.Block();
				blocks.AddItem(s);
			}
			s.buffer[s.count++] = unchecked((byte)b);
		}
Пример #9
0
			private bool NextBlock()
			{
				if (++this.blockIndex < this._enclosing.blocks.Count)
				{
					this.block = this._enclosing.blocks[this.blockIndex];
					this.blockPos = 0;
					return true;
				}
				return false;
			}
Пример #10
0
			public BlockInputStream(TemporaryBuffer _enclosing)
			{
				this._enclosing = _enclosing;
				this.block = this._enclosing.blocks[this.blockIndex];
			}
Пример #11
0
		/// <summary>Copy all bytes remaining on the input stream into this buffer.</summary>
		/// <remarks>Copy all bytes remaining on the input stream into this buffer.</remarks>
		/// <param name="in">the stream to read from, until EOF is reached.</param>
		/// <exception cref="System.IO.IOException">
		/// an error occurred reading from the input stream, or while
		/// writing to a local temporary file.
		/// </exception>
		public virtual void Copy(InputStream @in)
		{
			if (blocks != null)
			{
				for (; ; )
				{
					TemporaryBuffer.Block s = Last();
					if (s.IsFull())
					{
						if (ReachedInCoreLimit())
						{
							break;
						}
						s = new TemporaryBuffer.Block();
						blocks.AddItem(s);
					}
					int n = @in.Read(s.buffer, s.count, s.buffer.Length - s.count);
					if (n < 1)
					{
						return;
					}
					s.count += n;
				}
			}
			byte[] tmp = new byte[TemporaryBuffer.Block.SZ];
			int n_1;
			while ((n_1 = @in.Read(tmp)) > 0)
			{
				overflow.Write(tmp, 0, n_1);
			}
		}
Пример #12
0
		/// <exception cref="System.IO.IOException"></exception>
		public override void Write(byte[] b, int off, int len)
		{
			if (overflow == null)
			{
				while (len > 0)
				{
					TemporaryBuffer.Block s = Last();
					if (s.IsFull())
					{
						if (ReachedInCoreLimit())
						{
							break;
						}
						s = new TemporaryBuffer.Block();
						blocks.AddItem(s);
					}
					int n = Math.Min(s.buffer.Length - s.count, len);
					System.Array.Copy(b, off, s.buffer, s.count, n);
					s.count += n;
					len -= n;
					off += n;
				}
			}
			if (len > 0)
			{
				overflow.Write(b, off, len);
			}
		}