Exemplo n.º 1
0
        public void Write()
        {
            string        path = GetFile();
            StdFileStream fs   = new StdFileStream(path, FileMode.Open);

            Assert.AreEqual(0, fs.Length);
            Assert.AreEqual(0, fs.Position);

            fs.Write(new byte[] { 100, 103, 103, 104, 105 }, 0, 5);
            Assert.AreEqual(5, fs.Length);
            Assert.AreEqual(5, fs.Position);

            fs.Position = 2;
            Assert.AreEqual(2, fs.Position);

            fs.Write(new byte[] { 100, 103, 103, 104, 105 }, 1, 2);
            Assert.AreEqual(5, fs.Length);
            Assert.AreEqual(4, fs.Position);

            fs.Write(new byte[] { 100, 103, 103, 104, 105 }, 1, 2);
            Assert.AreEqual(6, fs.Length);
            Assert.AreEqual(6, fs.Position);

            fs.Close();
        }
Exemplo n.º 2
0
        public void Read()
        {
            byte[]        buffer = new byte[1024];
            string        path   = GetFile();
            StdFileStream fs     = new StdFileStream(path, FileMode.Open);

            fs.Write(new byte[] { 100, 102, 103, 104, 105, 106, 107, 108 }, 0, 8);
            fs.Position = 0;

            Assert.AreEqual(2, fs.Read(buffer, 0, 2));
            Assert.AreEqual(new byte[] { 100, 102 }, buffer.Take(2));

            Assert.AreEqual(5, fs.Read(buffer, 2, 5));
            Assert.AreEqual(new byte[] { 100, 102, 103, 104, 105, 106, 107 }, buffer.Take(7));

            Assert.AreEqual(1, fs.Read(buffer, 1, 5));
            Assert.AreEqual(new byte[] { 100, 108, 103, 104, 105, 106, 107 }, buffer.Take(7));

            Assert.AreEqual(0, fs.Read(buffer, 0, 5));

            fs.Close();
        }
Exemplo n.º 3
0
        public StdFileStream BuildFile(long length)
        {
            string path = GetFile();
            StdFileStream fs = new StdFileStream(path, FileMode.Open);

            try
            {
                byte[] buffer = new byte[4096];
                long remaining = length;

                while (remaining > 0)
                {
                    fs.Write(buffer, 0, (int)Math.Min(remaining, buffer.Length));
                    remaining -= buffer.Length;
                }

                return fs;
            }
            catch
            {
                fs.Close();
                throw;
            }
        }
Exemplo n.º 4
0
        public StdFileStream BuildFile(long length)
        {
            string        path = GetFile();
            StdFileStream fs   = new StdFileStream(path, FileMode.Open);

            try
            {
                byte[] buffer    = new byte[4096];
                long   remaining = length;

                while (remaining > 0)
                {
                    fs.Write(buffer, 0, (int)Math.Min(remaining, buffer.Length));
                    remaining -= buffer.Length;
                }

                return(fs);
            }
            catch
            {
                fs.Close();
                throw;
            }
        }
Exemplo n.º 5
0
        public void Write()
        {
            string path = GetFile();
            StdFileStream fs = new StdFileStream(path, FileMode.Open);

            Assert.AreEqual(0, fs.Length);
            Assert.AreEqual(0, fs.Position);

            fs.Write(new byte[] { 100, 103, 103, 104, 105 }, 0, 5);
            Assert.AreEqual(5, fs.Length);
            Assert.AreEqual(5, fs.Position);

            fs.Position = 2;
            Assert.AreEqual(2, fs.Position);

            fs.Write(new byte[] { 100, 103, 103, 104, 105 }, 1, 2);
            Assert.AreEqual(5, fs.Length);
            Assert.AreEqual(4, fs.Position);

            fs.Write(new byte[] { 100, 103, 103, 104, 105 }, 1, 2);
            Assert.AreEqual(6, fs.Length);
            Assert.AreEqual(6, fs.Position);

            fs.Close();
        }
Exemplo n.º 6
0
        public void Read()
        {
            byte[] buffer = new byte[1024];
            string path = GetFile();
            StdFileStream fs = new StdFileStream(path, FileMode.Open);

            fs.Write(new byte[] { 100, 102, 103, 104, 105, 106, 107, 108 }, 0, 8);
            fs.Position = 0;

            Assert.AreEqual(2, fs.Read(buffer, 0, 2));
            Assert.AreEqual(new byte[] { 100, 102 }, buffer.Take(2));

            Assert.AreEqual(5, fs.Read(buffer, 2, 5));
            Assert.AreEqual(new byte[] { 100, 102, 103, 104, 105, 106, 107 }, buffer.Take(7));

            Assert.AreEqual(1, fs.Read(buffer, 1, 5));
            Assert.AreEqual(new byte[] { 100, 108, 103, 104, 105, 106, 107 }, buffer.Take(7));

            Assert.AreEqual(0, fs.Read(buffer, 0, 5));

            fs.Close();
        }