• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Builtins.RubyIO类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: SysWrite

        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;
        }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:11,代码来源:IoOps.cs


示例17: WriteNoBlock

 public static int WriteNoBlock(RubyIO/*!*/ self, [NotNull]MutableString/*!*/ val) {
     var stream = self.GetWritableStream();
     int result = -1;
     self.NonBlockingOperation(() => result = Write(self, val), false);
     return result;
 }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:6,代码来源:IoOps.cs


示例18: PrepareReadBuffer

        private static MutableString PrepareReadBuffer(RubyIO/*!*/ io, MutableString buffer) {
            if (buffer == null) {
                buffer = MutableString.CreateBinary();
            } else {
                buffer.Clear();
            } 
#if TODO
            var internalEncoding = io.InternalEncoding ?? io.ExternalEncoding;

            if (buffer != null) {
                buffer.Clear();
                buffer.ForceEncoding(internalEncoding);
            } else if (io.ExternalEncoding == RubyEncoding.Binary && internalEncoding == RubyEncoding.Binary) {
                buffer = MutableString.CreateBinary();
            } else {
                buffer = MutableString.CreateMutable(internalEncoding);
            }
#endif            
            return buffer;
        }
开发者ID:ghouston,项目名称:ironlanguages,代码行数:20,代码来源:IoOps.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Builtins.RubyModule类代码示例发布时间:2022-05-26
下一篇:
C# Builtins.RubyFile类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap