RequireReadable() public method

public RequireReadable ( ) : void
return void
Beispiel #1
0
        public static object Each(RubyContext /*!*/ context, BlockParam block, RubyIO /*!*/ self, [DefaultProtocol] MutableString separator)
        {
            self.RequireReadable();

            MutableString line;

            while ((line = self.ReadLineOrParagraph(separator)) != null)
            {
                if (block == null)
                {
                    throw RubyExceptions.NoBlockGiven();
                }

                line.IsTainted = true;
                context.InputProvider.LastInputLineNumber = ++self.LineNumber;

                object result;
                if (block.Yield(line, out result))
                {
                    return(result);
                }
            }

            return(self);
        }
Beispiel #2
0
        public static int ReadChar(RubyIO /*!*/ self)
        {
            self.RequireReadable();
            int c = self.ReadByteNormalizeEoln();

            if (c == -1)
            {
                throw new EOFError("end of file reached");
            }

            return(c);
        }
Beispiel #3
0
        public static object EachByte(BlockParam block, RubyIO /*!*/ self)
        {
            self.RequireReadable();
            object aByte;

            while ((aByte = Getc(self)) != null)
            {
                if (block == null)
                {
                    throw RubyExceptions.NoBlockGiven();
                }

                object result;
                if (block.Yield((int)aByte, out result))
                {
                    return(result);
                }
            }
            return(self);
        }
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 int ReadChar(RubyIO/*!*/ self) {
            self.RequireReadable();
            int c = self.ReadByteNormalizeEoln();
            
            if (c == -1) {
                throw new EOFError("end of file reached");
            }

            return c;
        }
Beispiel #6
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 #7
0
 public static bool Eof(RubyIO/*!*/ self) {
     self.RequireReadable();
     return self.IsEndOfStream();
 }
Beispiel #8
0
        public static object EachByte(BlockParam block, RubyIO/*!*/ self) {
            self.RequireReadable();
            object aByte;
            while ((aByte = Getc(self)) != null) {
                if (block == null) {
                    throw RubyExceptions.NoBlockGiven();
                }

                object result;
                if (block.Yield((int)aByte, out result)) {
                    return result;
                }
            }
            return self;
        }
Beispiel #9
0
        public static object Each(RubyContext/*!*/ context, BlockParam block, RubyIO/*!*/ self, [DefaultProtocol]MutableString separator, [DefaultProtocol]int limit) {
            self.RequireReadable();

            MutableString line;
            while ((line = self.ReadLineOrParagraph(separator, limit)) != null) {
                if (block == null) {
                    throw RubyExceptions.NoBlockGiven();
                }

                line.IsTainted = true;
                context.InputProvider.LastInputLineNumber = ++self.LineNumber;

                object result;
                if (block.Yield(line, out result)) {
                    return result;
                }
            }

            return self;
        }
Beispiel #10
0
 public static MutableString ReadNoBlock(RubyIO/*!*/ self, [DefaultProtocol]int bytes, [DefaultProtocol, Optional]MutableString buffer) {
     self.RequireReadable();
     MutableString result = null;
     self.NonBlockingOperation(() => result = Read(self, bytes, buffer), true);
     if (result == null) {
         throw new EOFError("end of file reached");
     }
     return result;
 }
Beispiel #11
0
 public static bool Eof(RubyIO /*!*/ self)
 {
     self.RequireReadable();
     return(self.IsEndOfStream());
 }