org.jruby
Class RubyIO

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

public class RubyIO
extends RubyObject

Author:
jpetersen
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.Finalizer, RubyObject.ObjectMethods, RubyObject.VariableTableEntry
 
Field Summary
protected  java.util.List<RubyThread> blockingThreads
           
protected static java.util.concurrent.atomic.AtomicInteger filenoIndex
           
protected  OpenFile openFile
           
 
Fields inherited from class org.jruby.RubyObject
ALL_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, metaClass, NEVER, NIL_F, OBJECT_ALLOCATOR, TAINTED_F, UNDEF, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, VARIABLE_TABLE_DEFAULT_CAPACITY, VARIABLE_TABLE_EMPTY_TABLE, VARIABLE_TABLE_LOAD_FACTOR, VARIABLE_TABLE_MAXIMUM_CAPACITY, variableTable, variableTableSize, variableTableThreshold
 
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, java.io.OutputStream outputStream)
           
RubyIO(Ruby runtime, RubyClass type)
           
RubyIO(Ruby runtime, ShellLauncher.POpenProcess process, ModeFlags modes)
           
RubyIO(Ruby runtime, STDIO stdio)
           
 
Method Summary
 void addBlockingThread(RubyThread thread)
          Add a thread to the list of blocking threads for this IO.
 IRubyObject binmode()
           
protected  void checkClosed()
          Deprecated. will be removed in 1.2
protected  void checkInitialized()
          Deprecated. will be removed in 1.2
 IRubyObject close_read(ThreadContext context)
           
 IRubyObject close_write(ThreadContext context)
           
 IRubyObject close()
          Closes all open resources for the IO.
protected  IRubyObject close2(Ruby runtime)
           
 RubyBoolean closed_p(ThreadContext context)
          Closes the IO.
static IRubyObject copy_stream(ThreadContext context, IRubyObject recv, IRubyObject stream1, IRubyObject stream2)
           
static RubyClass createIOClass(Ruby runtime)
           
 IRubyObject ctl(Ruby runtime, IRubyObject cmd, IRubyObject arg)
           
 IRubyObject each_byte(ThreadContext context, Block block)
          Invoke a block for each byte.
 RubyIO each_line(ThreadContext context, IRubyObject[] args, Block block)
          Invoke a block for each line.
 RubyBoolean eof_p(ThreadContext context)
           
 IRubyObject fcntl(ThreadContext context, IRubyObject cmd, IRubyObject arg)
           
protected  Stream fdopen(ChannelDescriptor existingDescriptor, ModeFlags modes)
           
 RubyFixnum fileno(ThreadContext context)
           
 RubyIO flush()
          Flushes the IO output stream.
static IRubyObject foreach(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)
          rb_io_s_foreach
 RubyFixnum fsync(ThreadContext context)
           
protected  int fwrite(ByteList buffer)
           
 boolean getBlocking()
           
 IRubyObject getc()
          Read a byte.
 java.nio.channels.Channel getChannel()
           
 ChannelDescriptor getDescriptorByFileno(int aFileno)
           
 Stream getHandler()
           
 java.io.InputStream getInStream()
           
static ModeFlags getIOModes(Ruby runtime, java.lang.String modesString)
           
static int getIOModesIntFromString(Ruby runtime, java.lang.String modesString)
           
 IRubyObject getline(Ruby runtime, ByteList separator)
           
 IRubyObject getlineFast(Ruby runtime, int delim)
           
static int getNewFileno()
           
 OpenFile getOpenFile()
           
protected  OpenFile getOpenFileChecked()
           
 java.io.OutputStream getOutStream()
           
 IRubyObject gets(ThreadContext context, IRubyObject[] args)
          Read a line.
 IRubyObject initialize_copy(IRubyObject original)
          rb_obj_init_copy Initializes this object as a copy of the original, that is the parameter to this object.
 IRubyObject initialize(IRubyObject[] args, Block unusedBlock)
           
protected  void interruptBlockingThreads()
          Fire an IOError in all threads blocking on this IO object
 IRubyObject ioctl(ThreadContext context, IRubyObject[] args)
           
 RubyFixnum lineno_set(ThreadContext context, IRubyObject newLineNumber)
          Sets the current line number.
 RubyFixnum lineno(ThreadContext context)
          Returns the current line number.
static IRubyObject newInstance(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)
           
static RubyIO newIO(Ruby runtime, java.nio.channels.Channel channel)
           
 IRubyObject op_append(ThreadContext context, IRubyObject anObject)
          rb_io_addstr
static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)
           
 IRubyObject pid(ThreadContext context)
          Return the process id (pid) of the process this IO object spawned.
static IRubyObject pipe(ThreadContext context, IRubyObject recv)
           
static IRubyObject popen(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)
           
 RubyFixnum pos_set(ThreadContext context, IRubyObject newPosition)
           
 RubyFixnum pos(ThreadContext context)
           
 IRubyObject print(ThreadContext context, IRubyObject[] args)
          Print some objects to the stream.
 IRubyObject printf(ThreadContext context, IRubyObject[] args)
           
 IRubyObject putc(ThreadContext context, IRubyObject object)
           
 IRubyObject puts(ThreadContext context, IRubyObject[] args)
           
 IRubyObject read_nonblock(ThreadContext context, IRubyObject[] args)
           
 IRubyObject read(IRubyObject[] args)
           
 IRubyObject read(ThreadContext context)
           
 IRubyObject read(ThreadContext context, IRubyObject arg0)
           
 IRubyObject read(ThreadContext context, IRubyObject arg0, IRubyObject arg1)
           
static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)
           
static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObject arg0, Block block)
           
static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1, Block block)
           
static IRubyObject read(ThreadContext context, IRubyObject recv, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block)
           
protected  IRubyObject readAll(IRubyObject buffer)
           
 IRubyObject readchar()
          Read a byte.
 IRubyObject readline(ThreadContext context, IRubyObject[] args)
          Read a line.
 RubyArray readlines(ThreadContext context, IRubyObject[] args)
           
static RubyArray readlines(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)
           
 IRubyObject readpartial(ThreadContext context, IRubyObject[] args)
           
 void registerDescriptor(ChannelDescriptor descriptor)
           
 void removeBlockingThread(RubyThread thread)
          Remove a thread from the list of blocking threads for this IO.
 IRubyObject reopen(ThreadContext context, IRubyObject[] args)
           
 RubyFixnum rewind(ThreadContext context)
           
 RubyFixnum seek(ThreadContext context, IRubyObject arg0)
           
 RubyFixnum seek(ThreadContext context, IRubyObject[] args)
           
 RubyFixnum seek(ThreadContext context, IRubyObject arg0, IRubyObject arg1)
           
static IRubyObject select_static(ThreadContext context, Ruby runtime, IRubyObject[] args)
           
static IRubyObject select(ThreadContext context, IRubyObject recv, IRubyObject[] args)
           
 IRubyObject stat(ThreadContext context)
           
protected  boolean swallow(int term)
           
 IRubyObject sync_set(IRubyObject newSync)
          Sets the current sync mode.
 RubyBoolean sync(ThreadContext context)
          Returns the current sync mode.
 IRubyObject sysread(ThreadContext context, IRubyObject[] args)
           
 RubyFixnum sysseek(ThreadContext context, IRubyObject[] args)
           
 IRubyObject syswrite(ThreadContext context, IRubyObject obj)
           
 RubyIO to_io()
           
 java.lang.String toString()
          The default toString method is just a wrapper that calls the Ruby "to_s" method.
 RubyBoolean tty_p(ThreadContext context)
           
 IRubyObject ungetc(IRubyObject number)
          Pushes char represented by int back onto IOS.
 void unregisterDescriptor(int aFileno)
           
protected  boolean waitReadable(ChannelDescriptor descriptor)
           
protected  boolean waitWritable(ChannelDescriptor descriptor)
           
 IRubyObject write_nonblock(ThreadContext context, IRubyObject obj)
           
protected  void write(ThreadContext context, ByteList byteList)
           
 IRubyObject write(ThreadContext context, IRubyObject obj)
          io_write
 boolean writeDataBuffered()
          Deprecated.  
 
Methods inherited from class org.jruby.RubyObject
addFinalizer, anyToString, as, asJavaString, asString, attachToObjectSpace, callInit, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkFrozen, checkStringType, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToString, convertToType, copySpecialInstanceVariables, createObjectClass, dataGetStruct, dataWrapStruct, display, dup, ensureInstanceVariablesSettable, eql_p, eql, eqlInternal, equal_p, equalInternal, equals, evalUnder, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFlag, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariableList, getInternalVariables, getJavaClass, getMetaClass, getNativeTypeIndex, getRuntime, getSingletonClass, getSingletonClassClone, getType, getVariableCount, getVariableList, getVariableMap, getVariableNameList, hash, hashCode, hasInstanceVariable, hasInternalVariable, hasVariables, id_deprecated, id, infectBy, initialize, inspect, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval, instance_exec, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isRubyVariable, isTaint, isTrue, kind_of_p, makeMetaClass, method, methods, nil_p, op_eqq, op_equal, op_match, private_methods, protected_methods, public_methods, puts, rbClone, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respondsTo, send, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setTaint, singleton_methods, specificEval, specificEval, specificEval, specificEval, specificEval, syncVariables, taint, tainted_p, testFrozen, to_a, to_java, to_s, type_deprecated, type, untaint, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableGetMap, variableTableGetMap, variableTableGetSize, variableTableGetTable, variableTableReadLocked, variableTableRehash, variableTableRemove, variableTableStore, variableTableSync
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

