org.entityfs
Interface RandomlyAccessibleFile

All Superinterfaces:
Lockable, ReadLockable, ReadWriteLockable, WriteLockable
All Known Subinterfaces:
ArchiveFileEntry<T,U>, EFile, ReadWritableFile
All Known Implementing Classes:
AbstractReadWritableFile, ByteArrayReadableFile, PaxFileEntry, ReadWritableFileAdapter, TarFileEntry, UstarFileEntry, ZipFileEntry

public interface RandomlyAccessibleFile
extends ReadWriteLockable

This interface is implemented by objects that behave as files that can be randomly accessed, EFile:s for instance.

Use this interface instead of EFile wherever possible to make mocking and testing easier.

Since:
1.0
Author:
Karl Gustafsson
See Also:
ReadableFile, WritableFile

Method Summary
 RandomAccess openForRandomAccess(RandomAccessMode mode)
          Open the file for random access in the specified mode.
 
Methods inherited from interface org.entityfs.lock.ReadLockable
getReadLock, isReadLockedByCurrentThread, lockForReading
 
Methods inherited from interface org.entityfs.lock.WriteLockable
getWriteLock, isWriteLockedByCurrentThread, lockForWriting
 

Method Detail

openForRandomAccess

RandomAccess openForRandomAccess(RandomAccessMode mode)
                                 throws ReadLockRequiredException,
                                        WriteLockRequiredException,
                                        AccessDeniedException,
                                        UnsupportedCapabilityException,
                                        ReadOnlyException,
                                        WriteOnlyException
Open the file for random access in the specified mode.

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

Parameters:
mode - The mode to open the file in.
Returns:
An open RandomAccess object. It must be closed by the caller.
Throws:
ReadLockRequiredException - If the client does not have a read lock for the file and tries to open it for reading.
WriteLockRequiredException - If the client does not have a write lock for the file and tries to open it for writing.
AccessDeniedException - If the client does not have proper access rights for the file.
UnsupportedCapabilityException - If this is called on a file entity in a file system that does not support the FSCRandomAccessFiles capability.
ReadOnlyException - If the client tries to open a read only file for writing.
WriteOnlyException - If the client tries to open a write only file for reading.
Locks_required:
A read lock if the file is opened for reading. A write lock if it is opened for reading and writing.
Permissions_required:
Read access if the file is opened for reading. Write access if it is opened for reading and writing.
Generates_events:
EntityModifiedEvent for this when the RandomAccess is closed if mode allows writes., ChildEntityModifiedEvent for this's parent when the RandomAccess is closed if mode allows writes.