org.jruby
Class RubyIO

java.lang.Object
  extended by org.jruby.RubyObject
      extended by org.jruby.RubyIO
All Implemented Interfaces:
java.lang.Cloneable, IRubyObject
Direct Known Subclasses:
RubyBasicSocket, RubyFile

public class RubyIO
extends RubyObject

Author:
jpetersen

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.Finalizer
 
Field Summary
protected static int fileno
           
protected  IOHandler handler
           
protected  boolean isOpen
           
protected  int lineNumber
           
protected  IOModes modes
           
static int STDERR
           
static int STDIN
           
static int STDOUT
           
 
Fields inherited from class org.jruby.RubyObject
instanceVariables, isTrue, metaClass, NEVER, OBJECT_ALLOCATOR
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyIO(Ruby runtime, java.nio.channels.Channel channel)
           
RubyIO(Ruby runtime, java.io.InputStream inputStream)
           
RubyIO(Ruby runtime, int descriptor)
           
RubyIO(Ruby runtime, java.io.OutputStream outputStream)
           
RubyIO(Ruby runtime, java.lang.Process process)
           
RubyIO(Ruby runtime, RubyClass type)
           
 
Method Summary
 IRubyObject addString(IRubyObject anObject)
          rb_io_addstr
 IRubyObject binmode()
           
protected  void checkReadable()
           
protected  void checkWriteable()
           
 IRubyObject close()
          Closes all open resources for the IO.
 RubyBoolean closed()
          Closes the IO.
 IRubyObject closeWrite()
           
static RubyClass createIOClass(Ruby runtime)
           
 IRubyObject each_byte(Block block)
          Invoke a block for each byte.
 RubyIO each_line(IRubyObject[] args, Block block)
          Invoke a block for each line.
 RubyBoolean eof()
           
 IRubyObject fcntl(IRubyObject cmd, IRubyObject arg)
           
static IRubyObject fdOpen(Ruby runtime, int descriptor)
          Open a file descriptor, unless it is already open, then return it.
 RubyFixnum fileno()
           
 RubyIO flush()
          Flushes the IO output stream.
static IRubyObject foreach(IRubyObject recv, IRubyObject[] args, Block block)
          rb_io_s_foreach
 RubyFixnum fsync()
           
 boolean getBlocking()
           
 IRubyObject getc()
          Read a byte.
 java.nio.channels.Channel getChannel()
           
 java.io.InputStream getInStream()
           
 IOHandler getIOHandlerByFileno(int aFileno)
           
static int getNewFileno()
           
 java.io.OutputStream getOutStream()
           
 IRubyObject gets(IRubyObject[] args)
          Read a line.
 boolean hasPendingBuffered()
           
 IRubyObject initialize_copy(IRubyObject original)
          rb_obj_init_copy
 IRubyObject initialize(IRubyObject[] args, Block unusedBlock)
           
 IRubyObject internalGets(IRubyObject[] args)
          Read a line.
 IRubyObject io_wait()
          waits until input available or timed out and returns self, or nil when EOF reached.
 boolean isOpen()
           
 RubyFixnum lineno_set(IRubyObject newLineNumber)
          Sets the current line number.
 RubyFixnum lineno()
          Returns the current line number.
 IRubyObject pid()
          Return the process id (pid) of the process this IO object spawned.
static IRubyObject pipe(IRubyObject recv)
           
static IRubyObject popen(IRubyObject recv, IRubyObject[] args, Block block)
           
 RubyFixnum pos_set(IRubyObject newPosition)
           
 RubyFixnum pos()
           
 IRubyObject print(IRubyObject[] args)
          Print some objects to the stream.
 IRubyObject printf(IRubyObject[] args)
           
 IRubyObject putc(IRubyObject object)
           
 IRubyObject puts(IRubyObject[] args)
           
 IRubyObject read(IRubyObject[] args)
           
static IRubyObject read(IRubyObject recv, IRubyObject[] args, Block block)
           
 IRubyObject readchar()
          Read a byte.
 IRubyObject readline(IRubyObject[] args)
          Read a line.
 RubyArray readlines(IRubyObject[] args)
           
static RubyArray readlines(IRubyObject recv, IRubyObject[] args, Block block)
           
 IRubyObject readpartial(IRubyObject[] args)
           
 IRubyObject ready()
          returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil.
 void registerIOHandler(IOHandler newHandler)
           
 IRubyObject reopen(IRubyObject[] args)
           
 RubyFixnum rewind()
           
 RubyFixnum seek(IRubyObject[] args)
           
