GitSharp.Core.Util.TemporaryBuffer.ToArray C# (CSharp) Method

ToArray() public method

public ToArray ( ) : byte[]
return byte[]
        public byte[] ToArray()
        {
            long len = this.Length;
            if (int.MaxValue < len)
                throw new OutOfMemoryException("Length exceeds maximum array size");

            byte[] @out = new byte[(int)len];
            if (_blocks != null)
            {
                int outPtr = 0;
                foreach (Block b in _blocks)
                {
                    Array.Copy(b.buffer, 0, @out, outPtr, b.count);
                    outPtr += b.count;
                }
            }
            else
            {
                using (var @in = new FileStream(_onDiskFile.FullName, System.IO.FileMode.Open, FileAccess.Read))
                {
                    IO.ReadFully(@in, @out, 0, (int)len);
                }
            }
            return @out;
        }

Usage Example

Exemplo n.º 1
0
 public void testEmpty()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     try
     {
         b.close();
         Assert.AreEqual(0, b.Length);
         byte[] r = b.ToArray();
         Assert.IsNotNull(r);
         Assert.AreEqual(0, r.Length);
     }
     finally
     {
         b.destroy();
     }
 }
All Usage Examples Of GitSharp.Core.Util.TemporaryBuffer::ToArray