org.entityfs.ram
Class RamFileAdapter

java.lang.Object
  extended by org.entityfs.impl.impl.adapter.AbstractRWEntityAdapter<RamFileSystemAdapter,RamDirectoryAdapter>
      extended by org.entityfs.ram.AbstractRamEntityAdapter
          extended by org.entityfs.ram.RamFileAdapter
All Implemented Interfaces:
EntityAdapter, FileAdapter

public final class RamFileAdapter
extends AbstractRamEntityAdapter
implements FileAdapter

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

Constructor Summary
RamFileAdapter(RamFileSystemAdapter fs, RamDirectoryAdapter parent, String name)
           
 
Method Summary
 void copyTo(OutputStream os)
          Copy the file contents to the output stream.
 void copyTo(WritableByteChannel wbc)
          Copy the file contents to the writable channel.
 void delete()
          Override to leave back segments to the size guard
 long getDataSize()
          Get the file's data size in bytes.
 EntityType getEntityType()
          Get the EntityType for this entity.
 T getFileSystemAdapter()
          Get the FileSystemAdapter for the file system where the entity is.
 long getSize()
          Get the file size in bytes.
 void init()
          This implementation does nothing.
 ScatteringByteChannel openChannelForRead()
           
 GatheringByteChannel openChannelForWrite(boolean append)
           
 RandomAccess openForRandomAccess(RandomAccessMode mode)
           
 InputStream openForRead()
          Open an InputStream on the file.
 OutputStream openForWrite(boolean append)
          Open the file for writing.
 int read(long pos)
           
 int read(long pos, byte[] barr)
           
 int read(long pos, byte[] barr, int off, int len)
          Same behavior as InputStream.read
 int read(long pos, ByteBuffer bb)
           
 void replaceContents(FileAdapter fa)
          Replace the contents of this file adapter with the contents of the supplied file adapter.
 void setLength(long l)
           
 String toString()
           
 void write(byte[] barr)
           
 void write(byte[] barr, int off, int len)
          Same contract as OutputStream.write
 int write(ByteBuffer src)
           
 void write(int b)
           
 void writeAt(long pos, byte[] barr)
           
 void writeAt(long pos, byte[] barr, int off, int len)
           
 int writeAt(long pos, ByteBuffer src)
           
 void writeAt(long pos, int b)
           
 
Methods inherited from class org.entityfs.ram.AbstractRamEntityAdapter
canRead, canWrite, create, exists, getLastModified, rename, setLastModified
 
Methods inherited from class org.entityfs.impl.impl.adapter.AbstractRWEntityAdapter
getName, getParent, setName, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.entityfs.impl.adapter.EntityAdapter
canRead, canWrite, create, exists, getFileSystemAdapter, getLastModified, getName, getParent, init, rename, setLastModified
 

Constructor Detail

RamFileAdapter

public RamFileAdapter(RamFileSystemAdapter fs,
                      RamDirectoryAdapter parent,
                      String name)
Method Detail

getSize

public long getSize()
Description copied from interface: FileAdapter
Get the file size in bytes.

Specified by:
getSize in interface FileAdapter
Returns:
The file size in bytes.

getDataSize

public long getDataSize()
Description copied from interface: FileAdapter
Get the file's data size in bytes.

Specified by:
getDataSize in interface FileAdapter
Returns:
The file's data size in bytes.

openForRead

public InputStream openForRead()
Description copied from interface: FileAdapter
Open an InputStream on the file.

Specified by:
openForRead in interface FileAdapter
Returns:
An open InputStream for the file.

openForWrite

public OutputStream openForWrite(boolean append)
Description copied from interface: FileAdapter
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.

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

openChannelForRead

public ScatteringByteChannel openChannelForRead()
Specified by:
openChannelForRead in interface FileAdapter

openChannelForWrite

public GatheringByteChannel openChannelForWrite(boolean append)
Specified by:
openChannelForWrite in interface FileAdapter

openForRandomAccess

public RandomAccess openForRandomAccess(RandomAccessMode mode)
Specified by:
openForRandomAccess in interface FileAdapter

copyTo

public void copyTo(OutputStream os)
Description copied from interface: FileAdapter
Copy the file contents to the output stream.

Specified by:
copyTo in interface FileAdapter
Parameters:
os - The output stream. The stream is not closed by this method.

copyTo

public void copyTo(WritableByteChannel wbc)
Description copied from interface: FileAdapter
Copy the file contents to the writable channel.

Specified by:
copyTo in interface FileAdapter
Parameters:
wbc - The writable channel. The channel is not closed by this method.

getEntityType

public EntityType getEntityType()
Description copied from interface: EntityAdapter
Get the EntityType for this entity.

Specified by:
getEntityType in interface EntityAdapter
Returns:
The EntityType for this entity.

read

public int read(long pos)

read

public int read(long pos,
                byte[] barr,
                int off,
                int len)
Same behavior as InputStream.read


read

public int read(long pos,
                byte[] barr)

read

public int read(long pos,
                ByteBuffer bb)

write

public void write(int b)

write

public void write(byte[] barr,
                  int off,
                  int len)
Same contract as OutputStream.write

Parameters:
barr -
off -
len -

write

public void write(byte[] barr)

writeAt

public void writeAt(long pos,
                    int b)

writeAt

public void writeAt(long pos,
                    byte[] barr,
                    int off,
                    int len)

writeAt

public void writeAt(long pos,
                    byte[] barr)

write

public int write(ByteBuffer src)

writeAt

public int writeAt(long pos,
                   ByteBuffer src)

setLength

public void setLength(long l)

delete

public void delete()
Override to leave back segments to the size guard

Specified by:
delete in interface EntityAdapter
Overrides:
delete in class AbstractRamEntityAdapter

replaceContents

public void replaceContents(FileAdapter fa)
Description copied from interface: FileAdapter
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.

Specified by:
replaceContents in interface FileAdapter
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.

toString

public String toString()
Overrides:
toString in class Object

init

public void init()
This implementation does nothing. Override if necessary.

Specified by:
init in interface EntityAdapter

getFileSystemAdapter

public T getFileSystemAdapter()
Description copied from interface: EntityAdapter
Get the FileSystemAdapter for the file system where the entity is.

Specified by:
getFileSystemAdapter in interface EntityAdapter
Returns:
The entity adapter's FileSystemAdapter.