org.entityfs.impl.adapter
Interface FileAdapter

All Superinterfaces:
EntityAdapter
All Known Implementing Classes:
RamFileAdapter, ZipFileAdapter

public interface FileAdapter
extends EntityAdapter

This is an adapter for a file in the backing file system.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-core

Method Summary
 void copyTo(OutputStream os)
          Copy the file contents to the output stream.
 void copyTo(WritableByteChannel c)
          Copy the file contents to the writable channel.
 long getDataSize()
          Get the file's data size in bytes.
 long getSize()
          Get the file size in bytes.
 ReadableByteChannel openChannelForRead()
           
 WritableByteChannel openChannelForWrite(boolean append)
           
 RandomAccess openForRandomAccess(RandomAccessMode mode)
           
 InputStream openForRead()
          Open an InputStream on the file.
 OutputStream openForWrite(boolean append)
          Open the file for writing.
 void replaceContents(FileAdapter fa)
          Replace the contents of this file adapter with the contents of the supplied file adapter.
 
Methods inherited from interface org.entityfs.impl.adapter.EntityAdapter
canRead, canWrite, create, delete, exists, getEntityType, getFileSystemAdapter, getLastModified, getName, getParent, init, rename, setLastModified
 

Method Detail

getSize

long getSize()
Get the file size in bytes.

Returns:
The file size in bytes.

getDataSize

long getDataSize()
Get the file's data size in bytes.

Returns:
The file's data size in bytes.

openForRead

InputStream openForRead()
Open an InputStream on the file.

Returns:
An open InputStream for the file.

openForWrite

OutputStream openForWrite(boolean append)
Open the file for writing.

See WritableFile.openForWrite() and WritableFile.openForAppend() for the subtle and the not-so-subtle differences between the append and overwrite modes.

Parameters:
append - If true, new data will be appended to existing data in the file. If false, existing data will be overwritten.

openChannelForRead

ReadableByteChannel openChannelForRead()

openChannelForWrite

WritableByteChannel openChannelForWrite(boolean append)

openForRandomAccess

RandomAccess openForRandomAccess(RandomAccessMode mode)

copyTo

void copyTo(OutputStream os)
Copy the file contents to the output stream.

Parameters:
os - The output stream. The stream is not closed by this method.

copyTo

void copyTo(WritableByteChannel c)
Copy the file contents to the writable channel.

Parameters:
c - The writable channel. The channel is not closed by this method.

replaceContents

void replaceContents(FileAdapter fa)
Replace the contents of this file adapter with the contents of the supplied file adapter.

Implementations must make sure that the file's last modification time is updated.

Parameters:
fa - The file adapter whose contents this file adapter's contents should be replaced with. fa is guaranteed to be in the same file system as this file adapter.