com.caucho.vfs
Class JniFileStream

java.lang.Object
  extended by com.caucho.vfs.StreamImpl
      extended by com.caucho.vfs.JniFileStream
All Implemented Interfaces:
LockableStream

public class JniFileStream
extends StreamImpl
implements LockableStream

Stream using with JNI.


Field Summary
 
Fields inherited from class com.caucho.vfs.StreamImpl
_nullPath, _path
 
Constructor Summary
JniFileStream(int fd, boolean canRead, boolean canWrite)
          Create a new JniStream based on the java.io.* stream.
 
Method Summary
 boolean canRead()
          Returns true if this is a read stream.
 boolean canWrite()
          Returns true if this is a writeable stream.
 void close()
          Closes the stream.
protected  void finalize()
           
 void flush()
          Flushes the write output.
 void flushToDisk()
          Flushes the write output, forcing to disk.
 int getAvailable()
          Returns the number of bytes available without blocking.
static java.lang.Throwable getDisableCause()
           
 boolean hasSkip()
          Returns true if the stream implements skip.
static boolean isEnabled()
           
 boolean lock(boolean shared, boolean block)
          Implement LockableStream as a no-op, but maintain compatibility with FileWriteStream and FileReadStream wrt returning false to indicate error case.
static JniFileStream openRead(byte[] name, int length)
           
static JniFileStream openWrite(byte[] name, int length, boolean isAppend)
           
 int read(byte[] buf, int offset, int length)
          Reads data from the file.
 void seekEnd(long offset)
          Seeks based on the end.
 void seekStart(long offset)
          Seeks based on the start.
 long skip(long length)
          Skips a number of bytes, returning the bytes skipped.
 java.lang.String toString()
          Returns the debug name for the stream.
 boolean unlock()
          Unlock the advisory lock.
 void write(byte[] buf, int offset, int length, boolean isEnd)
          Writes data to the file.
 
Methods inherited from class com.caucho.vfs.StreamImpl
clearWrite, closeWrite, flushBuffer, getAttribute, getAttributeNames, getFlushOnNewline, getNewline, getPath, getReadBuffer, getReadPosition, isClosed, isEof, readNonBlock, readTimeout, removeAttribute, setAttribute, setPath, setWriteEncoding, write
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JniFileStream

public JniFileStream(int fd,
                     boolean canRead,
                     boolean canWrite)
Create a new JniStream based on the java.io.* stream.

Method Detail

isEnabled

public static boolean isEnabled()

getDisableCause

public static java.lang.Throwable getDisableCause()

openRead

public static JniFileStream openRead(byte[] name,
                                     int length)

openWrite

public static JniFileStream openWrite(byte[] name,
                                      int length,
                                      boolean isAppend)

canRead

public boolean canRead()
Description copied from class: StreamImpl
Returns true if this is a read stream.

Overrides:
canRead in class StreamImpl

hasSkip

public boolean hasSkip()
Description copied from class: StreamImpl
Returns true if the stream implements skip.

Overrides:
hasSkip in class StreamImpl

skip

public long skip(long length)
          throws java.io.IOException
Description copied from class: StreamImpl
Skips a number of bytes, returning the bytes skipped.

Overrides:
skip in class StreamImpl
Parameters:
length - the number of types to skip.
Returns:
the actual bytes skipped.
Throws:
java.io.IOException

read

public int read(byte[] buf,
                int offset,
                int length)
         throws java.io.IOException
Reads data from the file.

Overrides:
read in class StreamImpl
Parameters:
buf - byte array receiving the data.
offset - starting offset into the array.
length - number of bytes to read.
Returns:
the number of bytes read or -1 on end of file.
Throws:
java.io.IOException

getAvailable

public int getAvailable()
                 throws java.io.IOException
Description copied from class: StreamImpl
Returns the number of bytes available without blocking. Depending on the stream, this may return less than the actual bytes, but will always return a number > 0 if there is any data available.

Overrides:
getAvailable in class StreamImpl
Throws:
java.io.IOException

canWrite

public boolean canWrite()
Returns true if this is a writeable stream.

Overrides:
canWrite in class StreamImpl

write

public void write(byte[] buf,
                  int offset,
                  int length,
                  boolean isEnd)
           throws java.io.IOException
Writes data to the file.

Overrides:
write in class StreamImpl
Parameters:
buf - the byte array to write.
offset - the offset into the byte array.
length - the number of bytes to write.
isEnd - true when the write is flushing a close.
Throws:
java.io.IOException

seekStart

public void seekStart(long offset)
               throws java.io.IOException
Description copied from class: StreamImpl
Seeks based on the start.

Overrides:
seekStart in class StreamImpl
Throws:
java.io.IOException

seekEnd

public void seekEnd(long offset)
             throws java.io.IOException
Description copied from class: StreamImpl
Seeks based on the end.

Overrides:
seekEnd in class StreamImpl
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Description copied from class: StreamImpl
Flushes the write output.

Overrides:
flush in class StreamImpl
Throws:
java.io.IOException

flushToDisk

public void flushToDisk()
                 throws java.io.IOException
Description copied from class: StreamImpl
Flushes the write output, forcing to disk.

Overrides:
flushToDisk in class StreamImpl
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Description copied from class: StreamImpl
Closes the stream.

Overrides:
close in class StreamImpl
Throws:
java.io.IOException

finalize

protected void finalize()
                 throws java.io.IOException
Overrides:
finalize in class java.lang.Object
Throws:
java.io.IOException

lock

public boolean lock(boolean shared,
                    boolean block)
Implement LockableStream as a no-op, but maintain compatibility with FileWriteStream and FileReadStream wrt returning false to indicate error case.

Specified by:
lock in interface LockableStream

unlock

public boolean unlock()
Description copied from interface: LockableStream
Unlock the advisory lock. Return true if a lock was held, false otherwise.

Specified by:
unlock in interface LockableStream

toString

public java.lang.String toString()
Returns the debug name for the stream.

Overrides:
toString in class java.lang.Object