コード例 #1
0
ファイル: TypeWriter.cs プロジェクト: FilRip/IMDEV.Commun
 /**
  * Writes a 16-byte {@link ClassID} To an output stream.
  *
  * @param out The stream To Write To
  * @param n The value To Write
  * @return The number of bytes written
  * @exception IOException if an I/O error occurs
  */
 public static int WriteToStream(Stream out1, ClassID n)
 {
     byte[] b = new byte[16];
     n.Write(b, 0);
     out1.Write(b, 0, b.Length);
     return(b.Length);
 }
コード例 #2
0
        public void TestWriteArrayStoreException()
        {
            ClassID clsidTest = new ClassID(
                new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                             0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }
                , 0
                );
            bool bExceptionOccurred = false;

            try
            {
                clsidTest.Write(new byte[15], 0);
            }
            catch (Exception)
            {
                bExceptionOccurred = true;
            }
            Assert.IsTrue(bExceptionOccurred);

            bExceptionOccurred = false;
            try
            {
                clsidTest.Write(new byte[16], 1);
            }
            catch (Exception)
            {
                bExceptionOccurred = true;
            }
            Assert.IsTrue(bExceptionOccurred);

            // These should work without throwing an Exception
            bExceptionOccurred = false;
            try
            {
                clsidTest.Write(new byte[16], 0);
                clsidTest.Write(new byte[17], 1);
            }
            catch (Exception)
            {
                bExceptionOccurred = true;
            }
            Assert.IsFalse(bExceptionOccurred);
        }