|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.entityfs.util.base.AbstractReadWritableFile
org.entityfs.util.io.ReadWritableFileAdapter
public class ReadWritableFileAdapter
This class adapts java.io.File
to the ReadWritableFile
interface. It also implements NamedReadableFile
, making it possible
to get the file's name.
All locking methods return DummyLock
:s.
Field Summary |
---|
Fields inherited from class org.entityfs.util.base.AbstractReadWritableFile |
---|
DEFAULT_BUFFER_SIZE |
Constructor Summary | |
---|---|
ReadWritableFileAdapter(File f)
Create a ReadWritableFile adapter. |
|
ReadWritableFileAdapter(File f,
int bufferSize)
Create a ReadWritableFile adapter. |
Method Summary | |
---|---|
void |
delete()
Delete the file. |
boolean |
equals(Object o)
|
File |
getFile()
Get the adapted file. |
String |
getName()
Get the name. |
long |
getSize()
Get the size of the file (in bytes). |
int |
hashCode()
|
boolean |
isDeleted()
This method returns true if the result from calling
File.exists() on the adapted file is false , and
vice versa. |
FileChannel |
openChannelForAppend()
Open a channel for appending to the adapted file. |
FileChannel |
openChannelForRead()
Open a channel for reading from the adapted file. |
FileChannel |
openChannelForWrite()
Open a channel for writing on the adapted file. |
OutputStream |
openForAppend()
Open a stream for appending to the adapted file. |
RandomAccess |
openForRandomAccess(RandomAccessMode mode)
Open the file for random access in the specified mode. |
InputStream |
openForRead()
Open a stream for reading from the adapted file. |
OutputStream |
openForWrite()
Open a stream for writing on the adapted file. |
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()
|
Methods inherited from class org.entityfs.util.base.AbstractReadWritableFile |
---|
copy, copy, getDataSize, getReadLock, getSizeNoLocking, getWriteLock, isReadLockedByCurrentThread, isWriteLockedByCurrentThread, lockForReading, lockForWriting |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.entityfs.ReadableFile |
---|
getDataSize |
Methods inherited from interface org.entityfs.lock.ReadLockable |
---|
getReadLock, isReadLockedByCurrentThread, lockForReading |
Constructor Detail |
---|
public ReadWritableFileAdapter(File f)
ReadWritableFile
adapter.
If this object has to create a temporary buffer for storing data in, it
will use a buffer of the default buffer size,
AbstractReadWritableFile.DEFAULT_BUFFER_SIZE
.
f
- The file to adapt. It is not checked that the file referred by
the object exists and that it is a file.ReadWritableFileAdapter(File, int)
public ReadWritableFileAdapter(File f, int bufferSize) throws IllegalArgumentException
ReadWritableFile
adapter.
If this object has to create a temporary buffer for storing data in, it will use a buffer of the supplied size.
f
- The file to adapt. It is not checked that the file referred by
the object exists and that it is a file.bufferSize
- The size of temporary buffers used by this object.
IllegalArgumentException
- If the buffer size is not greater than
zero.ReadWritableFileAdapter(File)
Method Detail |
---|
public File getFile()
public FileChannel openChannelForRead() throws WrappedIOException
openChannelForRead
in interface ReadableFile
WrappedIOException
- On I/O errors.ReadableFile.openForRead()
public InputStream openForRead() throws WrappedIOException
openForRead
in interface ReadableFile
WrappedIOException
- On I/O errors.public FileChannel openChannelForWrite() throws WrappedIOException
openChannelForWrite
in interface WritableFile
WrappedIOException
- On I/O errors.WritableFile.openForWrite()
,
WritableFile.openChannelForAppend()
public OutputStream openForWrite() throws WrappedIOException
openForWrite
in interface WritableFile
WrappedIOException
- On I/O errors.WritableFile.openForAppend()
,
WritableFile.openChannelForWrite()
public FileChannel openChannelForAppend() throws WrappedIOException
openChannelForAppend
in interface WritableFile
WrappedIOException
- On I/O errors.public OutputStream openForAppend() throws WrappedIOException
openForAppend
in interface WritableFile
WrappedIOException
- On I/O errors.WritableFile.openForWrite()
,
WritableFile.openChannelForAppend()
public RandomAccess openForRandomAccess(RandomAccessMode mode) throws WrappedIOException
openForRandomAccess
in interface RandomlyAccessibleFile
mode
- The mode to open the file in.
RandomAccess
object.
WrappedIOException
- On I/O errors.public void delete() throws BackendErrorException
delete
in interface Deletable
BackendErrorException
- If the file cannot be deleted.public boolean isDeleted()
true
if the result from calling
File.exists()
on the adapted file is false
, and
vice versa.
isDeleted
in interface Deletable
true
if the entity object has been deleted.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
replaceContents
in class AbstractReadWritableFile
f
- The file whose contents are to be moved to this file. f
is deleted by this method.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 String getName() throws IllegalStateException, ReadLockRequiredException
Named
/
.
getName
in interface Named
IllegalStateException
- If this is called on a disconnected view.
ReadLockRequiredException
- If the client does not have a read lock
for the viewed entity or its parent.public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |