AppendBytes() public method

public AppendBytes ( MutableString buffer, int count ) : int
buffer MutableString
count int
return int
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() == "");

        }
Beispiel #2
0
        public static MutableString /*!*/ Read(RubyIO /*!*/ self)
        {
            var buffer = MutableString.CreateBinary();

            self.AppendBytes(buffer, Int32.MaxValue);
            return(buffer);
        }
Beispiel #3
0
        public static MutableString /*!*/ Read(RubyIO /*!*/ self, DynamicNull bytes, [DefaultProtocol, Optional] MutableString buffer)
        {
            if (buffer == null)
            {
                buffer = MutableString.CreateBinary();
            }
            else
            {
                buffer.Clear();
            }

            self.AppendBytes(buffer, Int32.MaxValue);
            return(buffer);
        }
Beispiel #4
0
        public static MutableString Read(RubyIO /*!*/ self, [DefaultProtocol] int bytes, [DefaultProtocol, Optional] MutableString buffer)
        {
            self.RequireReadable();
            if (bytes < 0)
            {
                throw RubyExceptions.CreateArgumentError("negative length -1 given");
            }

            if (buffer == null)
            {
                buffer = MutableString.CreateBinary();
            }
            else
            {
                buffer.Clear();
            }

            int bytesRead = self.AppendBytes(buffer, bytes);

            return((bytesRead == 0 && bytes != 0) ? null : buffer);
        }
Beispiel #5
0
        public static MutableString Read(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
            self.RequireReadable();
            if (bytes < 0) {
                throw RubyExceptions.CreateArgumentError("negative length -1 given");
            }

            buffer = PrepareReadBuffer(self, buffer);
            int bytesRead = self.AppendBytes(buffer, bytes);
            return (bytesRead == 0 && bytes != 0) ? null : buffer;
        }
Beispiel #6
0
 public static MutableString/*!*/ Read(RubyIO/*!*/ self, DynamicNull bytes, [DefaultProtocol, Optional]MutableString buffer) {
     buffer = PrepareReadBuffer(self, buffer);
     self.AppendBytes(buffer, Int32.MaxValue);
     return buffer;
 }
Beispiel #7
0
 public static MutableString/*!*/ Read(RubyIO/*!*/ self, DynamicNull bytes, [DefaultProtocol, Optional]MutableString buffer) {
     if (buffer == null) {
         buffer = MutableString.CreateBinary();
     } else {
         buffer.Clear();
     } 
     
     self.AppendBytes(buffer, Int32.MaxValue);
     return buffer;
 }
Beispiel #8
0
 public static MutableString/*!*/ Read(RubyIO/*!*/ self) {
     var buffer = MutableString.CreateBinary();
     self.AppendBytes(buffer, Int32.MaxValue);
     return buffer;
 }
Beispiel #9
0
        public static MutableString Read(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
            self.AssertOpenedForReading();
            if (bytes < 0) {
                throw RubyExceptions.CreateArgumentError("negative length -1 given");
            }

            if (buffer == null) {
                buffer = MutableString.CreateBinary();
            } else {
                buffer.Clear();
            }

            int bytesRead = self.AppendBytes(buffer, bytes);
            return (bytesRead == 0 && bytes != 0) ? null : buffer;
        }