com.caucho.quercus.lib.file
Class FileInputOutput

java.lang.Object
  extended by java.io.OutputStream
      extended by com.caucho.quercus.lib.file.AbstractBinaryOutput
          extended by com.caucho.quercus.lib.file.FileInputOutput
All Implemented Interfaces:
EnvCleanup, BinaryInput, BinaryOutput, BinaryStream, LockableStream, java.io.Closeable, java.io.Flushable

public class FileInputOutput
extends AbstractBinaryOutput
implements BinaryInput, BinaryOutput, LockableStream, EnvCleanup

Represents a PHP open file


Field Summary
 
Fields inherited from interface com.caucho.quercus.lib.file.BinaryStream
SEEK_CUR, SEEK_END, SEEK_SET
 
Constructor Summary
FileInputOutput(Env env, Path path)
           
FileInputOutput(Env env, Path path, boolean append, boolean truncate)
           
FileInputOutput(Env env, Path path, boolean append, boolean truncate, boolean temporary)
           
 
Method Summary
 StringValue appendTo(StringValue builder)
          Appends to a string builder.
 void cleanup()
          Implements the EnvCleanup interface.
 void close()
          Closes the file.
 void closeRead()
          Closes the file for reading.
 void closeWrite()
          Closes the file for writing.
 void flush()
          Flushes the output.
 java.io.InputStream getInputStream()
          Returns the read stream.
 java.io.OutputStream getOutputStream()
          Returns the write stream.
 Path getPath()
          Returns the path.
 long getPosition()
          Returns the current location in the file.
 boolean isEOF()
          Returns true on the EOF.
 boolean lock(boolean shared, boolean block)
          Lock the shared advisory lock.
 BinaryInput openCopy()
          Opens a copy.
 void print(char v)
          Prints a string to a file.
 void print(java.lang.String v)
          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.
 int read(char[] buffer, int offset, int length)
          Reads a buffer from a file, returning -1 on EOF.
 StringValue read(int length)
          Reads a Binary string.
 StringValue readLine(long length)
          Reads a line from the buffer.
 boolean readOptionalLinefeed()
          Reads the optional linefeed character from a \r\n
 long seek(long offset, int whence)
          Seek according to offset and whence.
 void setEncoding(java.lang.String encoding)
          Sets the current read encoding.
 boolean setPosition(long offset)
          Sets the current location in the stream
 Value stat()
          Returns an array filled with stat information.
 java.lang.String toString()
          Converts to a string.
 boolean unlock()
          Unlock the advisory lock.
 void unread()
          Unread a character.
 void write(byte[] buffer, int offset, int length)
          Writes a buffer to a file.
 void write(int ch)
          Writes a buffer to a file.
 
Methods inherited from class com.caucho.quercus.lib.file.AbstractBinaryOutput
getResourceType, write
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.caucho.quercus.lib.file.BinaryOutput
write
 

Constructor Detail

FileInputOutput

public FileInputOutput(Env env,
                       Path path)
                throws java.io.IOException
Throws:
java.io.IOException

FileInputOutput

public FileInputOutput(Env env,
                       Path path,
                       boolean append,
                       boolean truncate)
                throws java.io.IOException
Throws:
java.io.IOException

FileInputOutput

public FileInputOutput(Env env,
                       Path path,
                       boolean append,
                       boolean truncate,
                       boolean temporary)
                throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getOutputStream

public java.io.OutputStream getOutputStream()
Returns the write stream.

Specified by:
getOutputStream in interface BinaryOutput
Overrides:
getOutputStream in class AbstractBinaryOutput

getInputStream

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

Specified by:
getInputStream in interface BinaryInput

getPath

public Path getPath()
Returns the path.


setEncoding

public void setEncoding(java.lang.String encoding)
                 throws java.io.UnsupportedEncodingException
Sets the current read encoding. The encoding can either be a Java encoding name or a mime encoding.

Parameters:
encoding - name of the read encoding
Throws:
java.io.UnsupportedEncodingException

unread

public void unread()
            throws java.io.IOException
Unread a character.

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 int read(char[] buffer,
                int offset,
                int length)
         throws java.io.IOException
Reads a buffer from a file, returning -1 on EOF.

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

read

public StringValue read(int length)
                 throws java.io.IOException
Reads a Binary string.

Specified by:
read 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

readLine

public StringValue readLine(long length)
                     throws java.io.IOException
Reads a line from the buffer.

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

isEOF

public boolean isEOF()
Returns true on the EOF.

Specified by:
isEOF in interface BinaryStream
Overrides:
isEOF in class AbstractBinaryOutput

print

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

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

print

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

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

write

public void write(byte[] buffer,
                  int offset,
                  int length)
           throws java.io.IOException
Writes a buffer to a file.

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

write

public void write(int ch)
           throws java.io.IOException
Writes a buffer to a file.

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

flush

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

Specified by:
flush in interface BinaryOutput
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class AbstractBinaryOutput
Throws:
java.io.IOException

closeWrite

public void closeWrite()
Closes the file for writing.

Specified by:
closeWrite in interface BinaryOutput
Overrides:
closeWrite in class AbstractBinaryOutput

closeRead

public void closeRead()
Closes the file for reading.

Specified by:
closeRead in interface BinaryInput

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
Specified by:
close in interface java.io.Closeable
Overrides:
close in class AbstractBinaryOutput

cleanup

public void cleanup()
Implements the EnvCleanup interface.

Specified by:
cleanup in interface EnvCleanup

getPosition

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

Specified by:
getPosition in interface BinaryInput
Specified by:
getPosition in interface BinaryStream
Overrides:
getPosition in class AbstractBinaryOutput

setPosition

public boolean setPosition(long offset)
Sets the current location in the stream

Specified by:
setPosition in interface BinaryInput
Specified by:
setPosition in interface BinaryStream
Overrides:
setPosition in class AbstractBinaryOutput

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
Overrides:
seek in class AbstractBinaryOutput

openCopy

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

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

lock

public boolean lock(boolean shared,
                    boolean block)
Lock the shared advisory lock.

Specified by:
lock in interface LockableStream

unlock

public boolean unlock()
Unlock the advisory lock.

Specified by:
unlock in interface LockableStream

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
Overrides:
stat in class AbstractBinaryOutput

toString

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

Overrides:
toString in class java.lang.Object
Parameters:
env -