org.jruby.util.io
Class ChannelStream

java.lang.Object
  extended by org.jruby.util.io.ChannelStream
All Implemented Interfaces:
Finalizable, Stream

public class ChannelStream
extends java.lang.Object
implements Stream, Finalizable

This file implements a seekable IO file.


Field Summary
protected  java.nio.ByteBuffer buffer
           
protected  ModeFlags modes
           
protected  boolean reading
           
protected  boolean sync
           
protected  int ungotc
           
 
Fields inherited from interface org.jruby.util.io.Stream
PARAGRAPH_DELIMETER, PARAGRAPH_SEPARATOR, SEEK_CUR, SEEK_END, SEEK_SET
 
Constructor Summary
ChannelStream(Ruby runtime, ChannelDescriptor descriptor)
           
ChannelStream(Ruby runtime, ChannelDescriptor descriptor, java.io.FileDescriptor fileDescriptor)
           
ChannelStream(Ruby runtime, ChannelDescriptor descriptor, ModeFlags modes)
           
ChannelStream(Ruby runtime, ChannelDescriptor descriptor, ModeFlags modes, java.io.FileDescriptor fileDescriptor)
           
 
Method Summary
 void checkPermissionsSubsetOf(ModeFlags subsetModes)
           
 void checkReadable()
           
 void checkWritable()
           
 void clearerr()
           
 void fclose()
          Close IO handler resources.
static Stream fdopen(Ruby runtime, ChannelDescriptor descriptor, ModeFlags modes)
           
 boolean feof()
          Return true when at end of file (EOF).
 int fflush()
           
 int fgetc()
           
 long fgetpos()
          Get the current position within the file associated with this handler.
 ByteList fgets(ByteList separatorString)
           
 void finalize()
          Ensure close (especially flush) when we're finished with
static Stream fopen(Ruby runtime, java.lang.String path, ModeFlags modes)
           
 void fputc(int c)
           
 ByteList fread(int number)
           
 void freopen(java.lang.String path, ModeFlags modes)
           
 void ftruncate(long newLength)
           
 int fwrite(ByteList string)
           
 ChannelDescriptor getDescriptor()
           
 int getline(ByteList dst, byte terminator)
          An version of read that reads all bytes up to and including a terminator byte.
 ModeFlags getModes()
           
 Ruby getRuntime()
           
 boolean isBlocking()
           
 boolean isSync()
           
 void lseek(long offset, int type)
          Implementation of libc "lseek", which seeks on seekable streams, raises EPIPE if the fd is assocated with a pipe, socket, or FIFO, and doesn't do anything for other cases (like stdio).
 java.io.InputStream newInputStream()
           
 java.io.OutputStream newOutputStream()
           
 int read()
           
 ByteList read(int number)
           
 ByteList readall()
           
 boolean readDataBuffered()
           
 ByteList readnonblock(int number)
           
 ByteList readpartial(int number)
           
 int ready()
          Implement IO#ready? as per io/wait in MRI.
 void setBlocking(boolean block)
           
 void setSync(boolean sync)
           
 void sync()
          Flush and sync all writes to the filesystem.
 int ungetc(int c)
           
 void waitUntilReady()
          Implement IO#wait as per io/wait in MRI.
 boolean writeDataBuffered()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

modes

protected ModeFlags modes

sync

protected boolean sync

buffer

protected volatile java.nio.ByteBuffer buffer

reading

protected boolean reading

ungotc

protected int ungotc
Constructor Detail

ChannelStream

public ChannelStream(Ruby runtime,
                     ChannelDescriptor descriptor,
                     ModeFlags modes,
                     java.io.FileDescriptor fileDescriptor)
              throws InvalidValueException
Throws:
InvalidValueException

ChannelStream

public ChannelStream(Ruby runtime,
                     ChannelDescriptor descriptor)

ChannelStream

public ChannelStream(Ruby runtime,
                     ChannelDescriptor descriptor,
                     java.io.FileDescriptor fileDescriptor)

ChannelStream

public ChannelStream(Ruby runtime,
                     ChannelDescriptor descriptor,
                     ModeFlags modes)
              throws InvalidValueException
Throws:
InvalidValueException
Method Detail

getRuntime

public Ruby getRuntime()

checkReadable

public void checkReadable()
                   throws java.io.IOException
Throws:
java.io.IOException

checkWritable

public void checkWritable()
                   throws java.io.IOException
Throws:
java.io.IOException

checkPermissionsSubsetOf

public void checkPermissionsSubsetOf(ModeFlags subsetModes)

getModes

public ModeFlags getModes()
Specified by:
getModes in interface Stream

isSync

public boolean isSync()
Specified by:
isSync in interface Stream

setSync

public void setSync(boolean sync)
Specified by:
setSync in interface Stream

waitUntilReady

public void waitUntilReady()
                    throws java.io.IOException,
                           java.lang.InterruptedException
Implement IO#wait as per io/wait in MRI. waits until input available or timed out and returns self, or nil when EOF reached. The default implementation loops while ready returns 0.

Specified by:
waitUntilReady in interface Stream
Throws:
java.io.IOException
java.lang.InterruptedException

readDataBuffered

public boolean readDataBuffered()
Specified by:
readDataBuffered in interface Stream

writeDataBuffered

public boolean writeDataBuffered()
Specified by:
writeDataBuffered in interface Stream

fgets

public ByteList fgets(ByteList separatorString)
               throws java.io.IOException,
                      BadDescriptorException
Specified by:
fgets in interface Stream
Throws:
java.io.IOException
BadDescriptorException

getline

public int getline(ByteList dst,
                   byte terminator)
            throws java.io.IOException,
                   BadDescriptorException
An version of read that reads all bytes up to and including a terminator byte.

If the terminator byte is found, it will be the last byte in the output buffer.

Specified by:
getline in interface Stream
Parameters:
dst - The output buffer.
terminator - The byte to terminate reading.
Returns:
The number of bytes read, or -1 if EOF is reached.
Throws:
java.io.IOException
BadDescriptorException

readall

public ByteList readall()
                 throws java.io.IOException,
                        BadDescriptorException
Specified by:
readall in interface Stream
Throws:
java.io.IOException
BadDescriptorException

fclose

public void fclose()
            throws java.io.IOException,
                   BadDescriptorException

Close IO handler resources.

Specified by:
fclose in interface Stream
Throws:
java.io.IOException
BadDescriptorException
See Also:
org.jruby.util.IOHandler#close()

fflush

public int fflush()
           throws java.io.IOException,
                  BadDescriptorException
Specified by:
fflush in interface Stream
Throws:
java.io.IOException
BadDescriptorException
See Also:
org.jruby.util.IOHandler#flush()

newInputStream

public java.io.InputStream newInputStream()
Specified by:
newInputStream in interface Stream
See Also:
org.jruby.util.IOHandler#getInputStream()

newOutputStream

public java.io.OutputStream newOutputStream()
Specified by:
newOutputStream in interface Stream
See Also:
org.jruby.util.IOHandler#getOutputStream()

clearerr

public void clearerr()
Specified by:
clearerr in interface Stream

feof

public boolean feof()
             throws java.io.IOException,
                    BadDescriptorException
Description copied from interface: Stream

Return true when at end of file (EOF).

Specified by:
feof in interface Stream
Returns:
true if at EOF; false otherwise
Throws:
java.io.IOException
BadDescriptorException
See Also:
org.jruby.util.IOHandler#isEOF()

fgetpos

public long fgetpos()
             throws java.io.IOException,
                    PipeException,
                    InvalidValueException,
                    BadDescriptorException
Description copied from interface: Stream

Get the current position within the file associated with this handler.

Specified by:
fgetpos in interface Stream
Returns:
the current position in the file.
Throws:
java.io.IOException
PipeException - ESPIPE (illegal seek) when not a file
InvalidValueException
BadDescriptorException
See Also:
org.jruby.util.IOHandler#pos()

lseek

public void lseek(long offset,
                  int type)
           throws java.io.IOException,
                  InvalidValueException,
                  PipeException,
                  BadDescriptorException
Implementation of libc "lseek", which seeks on seekable streams, raises EPIPE if the fd is assocated with a pipe, socket, or FIFO, and doesn't do anything for other cases (like stdio).

