本文整理汇总了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() == "");
}
示例2: CreateIO
public static void CreateIO(RubyIO/*!*/ self,
[DefaultProtocol]int fileDescriptor, [DefaultProtocol, NotNull, Optional]MutableString modeString) {
// TODO:
if (modeString != null) {
self.ResetIOMode(modeString.ConvertToString());
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例9: SetLineNumber
public static void SetLineNumber(RubyContext/*!*/ context, RubyIO/*!*/ self, [DefaultProtocol]int value) {
self.RequireOpen();
self.LineNumber = value;
}
示例10: GetLineNumber
public static int GetLineNumber(RubyIO/*!*/ self) {
self.RequireOpen();
return self.LineNumber;
}
示例11: Pos
public static void Pos(RubyIO/*!*/ self, [DefaultProtocol]IntegerValue pos) {
self.Seek(pos.ToInt64(), SeekOrigin.Begin);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}