de.waldheinz.fs.fat
Class FatFile

java.lang.Object
  extended by de.waldheinz.fs.AbstractFsObject
      extended by de.waldheinz.fs.fat.FatFile
All Implemented Interfaces:
FsFile, FsObject

public final class FatFile
extends AbstractFsObject
implements FsFile

The in-memory representation of a single file (chain of clusters) on a FAT file system.

Since:
0.6
Author:
Matthias Treydte <waldheinz at gmail.com>

Method Summary
 void flush()
          Has no effect besides possibly throwing an ReadOnlyException.
 long getLength()
          Returns the length of this file in bytes.
 void read(long offset, ByteBuffer dest)
           Reads from this file into the specified ByteBuffer. Unless this file is read-ony, this method also updates the "last accessed" field in the directory entry that is associated with this file.
 void setLength(long length)
          Sets the size (in bytes) of this file.
 String toString()
          Returns a human-readable string representation of this FatFile, mainly for debugging purposes.
 void write(long offset, ByteBuffer srcBuf)
           Writes to this file taking the data to write from the specified ByteBuffer. If the data to be written extends beyond the current length of this file, an attempt is made to grow the file so that the data will fit.
 
Methods inherited from class de.waldheinz.fs.AbstractFsObject
checkValid, checkWritable, invalidate, isReadOnly, isValid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.waldheinz.fs.FsObject
isReadOnly, isValid
 

Method Detail

getLength

public long getLength()
Returns the length of this file in bytes. This is the length that is stored in the directory entry that is associated with this file.

Specified by:
getLength in interface FsFile
Returns:
long the length that is recorded for this file

setLength

public void setLength(long length)
               throws ReadOnlyException,
                      IOException
Sets the size (in bytes) of this file. Because writing to the file will grow it automatically if needed, this method is mainly usefull for truncating a file.

Specified by:
setLength in interface FsFile
Parameters:
length - the new length of the file in bytes
Throws:
ReadOnlyException - if this file is read-only
IOException - on error updating the file size

read

public void read(long offset,
                 ByteBuffer dest)
          throws IOException

Reads from this file into the specified ByteBuffer. The first byte read will be put into the buffer at it's position, and the number of bytes read will equal the buffer's remaining bytes.

Unless this file is read-ony, this method also updates the "last accessed" field in the directory entry that is associated with this file.

Specified by:
read in interface FsFile
Parameters:
offset - the offset into the file where to start reading
dest - the destination buffer where to put the bytes that were read
Throws:
IOException - on read error
See Also:
FatDirectoryEntry.setLastAccessed(long)

write

public void write(long offset,
                  ByteBuffer srcBuf)
           throws ReadOnlyException,
                  IOException

Writes to this file taking the data to write from the specified ByteBuffer. This method will read the buffer's remaining bytes starting at it's position.

If the data to be written extends beyond the current length of this file, an attempt is made to grow the file so that the data will fit. Additionally, this method updates the "last accessed" and "last modified" fields on the directory entry that is associated with this file.

Specified by:
write in interface FsFile
Parameters:
offset - the offset into the file where the first byte will be written
srcBuf - the source buffer to read the data from
Throws:
ReadOnlyException - if the file is read-only
IOException - on write error

flush

public void flush()
           throws ReadOnlyException
Has no effect besides possibly throwing an ReadOnlyException. To make sure that all data is written out to disk use the FatFileSystem.flush() method.

Specified by:
flush in interface FsFile
Throws:
ReadOnlyException - if this FatFile is read-only

toString

public String toString()
Returns a human-readable string representation of this FatFile, mainly for debugging purposes.

Overrides:
toString in class Object
Returns:
a string describing this FatFile


Copyright © 2014. All rights reserved.