static IRubyObject select_static(Ruby runtime, IRubyObject[] args)
           
static IRubyObject select(IRubyObject recv, IRubyObject[] args)
           
 IRubyObject sync_set(IRubyObject newSync)
          Sets the current sync mode.
 RubyBoolean sync()
          Returns the current sync mode.
 IRubyObject sysread(IRubyObject[] args)
           
 IRubyObject syswrite(IRubyObject obj)
           
 RubyIO to_io()
           
 java.lang.String toString()
           
 RubyBoolean tty()
           
 IRubyObject ungetc(IRubyObject number)
          Pushes char represented by int back onto IOS.
 void unregisterIOHandler(int aFileno)
           
 IRubyObject write(IRubyObject obj)
          io_write
 
Methods inherited from class org.jruby.RubyObject
addFinalizer, anyToString, asString, asSymbol, attachToObjectSpace, callInit, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethodMissing, callMethodMissing, callSuper, checkArrayType, checkFrozen, checkStringType, compilerCallMethod, compilerCallMethodWithIndex, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToString, convertToType, convertToType, convertToType, convertToTypeWithCheck, createObjectClass, dataGetStruct, dataWrapStruct, display, doClone, dup, eql, eqlInternal, equal, equalInternal, equals, evalSimple, evalUnder, evalWithBinding, extend, freeze, frozen, getInstanceVariable, getInstanceVariables, getInstanceVariablesSnapshot, getJavaClass, getMetaClass, getNativeTypeIndex, getRuntime, getSingletonClass, getSingletonClassClone, getType, hash, hashCode, id_deprecated, id, infectBy, inherited, initCopy, inspect, instance_eval, instance_exec, instance_of, instance_variable_get, instance_variable_set, instance_variables, instanceVariableNames, isFalse, isFrozen, isImmediate, isKindOf, isNil, isSingleton, isTaint, isTrue, kind_of, makeMetaClass, match, method, methods, nil_p, obj_equal, private_methods, protected_methods, public_methods, puts, rbClone, remove_instance_variable, removeFinalizers, removeInstanceVariable, respond_to, respondsTo, safeGetInstanceVariables, safeHasInstanceVariables, send, setFrozen, setInstanceVariable, setInstanceVariable, setInstanceVariables, setMetaClass, setTaint, singleton_methods, specificEval, taint, tainted, testFrozen, to_s, trueFalseNil, trueFalseNil, type_deprecated, type, untaint
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

STDIN

public static final int STDIN
See Also:
Constant Field Values

STDOUT

public static final int STDOUT
See Also:
Constant Field Values

STDERR

public static final int STDERR
See Also:
Constant Field Values

handler

protected IOHandler handler

modes

protected IOModes modes

lineNumber

protected int lineNumber

isOpen

protected boolean isOpen

fileno

protected static int fileno
Constructor Detail

RubyIO

public RubyIO(Ruby runtime,
              RubyClass type)

RubyIO

public RubyIO(Ruby runtime,
              java.io.OutputStream outputStream)

RubyIO

public RubyIO(Ruby runtime,
              java.io.InputStream inputStream)

RubyIO

public RubyIO(Ruby runtime,
              java.nio.channels.Channel channel)

RubyIO

public RubyIO(Ruby runtime,
              java.lang.Process process)

RubyIO

public RubyIO(Ruby runtime,
              int descriptor)
Method Detail

registerIOHandler

public void registerIOHandler(IOHandler newHandler)

unregisterIOHandler

public void unregisterIOHandler(int aFileno)

getIOHandlerByFileno

public IOHandler getIOHandlerByFileno(int aFileno)

getNewFileno

public static int getNewFileno()

createIOClass

public static RubyClass createIOClass(Ruby runtime)

fdOpen

public static IRubyObject fdOpen(Ruby runtime,
                                 int descriptor)

Open a file descriptor, unless it is already open, then return it.


checkWriteable

protected void checkWriteable()

checkReadable

protected void checkReadable()

isOpen

public boolean isOpen()

getOutStream

public java.io.OutputStream getOutStream()

getInStream

public java.io.InputStream getInStream()

getChannel

public java.nio.channels.Channel getChannel()

reopen

public IRubyObject reopen(IRubyObject[] args)

internalGets

public IRubyObject internalGets(IRubyObject[] args)
Read a line.


initialize

public IRubyObject initialize(IRubyObject[] args,
                              Block unusedBlock)
Overrides:
initialize in class RubyObject

binmode

public IRubyObject binmode()

