Esempio n. 1
0
        public RubyBufferedStream /*!*/ GetWritableStream()
        {
            var result = GetStream();

            if (!_mode.CanWrite())
            {
                throw RubyExceptions.CreateIOError("not opened for writing");
            }
            if (!result.CanWrite)
            {
                throw RubyExceptions.CreateEBADF();
            }
            return(result);
        }
Esempio n. 2
0
        public static RubyIO /*!*/ OpenPipe(
            RubyContext /*!*/ context,
            MutableString /*!*/ command,
            IOMode mode)
        {
            bool redirectStandardInput  = mode.CanWrite();
            bool redirectStandardOutput = mode.CanRead();

            Process process = RubyProcess.CreateProcess(context, command, redirectStandardInput, redirectStandardOutput, false);

            StreamReader reader = null;
            StreamWriter writer = null;

            if (redirectStandardOutput)
            {
                reader = process.StandardOutput;
            }

            if (redirectStandardInput)
            {
                writer = process.StandardInput;
            }

            return(new RubyIO(context, reader, writer, mode));
        }
Esempio n. 3
0
 private MutableString /*!*/ GetWritableContent()
 {
     if (!_mode.CanWrite())
     {
         throw RubyExceptions.CreateIOError("not opened for writing");
     }
     return(_content);
 }
Esempio n. 4
0
        private static MutableString/*!*/ CheckContent(MutableString/*!*/ content, IOMode mode) {
            if (content.IsFrozen && mode.CanWrite()) {
                throw Errno.CreateEACCES("Permission denied");
            }

            if ((mode & IOMode.Truncate) != 0) {
                content.Clear();
            }
            return content;
        }
Esempio n. 5
0
        private static MutableString /*!*/ CheckContent(MutableString /*!*/ content, IOMode mode)
        {
            if (content.IsFrozen && mode.CanWrite())
            {
                throw Errno.CreateEACCES("Permission denied");
            }

            if ((mode & IOMode.Truncate) != 0)
            {
                content.Clear();
            }
            return(content);
        }
Esempio n. 6
0
        public static RubyIO/*!*/ OpenPipe(
            RubyContext/*!*/ context, 
            MutableString/*!*/ command, 
            IOMode mode) {

            bool redirectStandardInput = mode.CanWrite();
            bool redirectStandardOutput = mode.CanRead();

            Process process = RubyProcess.CreateProcess(context, command, redirectStandardInput, redirectStandardOutput, false);

            StreamReader reader = null;
            StreamWriter writer = null;
            if (redirectStandardOutput) {
                reader = process.StandardOutput;
            }

            if (redirectStandardInput) {
                writer = process.StandardInput;
            }

            return new RubyIO(context, reader, writer, mode);
        }
Esempio n. 7
0
 public static IOMode CloseRead(this IOMode mode)
 {
     return((mode & ~IOMode.ReadWriteMask) | (mode.CanWrite() ? IOMode.WriteOnly : IOMode.Closed));
 }