com.caucho.quercus.lib.file
Class AbstractBinaryInputOutput

java.lang.Object
  extended by com.caucho.quercus.lib.file.AbstractBinaryInputOutput
All Implemented Interfaces:
BinaryInput, BinaryOutput, BinaryStream
Direct Known Subclasses:
BufferedBinaryInputOutput, UdpInputOutput

public abstract class AbstractBinaryInputOutput
extends java.lang.Object
implements BinaryInput, BinaryOutput

Represents a Quercus file open for reading


Field Summary
protected  Env _env
           
protected  boolean _isEOF
           
protected  boolean _isTimeout
           
protected  LineReader _lineReader
           
 
Fields inherited from interface com.caucho.quercus.lib.file.BinaryStream
SEEK_CUR, SEEK_END, SEEK_SET
 
Constructor Summary
protected AbstractBinaryInputOutput(Env env)
           
 
Method Summary
 StringValue appendTo(StringValue builder)
          Appends to a string builder.
 void close()
          Closes the file.
 void closeRead()
          Closes the stream for reading.
 void closeWrite()
          Closes the file.
 void flush()
          Flushes the output.
protected  Env getEnv()
           
 java.io.InputStream getInputStream()
          Returns the input stream.
 java.io.OutputStream getOutputStream()
          Returns self as the output stream.
abstract  long getPosition()
          Returns the current location in the file.
 java.lang.String getResourceType()
           
 void init(java.io.InputStream is, java.io.OutputStream os)
           
 boolean isEOF()
          Returns true on the EOF.
 boolean isTimeout()
          Returns true on the EOF.
 BinaryInput openCopy()
          Opens a copy.
 void print(char v)
          Prints a string to a file.
 void print(java.lang.String s)
          Prints a string to a file.
 int read()
          Reads a character from a file, returning -1 on EOF.
 int read(byte[] buffer, int offset, int length)
          Reads a buffer from a file, returning -1 on EOF.
 StringValue read(int length)
          Reads into a binary builder.
 StringValue readLine(long length)
          Reads a line from a file, returning null on EOF.
 boolean readOptionalLinefeed()
          Reads the optional linefeed character from a \r\n
 long seek(long offset, int whence)
          Seek according to offset and whence.
abstract  boolean setPosition(long offset)
          Sets the current location in the file.
 void setTimeout(long timeout)
           
 Value stat()
          Returns an array filled with stat information.
 java.lang.Object toJavaObject()
           
 java.lang.String toString()
          Converts to a string.
abstract  void unread()
          Unread the last byte.
 void write(byte[] buffer, int offset, int length)
          Writes a buffer.
 int write(java.io.InputStream is, int length)
          Read length bytes of data from the InputStream argument and write them to this output stream.
 void write(int ch)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_env

protected final Env _env

_lineReader

protected final LineReader _lineReader

_isTimeout

protected boolean _isTimeout

_isEOF

protected boolean _isEOF
Constructor Detail

AbstractBinaryInputOutput

protected AbstractBinaryInputOutput(Env env)
Method Detail

init

public void init(java.io.InputStream is,
                 java.io.OutputStream os)

getInputStream

public java.io.InputStream getInputStream()
Returns the input stream.

Specified by:
getInputStream in interface BinaryInput

openCopy

public BinaryInput openCopy()
                     throws java.io.IOException
Opens a copy.

Specified by:
openCopy in interface BinaryInput
Throws:
java.io.IOException

unread

public abstract void unread()
                     throws java.io.IOException
Unread the last byte.

Specified by:
unread in interface BinaryInput
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Reads a character from a file, returning -1 on EOF.

Specified by:
read in interface BinaryInput
Throws:
java.io.IOException

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws java.io.IOException
Reads a buffer from a file, returning -1 on EOF.

Specified by:
read in interface BinaryInput
Throws:
java.io.IOException

read

public StringValue read(int length)
                 throws java.io.IOException
Reads into a binary builder.

Specified by:
read in interface BinaryInput
Throws:
java.io.IOException

readLine

public StringValue readLine(long length)
                     throws java.io.IOException
Reads a line from a file, returning null on EOF.

Specified by:
readLine in interface BinaryInput
Throws:
java.io.IOException

readOptionalLinefeed

public boolean readOptionalLinefeed()
                             throws java.io.IOException
Reads the optional linefeed character from a \r\n

Specified by:
readOptionalLinefeed in interface BinaryInput
Throws:
java.io.IOException

appendTo

public StringValue appendTo(StringValue builder)
                     throws java.io.IOException
Appends to a string builder.

Specified by:
appendTo in interface BinaryInput
Throws:
java.io.IOException

isEOF

public boolean isEOF()
Returns true on the EOF.

Specified by:
isEOF in interface BinaryStream

isTimeout

public boolean isTimeout()
Returns true on the EOF.


getPosition

public abstract long getPosition()
Returns the current location in the file.

Specified by:
getPosition in interface BinaryInput
Specified by:
getPosition in interface BinaryStream

setPosition

public abstract boolean setPosition(long offset)
Sets the current location in the file.

Specified by:
setPosition in interface BinaryInput
Specified by:
setPosition in interface BinaryStream

seek

public long seek(long offset,
                 int whence)
Description copied from interface: BinaryStream
Seek according to offset and whence. For fseek() compatibility in wrapped streams.

Specified by:
seek in interface BinaryStream

stat

public Value stat()
Description copied from interface: BinaryStream
Returns an array filled with stat information. Mainly for wrapped stream functionality.

Specified by:
stat in interface BinaryStream

closeRead

public void closeRead()
Closes the stream for reading. The isEOF method will return true after this method has been invoked.

Specified by:
closeRead in interface BinaryInput

getOutputStream

public java.io.OutputStream getOutputStream()
Returns self as the output stream.

Specified by:
getOutputStream in interface BinaryOutput

write

public void write(int ch)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] buffer,
                  int offset,
                  int length)
           throws java.io.IOException
Description copied from interface: BinaryOutput
Writes a buffer.

Specified by:
write in interface BinaryOutput
Throws:
java.io.IOException

write

public int write(java.io.InputStream is,
                 int length)
          throws java.io.IOException
Read length bytes of data from the InputStream argument and write them to this output stream.

Specified by:
write in interface BinaryOutput
Throws:
java.io.IOException

print

public void print(char v)
           throws java.io.IOException
Prints a string to a file.

Specified by:
print in interface BinaryOutput
Throws:
java.io.IOException

print

public void print(java.lang.String s)
           throws java.io.IOException
Prints a string to a file.

Specified by:
print in interface BinaryOutput
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flushes the output.

Specified by:
flush in interface BinaryOutput
Throws:
java.io.IOException

closeWrite

public void closeWrite()
Closes the file.

Specified by:
closeWrite in interface BinaryOutput

close

public void close()
Closes the file.

Specified by:
close in interface BinaryInput
Specified by:
close in interface BinaryOutput
Specified by:
close in interface BinaryStream

toJavaObject

public java.lang.Object toJavaObject()

setTimeout

public void setTimeout(long timeout)

getResourceType

public java.lang.String getResourceType()

getEnv

protected Env getEnv()

toString

public java.lang.String toString()
Converts to a string.

Overrides:
toString in class java.lang.Object