|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.entityfs.lock.AbstractLockable
org.entityfs.impl.impl.AbstractEntityImpl
org.entityfs.impl.impl.FileImpl
public class FileImpl
Constructor Summary | |
---|---|
FileImpl(FileSystemImplementation fs,
DirectoryImplementation parent,
FileDelegate fd)
|
Method Summary | |
---|---|
void |
assertCanBeDeleted()
Perform entity type-specific checks in addition to the checks in the delete method. |
Set<EntityView> |
copy(DirectoryView d,
String targetName,
boolean preserveAttrs,
EntityLock... setupLocks)
Copy the viewed entity to a new directory and possibly give the target another name. |
long |
copy(OutputStream os)
Dump the file contents to the stream. |
long |
copy(WritableByteChannel c)
Copy the file's contents to the WritableByteChannel . |
void |
copyFrom(ReadableByteChannel c)
|
protected void |
deleteInternal()
This method is called by AbstractEntityImpl.delete() after it has performed all
validity, access control and lock checks. |
long |
getDataSize()
Get the size of the data in the file. |
long |
getSize()
Get the size of the file (in bytes). |
long |
getSizeNoLocking()
Get an approximate size of the file without having to lock it. |
EntityType |
getType()
Get the entity's EntityType . |
void |
notifyClosed(RandomAccess ra)
Notify the observer that the supplied RandomAccess has been
closed. |
WritableByteChannel |
openChannelForAppend()
Open a WritableByteChannel for appending to the file. |
ReadableByteChannel |
openChannelForRead()
Open a ReadableByteChannel for reading from the file. |
WritableByteChannel |
openChannelForWrite()
Open a WritableByteChannel for writing on the file. |
OutputStream |
openForAppend()
Open the file for appending. |
RandomAccess |
openForRandomAccess(RandomAccessMode mode)
Open the file for random access in the specified mode. |
InputStream |
openForRead()
Opens the file for reading. |
OutputStream |
openForWrite()
Opens the file for writing. |
void |
replaceContents(ReadWritableFile f)
Replace the contents of this file with the contents of the supplied file and then delete the supplied file. |
String |
toString()
Subclasses should override this to return something more pretty. |
Methods inherited from class org.entityfs.lock.AbstractLockable |
---|
assertIsReadLocked, assertIsWriteLocked, getLockAcquiringStrategy, getLockAdapter, getLocked, getReadLock, getWriteLock, isReadLockedByCurrentThread, isWriteLockedByCurrentThread, lock, lockForReading, lockForWriting, logLockStack |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.entityfs.impl.EntityViewImplementation |
---|
getAbsoluteLocationNoLocking, getFileSystemImplementation, getNameNoLocking, getObserverList |
Methods inherited from interface org.entityfs.Entity |
---|
hasExecuteAccess, hasReadAccess, hasWriteAccess |
Methods inherited from interface org.entityfs.EntityView |
---|
canRead, canWrite, copy, copyAttributes, createLock, disconnect, getCapability, getFileSystem, getLastModified, getParent, getViewed, getViewedEntity, isConnected, isRootDirectory, isValid, lock, rename, setLastModified, supportsCapability, touch |
Methods inherited from interface java.lang.Comparable |
---|
compareTo |
Methods inherited from interface org.entityfs.event.Observable |
---|
addObserver, countObservers, deleteObserver, deleteObservers |
Methods inherited from interface org.entityfs.Named |
---|
getName |
Methods inherited from interface org.entityfs.Deletable |
---|
delete, isDeleted |
Constructor Detail |
---|
public FileImpl(FileSystemImplementation fs, DirectoryImplementation parent, FileDelegate fd)
Method Detail |
---|
public EntityType getType()
EntityView
EntityType
.
getType
in interface EntityView
ETFile.TYPE
, always.public OutputStream openForWrite()
WritableFile
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
.
openForWrite
in interface WritableFile
OutputStream
to write to. The stream must be closed by
the caller.WritableFile.openForAppend()
,
WritableFile.openChannelForWrite()
public OutputStream openForAppend()
WritableFile
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
.
openForAppend
in interface WritableFile
OutputStream
to write to. The stream must be closed by
the caller.WritableFile.openForWrite()
,
WritableFile.openChannelForAppend()
public WritableByteChannel openChannelForWrite()
WritableFile
WritableByteChannel
for writing on the file. The semantics
of this method is the same as for WritableFile.openForWrite()
.
openChannelForWrite
in interface WritableFile
WritableByteChannel
. The channel must be closed
by the caller. The returned channel may be a
GatheringByteChannel
, but that is not required.WritableFile.openForWrite()
,
WritableFile.openChannelForAppend()
public WritableByteChannel openChannelForAppend()
WritableFile
WritableByteChannel
for appending to the file. The
semantics of this method is the same as for WritableFile.openForAppend()
.
openChannelForAppend
in interface WritableFile
WritableByteChannel
. The channel must be closed
by the caller. The returned channel may be a
GatheringByteChannel
, but that is not required.public InputStream openForRead()
ReadableFile
Although a read 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
LockAwareInputStream
.
openForRead
in interface ReadableFile
InputStream
on the file. The stream must be closed by
the caller.public ReadableByteChannel openChannelForRead()
ReadableFile
ReadableByteChannel
for reading from the file. The
semantics of this method is the same as for ReadableFile.openForRead()
.
Although a read lock on the file is required for the execution thread
opening the channel, the channel itself is not protected from access by
other threads. It can be protected by wrapping it in a
LockAwareReadableByteChannel
.
openChannelForRead
in interface ReadableFile
ReadableByteChannel
. The channel must be closed
by the caller. The channel may be a
ScatteringByteChannel
, but that is not
required.ReadableFile.openForRead()
public RandomAccess openForRandomAccess(RandomAccessMode mode)
RandomlyAccessibleFile
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.
openForRandomAccess
in interface RandomlyAccessibleFile
mode
- The mode to open the file in.
RandomAccess
object. It must be closed by the
caller.public long copy(OutputStream os)
ReadWritableFile
copy
in interface ReadWritableFile
os
- The stream the file contents are written to. The stream is not
closed after writing, that must be done by the caller.
public long copy(WritableByteChannel c)
ReadWritableFile
WritableByteChannel
.
copy
in interface ReadWritableFile
c
- The WritableByteChannel
. The channel is not closed by
this method.
public void copyFrom(ReadableByteChannel c)
copyFrom
in interface EFileImplementation
public Set<EntityView> copy(DirectoryView d, String targetName, boolean preserveAttrs, EntityLock... setupLocks)
EntityView
Filter
instances). If
an entity view is copied is copied into a directory view, the both view's
filters are combined in the returned view.
This method returns a list of entity view objects rather than just a
single EntityView
object. The reason for this is that the target
file system may have different ideas about what constitutes an entity
compared with the source file system. An entity in one file system might
be three entities in another file system, or no entity at all. When
copying within the same file system or between file systems with the same
set of capabilities, the returned list always has one and only one entity
view in it.
This method does not copy directories recursively. To do that, use the
IteratorCopier
.
This method can release locks that are only necessary for setting up the
target entity before data is copied to it. This may be the write lock for
the target directory and the read lock for the source entity's parent
directory. See the setupLocks
parameter.
If the copied entity supports any
ECEntityAttributes
capability, its
attributes are copied by this method if the preserveAttrs
parameter is set to true
.
copy
in interface EntityView
d
- A view of the target directory.targetName
- The target entity's name.preserveAttrs
- Should attributes from the source entity be copied
to the target entity? An example of an entity attribute is its latest
modification time. Capabilities may add their own attributes; see the
documentation for each capability for details.setupLocks
- Locks only necessary for setting up the target entity.
They are unlocked before data is copied to the target entity. The method
is guaranteed to release locks given here, even if it throws an
exception. The read lock on the source parent directory and/or the write
lock on the target directory can be supplied in this collection. If any
or both of the locks are, they are unlocked before any file data is
copied to the target entity.
public long getSize()
ReadableFile
Note: Most, but not all, implementations know their sizes. If an implementation does not know its size beforehand, this method will be slow since it has to calculate the file size when it is called.
Implementation note: If the size of the backing file is not known,
the
StreamUtil.getSizeOfDataInStream(InputStream, int)
method can be used to calculate it.
getSize
in interface ReadableFile
ReadableFile.getDataSize()
public long getSizeNoLocking()
ReadWritableFile
getSizeNoLocking
in interface ReadWritableFile
0
is returned.ReadableFile.getSize()
public long getDataSize()
ReadableFile
ReadableFile.getSize()
.
Warning: Calculating the data size of a file has the potential of being really slow, depending on the implementation used. The entire file may have to be read through in order to calculate the size of its data.
Implementation note: If the size of the backing file is not known,
the
StreamUtil.getSizeOfDataInStream(InputStream, int)
method can be used to calculate it.
getDataSize
in interface ReadableFile
ReadableFile.getSize()
public void notifyClosed(RandomAccess ra)
RandomAccessCloseObserver
RandomAccess
has been
closed.
notifyClosed
in interface RandomAccessCloseObserver
ra
- The closed RandomAccess
.public void replaceContents(ReadWritableFile f)
ReadWritableFile
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
.
replaceContents
in interface ReadWritableFile
f
- The file whose contents are to be moved to this file. f
is deleted by this method.public void assertCanBeDeleted()
AbstractEntityImpl
delete
method.
assertCanBeDeleted
in class AbstractEntityImpl
protected void deleteInternal()
AbstractEntityImpl
AbstractEntityImpl.delete()
after it has performed all
validity, access control and lock checks. Subclasses implement this to
call their delegate's delete
method.
deleteInternal
in class AbstractEntityImpl
public String toString()
AbstractEntityImpl
toString
in class AbstractEntityImpl
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |