Пример #1
0
 public void ReadFullyZeroBufferSize()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         StreamUtil.ReadFully(new MemoryStream(), 0);
     });
 }
Пример #2
0
 public void ReadFullyZeroLengthBuffer()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         StreamUtil.ReadFully(new MemoryStream(), new byte[0]);
     });
 }
Пример #3
0
    private static void savePicture()
    {
        using (SQLiteConnection cnn = new SQLiteConnection(""))
        {
            cnn.Open();
            using (SQLiteCommand cmd = cnn.CreateCommand())
            {
                //cmd.CommandText = "Create Table test(data Image)";
                //cmd.ExecuteNonQuery();

                cmd.CommandText = "insert into person values('12',@data,'14','13')";
                SQLiteParameter para = new SQLiteParameter("@data", DbType.Binary);
                string          file = @"F:/Image/飞机.png";
                FileStream      fs   = new FileStream(file, FileMode.Open);

                //StreamUtil su = new StreamUtil();
                //byte[] buffer = su.StreamToBytes(fs);
                byte[] buffer = StreamUtil.ReadFully(fs);

                fs.Close();

                para.Value = buffer;
                cmd.Parameters.Add(para);
                cmd.ExecuteNonQuery();
            }
        }
    }
Пример #4
0
 public void ReadFullyNullInput()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         StreamUtil.ReadFully(null);
     });
 }
Пример #5
0
        public static void Pack(Stream inputStream, Stream outputStream, GxGame game)
        {
            if (inputStream == null)
            {
                throw new ArgumentNullException("inputStream");
            }
            if (outputStream == null)
            {
                throw new ArgumentNullException("outputStream");
            }
            if (!Enum.IsDefined(typeof(GxGame), game))
            {
                throw new ArgumentOutOfRangeException("game");
            }

            // Read the input data and compress with LZSS
            byte[] uncompressedData = StreamUtil.ReadFully(inputStream);

            LzssEncoder encoder = new LzssEncoder();

            byte[] compressedData = encoder.Encode(uncompressedData);

            // Write file header and data
            int headerSizeField = compressedData.Length;

            if (game == GxGame.SuperMonkeyBall || game == GxGame.SuperMonkeyBallDX)
            {
                headerSizeField += 8; // SMB counts the 8 bytes of header in the compressed size field
            }
            EndianBinaryWriter outputBinaryWriter = new EndianBinaryWriter(EndianBitConverter.Little, outputStream);

            outputBinaryWriter.Write(headerSizeField);
            outputBinaryWriter.Write(uncompressedData.Length);
            outputBinaryWriter.Write(compressedData);
        }
Пример #6
0
 public void ReadFullyNullIBuffer()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         StreamUtil.ReadFully(new MemoryStream(), null as IBuffer);
     });
 }
Пример #7
0
        private static byte[] ReadColorTable(int bpc, GifImageHelper.GifParameters gif)
        {
            int ncolors = 1 << bpc;
            int nbytes  = 3 * ncolors;

            bpc = NewBpc(bpc);
            byte[] table = new byte[(1 << bpc) * 3];
            StreamUtil.ReadFully(gif.input, table, 0, nbytes);
            return(table);
        }
Пример #8
0
        public void ReadFullyWithByteBuffer()
        {
            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            byte[] actual = StreamUtil.ReadFully(input, new byte[8]);
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
            Assert.AreEqual(8, input.LastReadSize);
        }
Пример #9
0
        public void ReadFullyWithDataDefaults()
        {
            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            byte[] actual = StreamUtil.ReadFully(input);
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
            Assert.AreEqual(8 * 1024, input.LastReadSize);
        }
Пример #10
0
        public void ReadFullyWithOutCopying()
        {
            StreamStub input = new StreamStub();

            // The memory stream will expand to 256 bytes by default
            byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            for (int i = 0; i < 32; i++)
            {
                input.AddReadData(data);
            }
            byte[] actual = StreamUtil.ReadFully(input, new byte[8]);
            Assert.AreEqual(256, actual.Length);
            for (int i = 0; i < 256; i++)
            {
                Assert.AreEqual(i % 8, actual[i]);
            }
            Assert.AreEqual(8, input.LastReadSize);
        }
Пример #11
0
        public void ReadFullyWithIBuffer()
        {
            CachingBufferManager.Options options = new CachingBufferManager.Options();
            options.MinBufferSize = 7;
            CachingBufferManager manager = new CachingBufferManager(options);

            StreamStub input = new StreamStub();

            input.AddReadData(new byte[] { 1, 2, 3, 4, 5 });
            input.AddReadData(new byte[] { 6, 7, 8, 9, 10 });
            byte[] actual;
            using (IBuffer buffer = manager.GetBuffer(10))
            {
                actual = StreamUtil.ReadFully(input, buffer);
            }
            Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, actual);
            Assert.AreEqual(14, input.LastReadSize);
        }
Пример #12
0
 private static byte[] GetByteData(Stream stream)
 {
     return(StreamUtil.ReadFully(stream));
 }
Пример #13
0
 public void ReadFullyZeroBufferSize()
 {
     StreamUtil.ReadFully(new MemoryStream(), 0);
 }
Пример #14
0
 public void ReadFullyNullIBuffer()
 {
     StreamUtil.ReadFully(new MemoryStream(), null as IBuffer);
 }
Пример #15
0
 public void ReadFullyNullByteBuffer()
 {
     StreamUtil.ReadFully(new MemoryStream(), null as byte[]);
 }
Пример #16
0
 public void ReadFullyZeroLengthBuffer()
 {
     StreamUtil.ReadFully(new MemoryStream(), new byte[0]);
 }
Пример #17
0
        private static void DecodePass(int xOffset, int yOffset, int xStep, int yStep, int passWidth, int passHeight
                                       , PngImageHelper.PngParameters png)
        {
            if ((passWidth == 0) || (passHeight == 0))
            {
                return;
            }
            int bytesPerRow = (png.inputBands * passWidth * png.bitDepth + 7) / 8;

            byte[] curr  = new byte[bytesPerRow];
            byte[] prior = new byte[bytesPerRow];
            // Decode the (sub)image row-by-row
            int srcY;
            int dstY;

            for (srcY = 0, dstY = yOffset; srcY < passHeight; srcY++, dstY += yStep)
            {
                // Read the filter type byte and a row of data
                int filter = 0;
                try {
                    filter = png.dataStream.Read();
                    StreamUtil.ReadFully(png.dataStream, curr, 0, bytesPerRow);
                }
                catch (Exception) {
                }
                switch (filter)
                {
                case PNG_FILTER_NONE: {
                    // empty on purpose
                    break;
                }

                case PNG_FILTER_SUB: {
                    DecodeSubFilter(curr, bytesPerRow, png.bytesPerPixel);
                    break;
                }

                case PNG_FILTER_UP: {
                    DecodeUpFilter(curr, prior, bytesPerRow);
                    break;
                }

                case PNG_FILTER_AVERAGE: {
                    DecodeAverageFilter(curr, prior, bytesPerRow, png.bytesPerPixel);
                    break;
                }

                case PNG_FILTER_PAETH: {
                    DecodePaethFilter(curr, prior, bytesPerRow, png.bytesPerPixel);
                    break;
                }

                default: {
                    // Error -- uknown filter type
                    throw new iText.IO.IOException(iText.IO.IOException.UnknownPngFilter);
                }
                }
                ProcessPixels(curr, xOffset, xStep, dstY, passWidth, png);
                // Swap curr and prior
                byte[] tmp = prior;
                prior = curr;
                curr  = tmp;
            }
        }
Пример #18
0
 public void ReadFullyNullInput()
 {
     StreamUtil.ReadFully(null);
 }