Specified by:
lseek in interface Stream
Throws:
java.io.IOException
InvalidValueException
PipeException
BadDescriptorException
See Also:
org.jruby.util.IOHandler#seek(long, int)

sync

public void sync()
          throws java.io.IOException,
                 BadDescriptorException
Description copied from interface: Stream

Flush and sync all writes to the filesystem.

Specified by:
sync in interface Stream
Throws:
java.io.IOException - if the sync does not work
BadDescriptorException
See Also:
org.jruby.util.IOHandler#sync()

read

public ByteList read(int number)
              throws java.io.IOException,
                     BadDescriptorException
Specified by:
read in interface Stream
Throws:
java.io.IOException
BadDescriptorException

ftruncate

public void ftruncate(long newLength)
               throws java.io.IOException,
                      BadDescriptorException,
                      InvalidValueException
Specified by:
ftruncate in interface Stream
Throws:
java.io.IOException
BadDescriptorException
InvalidValueException

finalize

public void finalize()
Ensure close (especially flush) when we're finished with

Specified by:
finalize in interface Finalizable
Overrides:
finalize in class java.lang.Object

ready

public int ready()
          throws java.io.IOException
Description copied from interface: Stream
Implement IO#ready? as per io/wait in MRI. returns non-nil if input available without blocking, or nil.

Specified by:
ready in interface Stream
Throws:
java.io.IOException

fputc

public void fputc(int c)
           throws java.io.IOException,
                  BadDescriptorException
Specified by:
fputc in interface Stream
Throws:
java.io.IOException
BadDescriptorException

ungetc

public int ungetc(int c)
Specified by:
ungetc in interface Stream

fgetc

public int fgetc()
          throws java.io.IOException,
                 BadDescriptorException
Specified by:
fgetc in interface Stream
Throws:
java.io.IOException
BadDescriptorException

fwrite

public int fwrite(ByteList string)
           throws java.io.IOException,
                  BadDescriptorException
Specified by:
fwrite in interface Stream
Throws:
java.io.IOException
BadDescriptorException

fread

public ByteList fread(int number)
               throws java.io.IOException,
                      BadDescriptorException
Specified by:
fread in interface Stream
Throws:
java.io.IOException
BadDescriptorException

readnonblock

public ByteList readnonblock(int number)
                      throws java.io.IOException,
                             BadDescriptorException,
                             java.io.EOFException
Throws:
java.io.IOException
BadDescriptorException
java.io.EOFException

readpartial

public ByteList readpartial(int number)
                     throws java.io.IOException,
                            BadDescriptorException,
                            java.io.EOFException
Throws:
java.io.IOException
BadDescriptorException
java.io.EOFException

read

public int read()
         throws java.io.IOException,
                BadDescriptorException
Throws:
java.io.IOException
BadDescriptorException

getDescriptor

public ChannelDescriptor getDescriptor()
Specified by:
getDescriptor in interface Stream

setBlocking

public void setBlocking(boolean block)
                 throws java.io.IOException
Specified by:
setBlocking in interface Stream
Throws:
java.io.IOException

isBlocking

public boolean isBlocking()
Specified by:
isBlocking in interface Stream

freopen

public void freopen(java.lang.String path,
                    ModeFlags modes)
             throws DirectoryAsFileException,
                    java.io.IOException,
                    InvalidValueException,
                    PipeException,
                    BadDescriptorException
Specified by:
freopen in interface Stream
Throws:
DirectoryAsFileException
java.io.IOException
InvalidValueException
PipeException
BadDescriptorException

fopen

public static Stream fopen(Ruby runtime,
                           java.lang.String path,
                           ModeFlags modes)
                    throws java.io.FileNotFoundException,
                           DirectoryAsFileException,
                           FileExistsException,
                           java.io.IOException,
                           InvalidValueException,
                           PipeException,
                           BadDescriptorException
Throws:
java.io.FileNotFoundException
DirectoryAsFileException
FileExistsException
java.io.IOException
InvalidValueException
PipeException
BadDescriptorException

fdopen

public static Stream fdopen(Ruby runtime,
                            ChannelDescriptor descriptor,
                            ModeFlags modes)
                     throws InvalidValueException
Throws:
InvalidValueException


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