org.entityfs
Interface ReadWritableFile

All Superinterfaces:
Deletable, Lockable, RandomlyAccessibleFile, ReadableFile, ReadLockable, ReadWriteLockable, WritableFile, WriteLockable
All Known Subinterfaces:
EFile
All Known Implementing Classes:
AbstractReadWritableFile, ReadWritableFileAdapter

public interface ReadWritableFile
extends ReadableFile, WritableFile, RandomlyAccessibleFile, Deletable

This is a combination of the ReadableFile, WritableFile and RandomlyAccessibleFile interfaces. I.e., the most of that which makes a file a file, except for its entity properties such as its location in a file system.

This interface can be used to represent a file when its location is not important.

Since:
1.0
Author:
Karl Gustafsson

Method Summary
 long copy(OutputStream os)
          Dump the file contents to the stream.
 long copy(WritableByteChannel c)
          Copy the file's contents to the WritableByteChannel.
 long getSizeNoLocking()
          Get an approximate size of the file without having to lock it.
 void replaceContents(ReadWritableFile f)
          Replace the contents of this file with the contents of the supplied file and then delete the supplied file.
 
Methods inherited from interface org.entityfs.ReadableFile
getDataSize, getSize, openChannelForRead, openForRead
 
Methods inherited from interface org.entityfs.WritableFile
openChannelForAppend, openChannelForWrite, openForAppend, openForWrite
 
Methods inherited from interface org.entityfs.RandomlyAccessibleFile
openForRandomAccess
 
Methods inherited from interface org.entityfs.lock.ReadLockable
getReadLock, isReadLockedByCurrentThread, lockForReading
 
Methods inherited from interface org.entityfs.lock.WriteLockable
getWriteLock, isWriteLockedByCurrentThread, lockForWriting
 
Methods inherited from interface org.entityfs.Deletable
delete, isDeleted
 

Method Detail

replaceContents

void replaceContents(ReadWritableFile f)
                     throws WriteLockRequiredException,
                            AccessDeniedException,
                            ReadOnlyException,
                            IllegalArgumentException
Replace the contents of this file with the contents of the supplied file and then delete the supplied file. If both files are in the same file system, an optimized implementation simply moves the contents of f over to this file, which makes the entire operation quick and not requiring any extra disk space.

If both files support metadata, this file's metadata is replaced with that of f.

Parameters:
f - The file whose contents are to be moved to this file. f is deleted by this method.
Throws:
WriteLockRequiredException - If the client does not have write locks for this file, this file's parent directory, f and f's parent directory.
AccessDeniedException - If the client does not have write access to this file, this file's parent directory, f or f's parent directory.
ReadOnlyException - If this file or f is read only.
IllegalArgumentException - If the supplied file is not in the same file system as this file.
Locks_required:
A write lock on this file, this file's parent directory, on f and f's parent directory.
Permissions_required:
Write access to this file, this file's parent directory, to f and f's parent directory.

getSizeNoLocking

long getSizeNoLocking()
Get an approximate size of the file without having to lock it.

Returns:
The approximate size of the file, in bytes. If the file object is invalid, 0 is returned.
See Also:
ReadableFile.getSize()
Locks_required:
None
Permissions_required:
None

copy

long copy(OutputStream os)
          throws ReadLockRequiredException,
                 AccessDeniedException
Dump the file contents to the stream.

Parameters:
os - The stream the file contents are written to. The stream is not closed after writing, that must be done by the caller.
Returns:
The number of bytes written to the channel.
Throws:
ReadLockRequiredException - If the client does not have a read lock for the file.
AccessDeniedException - If the client does not have read access to the file.
Locks_required:
A read lock on the file.
Permissions_required:
Read access.

copy

long copy(WritableByteChannel c)
          throws ReadLockRequiredException,
                 AccessDeniedException
Copy the file's contents to the WritableByteChannel.

Parameters:
c - The WritableByteChannel. The channel is not closed by this method.
Returns:
The number of bytes written to the channel.
Throws:
ReadLockRequiredException - If the client does not have a read lock for the file.
AccessDeniedException - If the client does not have read access to the file.
Locks_required:
A read lock on the file.
Permissions_required:
Read access.