org.entityfs.util
Class FileWritableFile

java.lang.Object
  extended by org.entityfs.util.base.AbstractWritableFile
      extended by org.entityfs.util.FileWritableFile
All Implemented Interfaces:
Lockable, WriteLockable, WritableFile

public class FileWritableFile
extends AbstractWritableFile

This is a WritableFile that encapsulates a File

The locking methods return a NoObjectDummyLock.

Since:
1.1.3
Author:
Karl Gustafsson
See Also:
FileReadableFile

Constructor Summary
FileWritableFile(File f)
           
 
Method Summary
 boolean equals(Object o)
           
 File getFile()
          Get the encapsulated File object.
 int hashCode()
           
 WritableByteChannel openChannelForAppend()
          This method opens a byte channel on the OutputStream returned from openForAppend.
 WritableByteChannel openChannelForWrite()
          This method opens a byte channel on the OutputStream returned from openForWrite.
 OutputStream openForAppend()
          Open the file for appending.
 OutputStream openForWrite()
          Opens the file for writing.
 String toString()
           
 
Methods inherited from class org.entityfs.util.base.AbstractWritableFile
getWriteLock, isWriteLockedByCurrentThread, lockForWriting
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileWritableFile

public FileWritableFile(File f)
Method Detail

getFile

public File getFile()
Get the encapsulated File object.

Returns:
The encapsulated File object.
Since:
1.1.4

openChannelForAppend

public WritableByteChannel openChannelForAppend()
                                         throws WrappedIOException
Description copied from class: AbstractWritableFile
This method opens a byte channel on the OutputStream returned from openForAppend.

Specified by:
openChannelForAppend in interface WritableFile
Overrides:
openChannelForAppend in class AbstractWritableFile
Returns:
An open WritableByteChannel. The channel must be closed by the caller. The returned channel may be a GatheringByteChannel, but that is not required.
Throws:
WrappedIOException

openChannelForWrite

public WritableByteChannel openChannelForWrite()
                                        throws WrappedIOException
Description copied from class: AbstractWritableFile
This method opens a byte channel on the OutputStream returned from openForWrite.

Specified by:
openChannelForWrite in interface WritableFile
Overrides:
openChannelForWrite in class AbstractWritableFile
Returns:
An open WritableByteChannel. The channel must be closed by the caller. The returned channel may be a GatheringByteChannel, but that is not required.
Throws:
WrappedIOException
See Also:
WritableFile.openForWrite(), WritableFile.openChannelForAppend()

openForAppend

public OutputStream openForAppend()
                           throws WrappedIOException
Description copied from interface: WritableFile
Open the file for appending. This preserves all previous contents of the file. Use WritableFile.openForWrite() to delete the previous contents before writing. This requires that the file supports the FCAppendable capability (and/or that the file system supports the FSCAppendableFiles capability.

The caller is responsible for closing the stream.

When two appending output streams are open on the same file, one stream will not overwrite contents written by the other stream. Compare this with the behavior of one writing and one appending stream.

Although a write lock on the file is required for the execution thread opening the stream, the stream itself is not protected from access by other threads. It can be protected by wrapping it in a LockAwareWritableByteChannel.

Returns:
An OutputStream to write to. The stream must be closed by the caller.
Throws:
WrappedIOException
See Also:
WritableFile.openForWrite(), WritableFile.openChannelForAppend()

openForWrite

public OutputStream openForWrite()
                          throws WriteLockRequiredException,
                                 AccessDeniedException,
                                 ReadOnlyException
Description copied from interface: WritableFile
Opens the file for writing. This deletes all previous contents of the file. Use WritableFile.openForAppend() to append to the file.

The caller is responsible for closing the stream.

When two output streams, one writing and one appending are open on the same file, the stream opened for write will ignore the contents written by the other stream and the content written by the other stream will be overwritten. When two or more appending streams are opened on a file, a stream will not overwrite the content written by the other streams.

Although a write lock on the file is required for the execution thread opening the stream, the stream itself is not protected from access by other threads. It can be protected by wrapping it in a LockAwareOutputStream.

Returns:
An OutputStream to write to. The stream must be closed by the caller.
Throws:
WriteLockRequiredException - If the client does not have a write lock for the file.
AccessDeniedException - If the client does not have write access to the file.
ReadOnlyException - If the file system is read-only.
See Also:
WritableFile.openForAppend(), WritableFile.openChannelForWrite()

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object