GitSharp.Core.Util.TemporaryBuffer.copy C# (CSharp) Метод

copy() публичный Метод

public copy ( Stream @in ) : void
@in Stream
Результат void
        public void copy(Stream @in)
        {
            if (_blocks != null)
            {
                for (; ; )
                {
                    Block s = last();
                    if (s.isFull())
                    {
                        if (reachedInCoreLimit())
                            break;
                        s = new Block();
                        _blocks.Add(s);
                    }

                    int n = @in.Read(s.buffer, s.count, Block.SZ - s.count);
                    if (n < 1)
                        return;
                    s.count += n;
                }
            }

            byte[] tmp = new byte[Block.SZ];
            int nn;
            while ((nn = @in.Read(tmp, 0, tmp.Length)) > 0)
                diskOut.Write(tmp, 0, nn);
        }

Usage Example

Пример #1
0
 public void testOneBlockAndHalf_Copy()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     byte[] test = new TestRng(getName())
            .nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
     try
     {
         var @in = new MemoryStream(test);
         // [caytchen] StreamReader buffers data After the very first Read, thus advancing the Position in the underlying stream - causing this test to fail
         //var inReader = new StreamReader(@in);
         b.write(@in.ReadByte());
         b.copy(@in);
         b.close();
         Assert.AreEqual(test.Length, b.Length);
         {
             byte[] r = b.ToArray();
             Assert.IsNotNull(r);
             Assert.AreEqual(test.Length, r.Length);
             Assert.IsTrue(test.SequenceEqual(r));
         }
         {
             byte[] r;
             using (MemoryStream o = new MemoryStream())
             {
                 b.writeTo(o, null);
                 r = o.ToArray();
             }
             Assert.AreEqual(test.Length, r.Length);
             Assert.IsTrue(test.SequenceEqual(r));
         }
     }
     finally
     {
         b.destroy();
     }
 }
All Usage Examples Of GitSharp.Core.Util.TemporaryBuffer::copy