IronRuby.Builtins.RubyIO.AppendBytes C# (CSharp) Method

AppendBytes() public method

public AppendBytes ( MutableString buffer, int count ) : int
buffer MutableString
count int
return int
        public int AppendBytes(MutableString/*!*/ buffer, int count) {
            var stream = GetReadableStream();
            try {
                return stream.AppendBytes(buffer, count, PreserveEndOfLines);
            } catch (ObjectDisposedException) {
                throw RubyExceptions.CreateEBADF();
            }
        }

Usage Example

Beispiel #1
0
        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() == "");

        }
All Usage Examples Of IronRuby.Builtins.RubyIO::AppendBytes