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

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

public writeTo ( Stream os, ProgressMonitor pm ) : void
os Stream
pm ProgressMonitor
Результат void
        public void writeTo(Stream os, ProgressMonitor pm)
        {
            if (pm == null)
                pm = new NullProgressMonitor();
            if (_blocks != null)
            {
                // Everything is in core so we can stream directly to the output.
                //
                foreach (Block b in _blocks)
                {
                    os.Write(b.buffer, 0, b.count);
                    pm.Update(b.count / 1024);
                }
            }
            else
            {
                // Reopen the temporary file and copy the contents.
                //
                using (var @in = new FileStream(_onDiskFile.FullName, System.IO.FileMode.Open, FileAccess.Read))
                {
                    int cnt;
                    byte[] buf = new byte[Block.SZ];
                    while ((cnt = @in.Read(buf, 0, buf.Length)) > 0)
                    {
                        os.Write(buf, 0, cnt);
                        pm.Update(cnt / 1024);
                    }
                }
            }
        }

Usage Example

Пример #1
0
 public void testInCoreLimit_SwitchBeforeAppendByte()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     byte[] test = new TestRng(getName())
            .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
     try
     {
         b.write(test, 0, test.Length - 1);
         b.write(test[test.Length - 1]);
         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::writeTo