openFile

protected OpenFile openFile

blockingThreads

protected java.util.List<RubyThread> blockingThreads

filenoIndex

protected static java.util.concurrent.atomic.AtomicInteger filenoIndex
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,
              ShellLauncher.POpenProcess process,
              ModeFlags modes)

RubyIO

public RubyIO(Ruby runtime,
              STDIO stdio)
Method Detail

registerDescriptor

public void registerDescriptor(ChannelDescriptor descriptor)

unregisterDescriptor

public void unregisterDescriptor(int aFileno)

getDescriptorByFileno

public ChannelDescriptor getDescriptorByFileno(int aFileno)

getNewFileno

public static int getNewFileno()

newIO

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

getOpenFile

public OpenFile getOpenFile()

getOpenFileChecked

protected OpenFile getOpenFileChecked()

createIOClass

public static RubyClass createIOClass(Ruby runtime)

getOutStream

public java.io.OutputStream getOutStream()

getInStream

public java.io.InputStream getInStream()

getChannel

public java.nio.channels.Channel getChannel()

getHandler

public Stream getHandler()

reopen

public IRubyObject reopen(ThreadContext context,
                          IRubyObject[] args)
                   throws InvalidValueException
Throws:
InvalidValueException

getIOModes

public static ModeFlags getIOModes(Ruby runtime,
                                   java.lang.String modesString)
                            throws InvalidValueException
Throws:
InvalidValueException

getIOModesIntFromString

public static int getIOModesIntFromString(Ruby runtime,
                                          java.lang.String modesString)

getline

public IRubyObject getline(Ruby runtime,
                           ByteList separator)

swallow

protected boolean swallow(int term)
                   throws java.io.IOException,
                          BadDescriptorException
Throws:
java.io.IOException
BadDescriptorException

getlineFast

public IRubyObject getlineFast(Ruby runtime,
                               int delim)
                        throws java.io.IOException,
                               BadDescriptorException
Throws:
java.io.IOException
BadDescriptorException

newInstance

public static IRubyObject newInstance(ThreadContext context,
                                      IRubyObject recv,
                                      IRubyObject[] args,
                                      Block block)

initialize

public IRubyObject initialize(IRubyObject[] args,
                              Block unusedBlock)

fdopen

protected Stream fdopen(ChannelDescriptor existingDescriptor,
                        ModeFlags modes)
                 throws InvalidValueException
Throws:
InvalidValueException

open

public static IRubyObject open(ThreadContext context,
                               IRubyObject recv,
                               IRubyObject[] args,
                               Block block)

binmode

public IRubyObject binmode()

checkInitialized

protected void checkInitialized()
Deprecated. will be removed in 1.2


checkClosed

protected void checkClosed()
Deprecated. will be removed in 1.2


syswrite

public IRubyObject syswrite(ThreadContext context,
                            IRubyObject obj)

write_nonblock

public IRubyObject write_nonblock(ThreadContext context,
                                  IRubyObject obj)

write

public IRubyObject write(ThreadContext context,
                         IRubyObject obj)
io_write


waitWritable

protected boolean waitWritable(ChannelDescriptor descriptor)
                        throws java.io.IOException
Throws:
java.io.IOException

waitReadable

protected boolean waitReadable(ChannelDescriptor descriptor)
                        throws java.io.IOException
Throws:
java.io.IOException

fwrite

protected int fwrite(ByteList buffer)

op_append

public IRubyObject op_append(ThreadContext context,
                             IRubyObject anObject)
rb_io_addstr


fileno

public RubyFixnum fileno(ThreadContext context)

lineno

public RubyFixnum lineno(ThreadContext context)
Returns the current line number.

Returns:
the current line number.

lineno_set

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

Parameters:
newLineNumber - The new line number.

sync

public RubyBoolean sync(ThreadContext context)
Returns the current sync mode.

Returns:
the current sync mode.

pid

public IRubyObject pid(ThreadContext context)

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

writeDataBuffered

public boolean writeDataBuffered()
Deprecated. 

Returns:

pos

public RubyFixnum pos(ThreadContext context)

pos_set

public RubyFixnum pos_set(ThreadContext context,
                          IRubyObject newPosition)

print

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


printf

public IRubyObject printf(ThreadContext context,
                          IRubyObject[] args)

putc

public IRubyObject putc(ThreadContext context,
                        IRubyObject object)

seek

public RubyFixnum seek(ThreadContext context,
                       IRubyObject[] args)

seek