syswrite

public IRubyObject syswrite(IRubyObject obj)

write

public IRubyObject write(IRubyObject obj)
io_write


addString

public IRubyObject addString(IRubyObject anObject)
rb_io_addstr


fileno

public RubyFixnum fileno()

lineno

public RubyFixnum lineno()
Returns the current line number.

Returns:
the current line number.

lineno_set

public RubyFixnum lineno_set(IRubyObject newLineNumber)
Sets the current line number.

Parameters:
newLineNumber - The new line number.

sync

public RubyBoolean sync()
Returns the current sync mode.

Returns:
the current sync mode.

pid

public IRubyObject pid()

Return the process id (pid) of the process this IO object spawned. If no process exists (popen was not called), then nil is returned. This is not how it appears to be defined but ruby 1.8 works this way.

Returns:
the pid or nil

hasPendingBuffered

public boolean hasPendingBuffered()

pos

public RubyFixnum pos()

pos_set

public RubyFixnum pos_set(IRubyObject newPosition)

print

public IRubyObject print(IRubyObject[] args)
Print some objects to the stream.


printf

public IRubyObject printf(IRubyObject[] args)

putc

public IRubyObject putc(IRubyObject object)

seek

public RubyFixnum seek(IRubyObject[] args)

rewind

public RubyFixnum rewind()

fsync

public RubyFixnum fsync()

sync_set

public IRubyObject sync_set(IRubyObject newSync)
Sets the current sync mode.

Parameters:
newSync - The new sync mode.

eof

public RubyBoolean eof()

tty

public RubyBoolean tty()

initialize_copy

public IRubyObject initialize_copy(IRubyObject original)
Description copied from class: RubyObject
rb_obj_init_copy

Overrides:
initialize_copy in class RubyObject

closed

public RubyBoolean closed()
Closes the IO.

Returns:
The IO.

close

public IRubyObject close()

Closes all open resources for the IO. It also removes it from our magical all open file descriptor pool.

Returns:
The IO.

closeWrite

public IRubyObject closeWrite()

flush

public RubyIO flush()
Flushes the IO output stream.

Returns:
The IO.

gets

public IRubyObject gets(IRubyObject[] args)
Read a line.


getBlocking

public boolean getBlocking()

fcntl

public IRubyObject fcntl(IRubyObject cmd,
                         IRubyObject arg)
                  throws java.io.IOException
Throws:
java.io.IOException

puts

public IRubyObject puts(IRubyObject[] args)

readline

public IRubyObject readline(IRubyObject[] args)
Read a line.


getc

public IRubyObject getc()
Read a byte. On EOF returns nil.


ungetc

public IRubyObject ungetc(IRubyObject number)

Pushes char represented by int back onto IOS.

Parameters:
number - to push back

readpartial

public IRubyObject readpartial(IRubyObject[] args)

sysread

public IRubyObject sysread(IRubyObject[] args)

read

public IRubyObject read(IRubyObject[] args)

readchar

public IRubyObject readchar()
Read a byte. On EOF throw EOFError.


each_byte

public IRubyObject each_byte(Block block)

Invoke a block for each byte.


each_line

public RubyIO each_line(IRubyObject[] args,
                        Block block)

Invoke a block for each line.


readlines

public RubyArray readlines(IRubyObject[] args)

to_io

public RubyIO to_io()

toString

public java.lang.String toString()
Overrides:
toString in class RubyObject

foreach

public static IRubyObject foreach(IRubyObject recv,
                                  IRubyObject[] args,
                                  Block block)
rb_io_s_foreach


select

public static IRubyObject select(IRubyObject recv,
                                 IRubyObject[] args)

select_static

public static IRubyObject select_static(Ruby runtime,
                                        IRubyObject[] args)

read

public static IRubyObject read(IRubyObject recv,
                               IRubyObject[] args,
                               Block block)

readlines

public static RubyArray readlines(IRubyObject recv,
                                  IRubyObject[] args,
                                  Block block)

popen

public static IRubyObject popen(IRubyObject recv,
                                IRubyObject[] args,
                                Block block)

pipe

public static IRubyObject pipe(IRubyObject recv)
                        throws java.lang.Exception
Throws:
java.lang.Exception

ready

public IRubyObject ready()
returns non-nil if input available without blocking, false if EOF or not open/readable, otherwise nil.


io_wait

public IRubyObject io_wait()
waits until input available or timed out and returns self, or nil when EOF reached.



Copyright © 2002-2007 JRuby Team. All Rights Reserved.