Esempio n. 1
0
        public RubyIO(RubyContext/*!*/ context) {
            ContractUtils.RequiresNotNull(context, "context");

            _context = context;
            _fileDescriptor = -1;
            _stream = null;
            _externalEncoding = context.DefaultExternalEncoding;
            _internalEncoding = context.DefaultInternalEncoding;
        }
Esempio n. 2
0
        public RubyIO(RubyContext /*!*/ context)
        {
            ContractUtils.RequiresNotNull(context, "context");

            _context          = context;
            _fileDescriptor   = -1;
            _stream           = null;
            _externalEncoding = context.DefaultExternalEncoding;
            _internalEncoding = context.DefaultInternalEncoding;
        }
Esempio n. 3
0
        public RubyIO(RubyContext/*!*/ context) {
            ContractUtils.RequiresNotNull(context, "context");

            _context = context;
            _fileDescriptor = -1;
            _stream = null;

            // TODO (encoding): enable setting
            _externalEncoding = RubyEncoding.Binary;
            _internalEncoding = null;
        }
Esempio n. 4
0
        public RubyIO(RubyContext /*!*/ context)
        {
            ContractUtils.RequiresNotNull(context, "context");

            _context        = context;
            _fileDescriptor = -1;
            _stream         = null;

            // TODO (encoding): enable setting
            _externalEncoding = RubyEncoding.Binary;
            _internalEncoding = null;
        }
Esempio n. 5
0
        public void Close()
        {
            int fd = _fileDescriptor;

            _mode           = _mode.Close();
            _fileDescriptor = -1;

            if (_stream != null)
            {
                _stream = null;
                _context.CloseStream(fd);
            }
        }
Esempio n. 6
0
        public static int SysWrite(BinaryOpStorage /*!*/ writeStorage, ConversionStorage <MutableString> /*!*/ tosConversion,
                                   RubyContext /*!*/ context, RubyIO /*!*/ self, [NotNull] MutableString /*!*/ val)
        {
            RubyBufferedStream stream = self.GetWritableStream();

            if (stream.DataBuffered)
            {
                PrintOps.ReportWarning(writeStorage, tosConversion, MutableString.CreateAscii("syswrite for buffered IO"));
            }
            int bytes = Write(self, val);

            self.Flush();
            return(bytes);
        }
Esempio n. 7
0
        public void File_AppendBytes1()
        {
            string s;
            string crlf = "\r\n";
            var stream = new TestStream(false, B(
                "ab\r\r\n" +
                "e" + (s = "fgh" + crlf + "ijkl" + crlf + "mnop" + crlf + crlf + crlf + crlf + "qrst") +
                crlf + "!"
            ));
            int s_crlf_count = 6;

            var io = new RubyBufferedStream(stream);
            Assert(io.PeekByte() == (byte)'a');

            var buffer = MutableString.CreateBinary(B("foo:"));
            Assert(io.AppendBytes(buffer, 4, false) == 4);
            Assert(buffer.ToString() == "foo:ab\r\n");

            buffer = MutableString.CreateBinary();
            Assert(io.AppendBytes(buffer, 1, false) == 1);
            Assert(buffer.ToString() == "e");

            buffer = MutableString.CreateMutable("x:", RubyEncoding.Binary);
            int c = s.Length - s_crlf_count - 2;
            Assert(io.AppendBytes(buffer, c, false) == c);
            Assert(buffer.ToString() == "x:" + s.Replace(crlf, "\n").Substring(0, c));

            buffer = MutableString.CreateBinary();
            Assert(io.AppendBytes(buffer, 10, false) == 4);
            Assert(buffer.ToString() == "st\n!");

            buffer = MutableString.CreateBinary();
            Assert(io.AppendBytes(buffer, 10, false) == 0);
            Assert(buffer.ToString() == "");

            stream = new TestStream(false, B(s = "abcd" + crlf + "xyz" + crlf + "qqq;"));
            io = new RubyBufferedStream(stream);
            buffer = MutableString.CreateBinary();
            Assert(io.AppendBytes(buffer, Int32.MaxValue, true) == s.Length);
            io.BaseStream.Seek(0, SeekOrigin.Begin);
            Assert(io.AppendBytes(buffer, Int32.MaxValue, false) == s.Length - 2);
            Assert(buffer.ToString() == s + s.Replace(crlf, "\n"));
        }
