当前位置: 首页>>代码示例>>C#>>正文


C# Builtins.RubyIO类代码示例

本文整理汇总了C#中IronRuby.Builtins.RubyIO的典型用法代码示例。如果您正苦于以下问题:C# RubyIO类的具体用法?C# RubyIO怎么用?C# RubyIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RubyIO类属于IronRuby.Builtins命名空间,在下文中一共展示了RubyIO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_Read1

        private void Test_Read1() {
            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 RubyIO(Context, stream, "r");
            Assert(io.PeekByte() == (byte)'a');

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

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

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

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

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

        }
开发者ID:xerxesb,项目名称:ironruby,代码行数:35,代码来源:IoTests.cs

示例2: CreateIO

        public static void CreateIO(RubyIO/*!*/ self,
            [DefaultProtocol]int fileDescriptor, [DefaultProtocol, NotNull, Optional]MutableString modeString) {

            // TODO:
            if (modeString != null) {
                self.ResetIOMode(modeString.ConvertToString());
            }
        }
开发者ID:m4dc4p,项目名称:ironruby,代码行数:8,代码来源:IoOps.cs

示例3: InitializeCopy

        public static RubyIO/*!*/ InitializeCopy(RubyIO/*!*/ self, [NotNull]RubyIO/*!*/ source) {
            Stream stream = source.GetStream();
            int descriptor = self.Context.DuplicateFileDescriptor(source.GetFileDescriptor());

            self.SetStream(stream);
            self.SetFileDescriptor(descriptor);
            self.Mode = source.Mode;
            return self;
        }
开发者ID:techarch,项目名称:ironruby,代码行数:9,代码来源:IoOps.cs

示例4: Request

        public Request(HttpRequestBase request) {
            ContractUtils.RequiresNotNull(request, "request");

            // http or https
            this.scheme = request.Url.Scheme;

            // move headers to a Ruby Hash
            this.headers = new Hash(RubyEngine.Context);
            foreach (string key in request.Headers.AllKeys) {
                string value = request.Headers.Get(key);
                if (string.IsNullOrEmpty(value)) continue;
                headers.Add(key, value);
            }

            this.queryString = request.QueryString.ToString();

            this.body = new RubyIO(RubyEngine.Context, request.InputStream, IOMode.ReadOnly);

            // Save the origional request incase it's needed.
            OrigionalRequest = request;
        }
开发者ID:BenHall,项目名称:ironruby,代码行数:21,代码来源:Request.cs

示例5: ReadLines

        public static RubyArray/*!*/ ReadLines(RubyContext/*!*/ context, RubyIO/*!*/ self, [DefaultProtocol]MutableString separator, [DefaultProtocol]int limit) {
            RubyArray result = new RubyArray();

            // no dynamic call, doesn't modify $_ scope variable:
            MutableString line;
            while ((line = self.ReadLineOrParagraph(separator, limit)) != null) {
                result.Add(line);
            }

            self.LineNumber += result.Count;
            context.InputProvider.LastInputLineNumber = self.LineNumber;
            return result;
        }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:13,代码来源:IoOps.cs

示例6: ReadLine

        public static MutableString/*!*/ ReadLine(RubyScope/*!*/ scope, RubyIO/*!*/ self, [DefaultProtocol]MutableString separator, [DefaultProtocol]int limit) {

            // no dynamic call, modifies $_ scope variable:
            MutableString result = Gets(scope, self, separator, limit);
            if (result == null) {
                throw new EOFError("end of file reached");
            }

            return result;
        }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:10,代码来源:IoOps.cs

示例7: ReadChar

        public static int ReadChar(RubyIO/*!*/ self) {
            self.RequireReadable();
            int c = self.ReadByteNormalizeEoln();
            
            if (c == -1) {
                throw new EOFError("end of file reached");
            }

            return c;
        }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:10,代码来源:IoOps.cs

示例8: SystemRead

        public static MutableString/*!*/ SystemRead(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
            var stream = self.GetReadableStream();
            if (stream.DataBuffered) {
                throw RubyExceptions.CreateIOError("sysread for buffered IO");
            }

            // We use Flush to simulate non-buffered IO. 
            // A better approach would be to create a parallel FileStream with 
            // System.IO.FileOptions.WriteThrough (which corresponds to FILE_FLAG_NO_BUFFERING), and also maybe 
            // System.IO.FileOptions.SequentialScan (FILE_FLAG_SEQUENTIAL_SCAN).
            // TODO: sysopen does that?
            stream.Flush();

            var result = Read(self, bytes, buffer);
            if (result == null) {
                throw new EOFError("end of file reached");
            }
            return result;
        }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:19,代码来源:IoOps.cs

示例9: SetLineNumber

 public static void SetLineNumber(RubyContext/*!*/ context, RubyIO/*!*/ self, [DefaultProtocol]int value) {
     self.RequireOpen();
     self.LineNumber = value;
 }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:4,代码来源:IoOps.cs

示例10: GetLineNumber

 public static int GetLineNumber(RubyIO/*!*/ self) {
     self.RequireOpen();
     return self.LineNumber;
 }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:4,代码来源:IoOps.cs

示例11: Pos

 public static void Pos(RubyIO/*!*/ self, [DefaultProtocol]IntegerValue pos) {
     self.Seek(pos.ToInt64(), SeekOrigin.Begin);
 }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:3,代码来源:IoOps.cs

示例12: SysSeek

 public static object SysSeek(RubyIO/*!*/ self, [DefaultProtocol]IntegerValue pos, [DefaultProtocol, DefaultParameterValue(SEEK_SET)]int seekOrigin) {
     self.Flush();
     self.Seek(pos.ToInt64(), RubyIO.ToSeekOrigin(seekOrigin));
     return pos.ToObject();
 }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:5,代码来源:IoOps.cs

示例13: Read

 public static MutableString/*!*/ Read(RubyIO/*!*/ self, DynamicNull bytes, [DefaultProtocol, Optional]MutableString buffer) {
     buffer = PrepareReadBuffer(self, buffer);
     self.AppendBytes(buffer, Int32.MaxValue);
     return buffer;
 }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:5,代码来源:IoOps.cs

示例14: Write

 public static int Write(RubyIO/*!*/ self, [NotNull]MutableString/*!*/ val) {
     int bytesWritten = val.IsEmpty ? 0 : self.WriteBytes(val, 0, val.GetByteCount());
     if (self.AutoFlush) {
         self.Flush();
     }
     return bytesWritten;
 }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:7,代码来源:IoOps.cs

示例15: ReadNoBlock

 public static MutableString ReadNoBlock(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
     var stream = self.GetReadableStream();
     MutableString result = null;
     self.NonBlockingOperation(() => result = Read(self, bytes, buffer), true);
     return result;
 }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:6,代码来源:IoOps.cs


注:本文中的IronRuby.Builtins.RubyIO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。