write() public method

public write ( byte bytes ) : void
bytes byte
return void
コード例 #1
0
 public void testDestroyWhileOpen()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     try
     {
         b.write(new TestRng(getName())
                 .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2));
     }
     finally
     {
         b.destroy();
     }
 }
コード例 #2
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();
     }
 }
コード例 #3
0
        public void testRandomWrites()
        {
            TemporaryBuffer b = new TemporaryBuffer();
            TestRng rng = new TestRng(getName());
            int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2;
            byte[] expect = new byte[max];
            try
            {
                int written = 0;
                bool onebyte = true;
                while (written < max)
                {
                    if (onebyte)
                    {
                        byte v = (byte)rng.nextInt();
                        b.write(v);
                        expect[written++] = v;
                    }
                    else
                    {
                        int len = Math.Min(rng.nextInt() & 127, max - written);
                        byte[] tmp = rng.nextBytes(len);
                        b.write(tmp, 0, len);
                        Array.Copy(tmp, 0, expect, written, len);
                        written += len;
                    }
                    onebyte = !onebyte;
                }
                Assert.AreEqual(expect.Length, written);
                b.close();

                Assert.AreEqual(expect.Length, b.Length);
                {
                    byte[] r = b.ToArray();
                    Assert.IsNotNull(r);
                    Assert.AreEqual(expect.Length, r.Length);
                    Assert.IsTrue(expect.SequenceEqual(r));
                }
                {
                    byte[] r;
                    using (MemoryStream o = new MemoryStream())
                    {
                        b.writeTo(o, null);
                        r = o.ToArray();
                    }
                    Assert.AreEqual(expect.Length, r.Length);
                    Assert.IsTrue(expect.SequenceEqual(r));
                }
            }
            finally
            {
                b.destroy();
            }
        }
コード例 #4
0
 public void testOneBlock_BulkWrite()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     byte[] test = new TestRng(getName())
            .nextBytes(TemporaryBuffer.Block.SZ);
     try
     {
         b.write(test, 0, 2);
         b.write(test, 2, 4);
         b.write(test, 6, test.Length - 6 - 2);
         b.write(test, test.Length - 2, 2);
         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();
     }
 }
コード例 #5
0
 public void testOneByte()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     byte test = (byte)new TestRng(getName()).nextInt();
     try
     {
         b.write(test);
         b.close();
         Assert.AreEqual(1, b.Length);
         {
             byte[] r = b.ToArray();
             Assert.IsNotNull(r);
             Assert.AreEqual(1, r.Length);
             Assert.AreEqual(test, r[0]);
         }
         {
             byte[] r;
             using (MemoryStream o = new MemoryStream())
             {
                 b.writeTo(o, null);
                 r = o.ToArray();
             }
             Assert.AreEqual(1, r.Length);
             Assert.AreEqual(test, r[0]);
         }
     }
     finally
     {
         b.destroy();
     }
 }
コード例 #6
0
 public void testOneBlockAndHalf_SingleWrite()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     byte[] test = new TestRng(getName())
            .nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
     try
     {
         for (int i = 0; i < test.Length; i++)
             b.write(test[i]);
         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();
     }
 }
コード例 #7
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();
     }
 }
コード例 #8
0
ファイル: DirCacheTree.cs プロジェクト: spraints/GitSharp
        public void write(byte[] tmp, TemporaryBuffer os)
        {
            int ptr = tmp.Length;
            tmp[--ptr] = (byte)'\n';
            ptr = RawParseUtils.formatBase10(tmp, ptr, _childCount);
            tmp[--ptr] = (byte)' ';
            ptr = RawParseUtils.formatBase10(tmp, ptr, isValid() ? _entrySpan : -1);
            tmp[--ptr] = 0;

            os.write(_encodedName, 0, _encodedName.Length);
            os.write(tmp, ptr, tmp.Length - ptr);

            if (isValid())
            {
                _id.copyRawTo(tmp, 0);
                os.write(tmp, 0, Constants.OBJECT_ID_LENGTH);
            }

            for (int i = 0; i < _childCount; i++)
            {
                _children[i].write(tmp, os);
            }
        }
コード例 #9
0
 public void testLarge_SingleWrite()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     byte[] test = new TestRng(getName()).nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
     try
     {
         b.write(test);
         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));
         }
         {
             MemoryStream o = new MemoryStream();
             b.writeTo(o, null);
             o.Close();
             byte[] r = o.ToArray();
             Assert.AreEqual(test.Length, r.Length);
             Assert.IsTrue(test.SequenceEqual(r));
         }
     }
     finally
     {
         b.destroy();
     }
 }
コード例 #10
0
 public void testInCoreLimit_SwitchOnCopy()
 {
     TemporaryBuffer b = new TemporaryBuffer();
     byte[] test = new TestRng(getName())
            .nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2);
     try
     {
         MemoryStream @in = new MemoryStream(test,
                TemporaryBuffer.DEFAULT_IN_CORE_LIMIT, test.Length
                        - TemporaryBuffer.DEFAULT_IN_CORE_LIMIT);
         b.write(test, 0, TemporaryBuffer.DEFAULT_IN_CORE_LIMIT);
         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));
         }
         {
             MemoryStream o = new MemoryStream();
             b.writeTo(o, null);
             o.Close();
             byte[] r = o.ToArray();
             Assert.AreEqual(test.Length, r.Length);
             Assert.IsTrue(test.SequenceEqual(r));
         }
     }
     finally
     {
         b.destroy();
     }
 }