Esempio n. 8
0
        public void File_WriteBytes1() {
            var stream = new MemoryStream();
            var io = new RubyBufferedStream(stream);

            io.Write(new byte[] { 0, 1, 2, 3 }, 1, 2);
            Assert(stream.ToArray().ValueEquals(new byte[] { 1, 2 }));
            stream.Seek(0, SeekOrigin.Begin);

            Assert(io.WriteBytes(new byte[] { 0, 1, 2, 3 }, 1, 2, true) == 2);
            Assert(stream.ToArray().ValueEquals(new byte[] { 1, 2 }));
            stream.Seek(0, SeekOrigin.Begin);

            Assert(io.WriteBytes(new byte[] { 0, 1, 2, 3 }, 1, 2, false) == 2);
            Assert(stream.ToArray().ValueEquals(new byte[] { 1, 2 }));
            stream.Seek(0, SeekOrigin.Begin);

            Assert(io.WriteBytes(new byte[] { 0, 1, (byte)'\n', 2 }, 1, 2, false) == 3);
            Assert(stream.ToArray().ValueEquals(new byte[] { 1, (byte)'\r', (byte)'\n' }));
            stream.Seek(0, SeekOrigin.Begin);
        }
Esempio n. 9
0
 private void TestReadLine(RubyBufferedStream/*!*/ io, bool preserveEolns, string expected) {
     var s = io.ReadLine(RubyEncoding.Binary, preserveEolns);
     Assert(s == null && expected == null || s.ToString() == expected);
 }
Esempio n. 10
0
        public void File_ReadLine1() {
            var stream = new TestStream(false, B(
                "a\r\n\r\nbbbbbbbbbbbbbbbbbbbbb1bbbbbbbbbbbbb2bbbbbbbbbbbbbbbbbbbbb3bbbbbbbbbbbbb4\rc\nd\n\n\n\nef")
            );

            foreach (int bufferSize in new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100 }) {
                stream.Seek(0, SeekOrigin.Begin);
                var io = new RubyBufferedStream(stream, false, bufferSize);

                TestReadLine(io, true, "a\r\n");
                TestReadLine(io, true, "\r\n");
                TestReadLine(io, true, "bbbbbbbbbbbbbbbbbbbbb1bbbbbbbbbbbbb2bbbbbbbbbbbbbbbbbbbbb3bbbbbbbbbbbbb4\rc\n");
                TestReadLine(io, true, "d\n");
                TestReadLine(io, true, "\n");
                TestReadLine(io, true, "\n");
                TestReadLine(io, true, "\n");
                TestReadLine(io, true, "ef");
                TestReadLine(io, true, null);

                stream.Seek(0, SeekOrigin.Begin);
                TestReadLine(io, false, "a\n");
                TestReadLine(io, false, "\n");
                TestReadLine(io, false, "bbbbbbbbbbbbbbbbbbbbb1bbbbbbbbbbbbb2bbbbbbbbbbbbbbbbbbbbb3bbbbbbbbbbbbb4\rc\n");
                TestReadLine(io, false, "d\n");
                TestReadLine(io, false, "\n");
                TestReadLine(io, false, "\n");
                TestReadLine(io, false, "\n");
                TestReadLine(io, false, "ef");
                TestReadLine(io, false, null);
            }
        }
Esempio n. 11
0
        public void Close() {
            int fd = _fileDescriptor;
            _mode = _mode.Close();
            _fileDescriptor = -1;

            if (_stream != null) {
                _stream = null;
                _context.CloseStream(fd);
            }
        }
Esempio n. 12
0
 public void SetStream(Stream/*!*/ stream) {
     ContractUtils.RequiresNotNull(stream, "stream");
     _stream = new RubyBufferedStream(stream, _context.RubyOptions.Compatibility >= RubyCompatibility.Ruby19);
 }
Esempio n. 13
0
 public void SetStream(Stream /*!*/ stream)
 {
     ContractUtils.RequiresNotNull(stream, "stream");
     _stream = new RubyBufferedStream(stream, _context.RubyOptions.Compatibility >= RubyCompatibility.Ruby19);
 }
Esempio n. 14
0
 public RubyIO(RubyContext/*!*/ context, Stream/*!*/ stream, int descriptor, IOMode mode) 
     : this(context) {
     ContractUtils.RequiresNotNull(context, "context");
     ContractUtils.RequiresNotNull(stream, "stream");
     _stream = new RubyBufferedStream(stream);
     _mode = mode;
     _fileDescriptor = descriptor;
 }
Esempio n. 15
0
 public void SetStream(Stream/*!*/ stream) {
     ContractUtils.RequiresNotNull(stream, "stream");
     _stream = new RubyBufferedStream(stream);
 }