Beispiel #1
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            ByteReaderTestData.Init();
            var nBytes      = ByteReaderTestData.nBytes;
            var nBlocks     = ByteReaderTestData.nBlocks;
            var testBytes   = ByteReaderTestData.testBytes;
            var infileName  = ByteReaderTestData.infileName;
            var outfileName = ByteReaderTestData.outfileName;

            byte[]       buf    = new byte[nBytes];
            MgByteReader reader = new MgByteReader(infileName, "png", false);

            Assert.AreEqual(nBlocks * nBytes, reader.GetLength());
            reader.Read(buf, nBytes);
            Assert.AreEqual(buf, testBytes);
            Assert.AreEqual((nBlocks - 1) * nBytes, reader.GetLength());
            reader.Rewind();
            Assert.AreEqual(nBlocks * nBytes, reader.GetLength());
            reader.ToFile(outfileName);
            reader.Rewind();

            byte[] buf2             = new byte[nBytes];
            System.IO.FileStream fp = System.IO.File.OpenRead(outfileName);
            for (int j = 0; j < nBlocks; j++)
            {
                fp.Read(buf2, 0, nBytes);
                reader.Read(buf, nBytes);
                Assert.AreEqual(buf, buf2);
            }
            fp.Close();
        }
Beispiel #2
0
        /// <summary>
        /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
        /// </summary>
        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between <paramref name="offset"/> and (<paramref name="offset"/> + <paramref name="count"/> - 1) replaced by the bytes read from the current source.</param>
        /// <param name="offset">The zero-based byte offset in <paramref name="buffer"/> at which to begin storing the data read from the current stream.</param>
        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
        /// <returns>
        /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
        /// </returns>
        /// <exception cref="T:System.ArgumentException">
        /// The sum of <paramref name="offset"/> and <paramref name="count"/> is larger than the buffer length.
        ///   </exception>
        ///
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="buffer"/> is null.
        ///   </exception>
        ///
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="offset"/> or <paramref name="count"/> is negative.
        ///   </exception>
        ///
        /// <exception cref="T:System.IO.IOException">
        /// An I/O error occurs.
        ///   </exception>
        ///
        /// <exception cref="T:System.NotSupportedException">
        /// The stream does not support reading.
        ///   </exception>
        ///
        /// <exception cref="T:System.ObjectDisposedException">
        /// Methods were called after the stream was closed.
        ///   </exception>
        public override int Read(byte[] buffer, int offset, int count)
        {
            int read = 0;

            //For good times, please always have the offset as 0
            if (offset == 0)
            {
                read = _reader.Read(buffer, count);
            }
            else //So you want to play the hard way eh? Bad performance for you!
            {
                byte[] b = new byte[count];
                read = _reader.Read(b, count);
                Array.Copy(b, 0, buffer, offset, read);
            }
            return(read);
        }
Beispiel #3
0
        public ImageResponseDialog(MgByteReader reader)
            : this()
        {
            byte[] b = new byte[reader.GetLength()];
            reader.Read(b, b.Length);
            using (var ms = new MemoryStream(b))
            {
                var img = Image.FromStream(ms);
                picResult.Image = img;

                this.Width = img.Width;
                this.Height = img.Height;
            }
        }
Beispiel #4
0
        public void FileConstructor()
        {
            byte[] buf = new byte[nBytes];
            MgByteReader reader = new MgByteReader(infileName, "png", false);
            Assert.AreEqual(nBlocks * nBytes, reader.GetLength());
            reader.Read(buf, nBytes);
            Assert.AreEqual(buf, testBytes);
            Assert.AreEqual((nBlocks-1) * nBytes, reader.GetLength());
            reader.Rewind();
            Assert.AreEqual(nBlocks * nBytes, reader.GetLength());
            reader.ToFile(outfileName);
            reader.Rewind();

            byte[] buf2 = new byte[nBytes];
            System.IO.FileStream fp = System.IO.File.OpenRead(outfileName);
            for (int j = 0; j < nBlocks; j++)
            {
                fp.Read(buf2, 0, nBytes);
                reader.Read(buf, nBytes);
                Assert.AreEqual(buf, buf2);
            }
            fp.Close();
        }
Beispiel #5
0
        public ImageResponseDialog(MgByteReader reader)
            : this()
        {
            byte[] b = new byte[reader.GetLength()];
            reader.Read(b, b.Length);
            using (var ms = new MemoryStream(b))
            {
                var img = Image.FromStream(ms);
                picResult.Image = img;

                this.Width  = img.Width;
                this.Height = img.Height;
            }
        }
Beispiel #6
0
        public void MemoryConstructor()
        {
            byte[] buf = new byte[nBytes];
            MgByteReader reader = new MgByteReader(testBytes, nBytes, "png");
            Assert.AreEqual(nBytes, reader.GetLength());
            reader.Read(buf, nBytes);
            Assert.AreEqual(buf, testBytes);
            Assert.AreEqual(0, reader.GetLength());
            reader.Rewind();
            Assert.AreEqual(nBytes, reader.GetLength());

            reader.ToFile(outfileName);

            System.IO.FileStream fp = System.IO.File.OpenRead(outfileName);
            fp.Read(buf, 0, nBytes);
            Assert.AreEqual(buf, testBytes);
            fp.Close();
        }
Beispiel #7
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            ByteReaderTestData.Init();
            var nBytes      = ByteReaderTestData.nBytes;
            var testBytes   = ByteReaderTestData.testBytes;
            var outfileName = ByteReaderTestData.outfileName;

            byte[]       buf    = new byte[nBytes];
            MgByteReader reader = new MgByteReader(testBytes, nBytes, "png");

            Assert.AreEqual(nBytes, reader.GetLength());
            reader.Read(buf, nBytes);
            Assert.AreEqual(buf, testBytes);
            Assert.AreEqual(0, reader.GetLength());
            reader.Rewind();
            Assert.AreEqual(nBytes, reader.GetLength());

            reader.ToFile(outfileName);

            System.IO.FileStream fp = System.IO.File.OpenRead(outfileName);
            fp.Read(buf, 0, nBytes);
            Assert.AreEqual(buf, testBytes);
            fp.Close();
        }
Beispiel #8
0
        void OutputReaderContent(HttpResponse response, MgByteReader byteReader)
        {
            MemoryStream memBuf = new MemoryStream();

            byte[] byteBuffer = new byte[1024];
            int numBytes = byteReader.Read(byteBuffer, 1024);
            while (numBytes > 0)
            {
                memBuf.Write(byteBuffer, 0, numBytes);
                numBytes = byteReader.Read(byteBuffer, 1024);
            }

            response.ContentType = byteReader.GetMimeType();
            byte[] content = memBuf.ToArray();
            response.OutputStream.Write(content, 0, content.Length);
        }
 IActionResult OutputReaderContent(MgByteReader outputReader)
 {
     using (MemoryStream memBuf = new MemoryStream())
     {
         byte[] byteBuffer = new byte[1024];
         int numBytes = outputReader.Read(byteBuffer, 1024);
         while (numBytes > 0)
         {
             memBuf.Write(byteBuffer, 0, numBytes);
             numBytes = outputReader.Read(byteBuffer, 1024);
         }
         byte[] content = memBuf.ToArray();
         return File(content, outputReader.MimeType);
     }
 }