public RubyFixnum seek(ThreadContext context,
                       IRubyObject arg0)

seek

public RubyFixnum seek(ThreadContext context,
                       IRubyObject arg0,
                       IRubyObject arg1)

sysseek

public RubyFixnum sysseek(ThreadContext context,
                          IRubyObject[] args)

rewind

public RubyFixnum rewind(ThreadContext context)

fsync

public RubyFixnum fsync(ThreadContext context)

sync_set

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

Parameters:
newSync - The new sync mode.

eof_p

public RubyBoolean eof_p(ThreadContext context)

tty_p

public RubyBoolean tty_p(ThreadContext context)

initialize_copy

public IRubyObject initialize_copy(IRubyObject original)
Description copied from class: RubyObject
rb_obj_init_copy Initializes this object as a copy of the original, that is the parameter to this object. Will make sure that the argument actually has the same real class as this object. It shouldn't be possible to initialize an object with something totally different.

Overrides:
initialize_copy in class RubyObject

closed_p

public RubyBoolean closed_p(ThreadContext context)
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.

close2

protected IRubyObject close2(Ruby runtime)

close_write

public IRubyObject close_write(ThreadContext context)
                        throws BadDescriptorException
Throws:
BadDescriptorException

close_read

public IRubyObject close_read(ThreadContext context)
                       throws BadDescriptorException
Throws:
BadDescriptorException

flush

public RubyIO flush()
Flushes the IO output stream.

Returns:
The IO.

gets

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


getBlocking

public boolean getBlocking()

fcntl

public IRubyObject fcntl(ThreadContext context,
                         IRubyObject cmd,
                         IRubyObject arg)

ioctl

public IRubyObject ioctl(ThreadContext context,
                         IRubyObject[] args)

ctl

public IRubyObject ctl(Ruby runtime,
                       IRubyObject cmd,
                       IRubyObject arg)

puts

public IRubyObject puts(ThreadContext context,
                        IRubyObject[] args)

write

protected void write(ThreadContext context,
                     ByteList byteList)

readline

public IRubyObject readline(ThreadContext context,
                            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

read_nonblock

public IRubyObject read_nonblock(ThreadContext context,
                                 IRubyObject[] args)

readpartial

public IRubyObject readpartial(ThreadContext context,
                               IRubyObject[] args)

sysread

public IRubyObject sysread(ThreadContext context,
                           IRubyObject[] args)

read

public IRubyObject read(IRubyObject[] args)

read

public IRubyObject read(ThreadContext context)

read

public IRubyObject read(ThreadContext context,
                        IRubyObject arg0)

read

public IRubyObject read(ThreadContext context,
                        IRubyObject arg0,
                        IRubyObject arg1)

readAll

protected IRubyObject readAll(IRubyObject buffer)
                       throws BadDescriptorException,
                              java.io.EOFException,
                              java.io.IOException
Throws:
BadDescriptorException
java.io.EOFException
java.io.IOException

readchar

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


stat

public IRubyObject stat(ThreadContext context)

each_byte

public IRubyObject each_byte(ThreadContext context,
                             Block block)

Invoke a block for each byte.


each_line

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

Invoke a block for each line.


readlines

public RubyArray readlines(ThreadContext context,
                           IRubyObject[] args)

to_io

public RubyIO to_io()

toString

public java.lang.String toString()
Description copied from class: RubyObject
The default toString method is just a wrapper that calls the Ruby "to_s" method.

Overrides:
toString in class RubyObject

foreach

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


select

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

select_static

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

read

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

read

public static IRubyObject read(ThreadContext context,
                               IRubyObject recv,
                               IRubyObject arg0,
                               Block block)

read

public static IRubyObject read(ThreadContext context,
                               IRubyObject recv,
                               IRubyObject arg0,
                               IRubyObject arg1,
                               Block block)

read

public static IRubyObject read(ThreadContext context,
                               IRubyObject recv,
                               IRubyObject arg0,
                               IRubyObject arg1,
                               IRubyObject arg2,
                               Block block)

readlines

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

popen

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

pipe

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

copy_stream

public static IRubyObject copy_stream(ThreadContext context,
                                      IRubyObject recv,
                                      IRubyObject stream1,
                                      IRubyObject stream2)
                               throws java.io.IOException
Throws:
java.io.IOException

addBlockingThread

public void addBlockingThread(RubyThread thread)
Add a thread to the list of blocking threads for this IO.

Parameters:
thread - A thread blocking on this IO

removeBlockingThread

public void removeBlockingThread(RubyThread thread)
Remove a thread from the list of blocking threads for this IO.

Parameters:
thread - A thread blocking on this IO

interruptBlockingThreads

protected void interruptBlockingThreads()
Fire an IOError in all threads blocking on this IO object



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