com.groovyj.filesystem
Class Filesystem.File

java.lang.Object
  |
  +--com.groovyj.filesystem.Filesystem.File
Enclosing class:
Filesystem

public class Filesystem.File
extends java.lang.Object

Filesystem.File is a class containing all the operations you can do to a file in the Filesystem.


Method Summary
 void delete()
          Deletes this file entirely.
 int getFilePointer()
          Get the file pointer, in bytes, of this file.
 long getOffset()
          Get the offset at which this file begins.
 int length()
          Get the length, in bytes, of this file.
 byte[] read(int len)
          Read an amount of bytes starting at the file pointer, and return an array filled with the bytes read.
 void seek(int offset)
          Move the file pointer to the given byte offset in this file.
 void truncate()
          Truncates this file at the file pointer.
 void write(byte[] data)
          Write the given data to the file at the file pointer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getOffset

public long getOffset()
Get the offset at which this file begins. This is the only way a program can open this file again.
Returns:
the offset of this file, or -1 if this file is new and hasn't been written to.

length

public int length()
Get the length, in bytes, of this file.
Returns:
the length, in bytes, of this file.

getFilePointer

public int getFilePointer()
Get the file pointer, in bytes, of this file. The file pointer of this file is the offset into this file at which the next write or read operation will take place. The file pointer of a newly opened file is always 0.
Returns:
the file pointer of this file.

seek

public void seek(int offset)
          throws java.io.IOException
Move the file pointer to the given byte offset in this file. If the length of this file is L, then you can move the file pointer anywhere between 0 and L inclusive without throwing an IOException. Moving the file pointer to L means that the next write operation will append to this file. If the file pointer is at L, then the next read operation will fail since there is nothing to read.
Parameters:
offset - the byte offset into the file to which to move the file pointer.
Throws:
java.io.IOException - the offset was negative or greater than the length of this file.

write

public void write(byte[] data)
           throws java.io.IOException
Write the given data to the file at the file pointer.
Parameters:
data - an array of bytes which will be written to this file.
Throws:
java.io.IOException - writing the raw underlying filesystem failed.

read

public byte[] read(int len)
            throws java.io.IOException
Read an amount of bytes starting at the file pointer, and return an array filled with the bytes read.
Parameters:
len - the number of bytes to read.
Returns:
an array of bytes containing the bytes read. The length of the array may not be equal to len, and if no bytes could be read (for example the file pointer is at the end of this file) then the array will be of zero length.
Throws:
java.io.IOException - reading the raw underlying filesystem failed.

delete

public void delete()
            throws java.io.IOException
Deletes this file entirely. Reclaims all the space used by this file. This file becomes equivalent to a new file.
Throws:
java.io.IOException - the raw underlying filesystem couldn't be updated.

truncate

public void truncate()
              throws java.io.IOException
Truncates this file at the file pointer. Any segments after the file pointer are reclaimed as free space.
Throws:
java.io.IOException - the raw underlying filesystem couldn't be updated.