peer2me.util
Class FileHandler

java.lang.Object
  extended bypeer2me.util.FileHandler

public class FileHandler
extends java.lang.Object

This class contains functionality for reading and writing all kinds of files to and from the device file system.

Author:
Torbjørn Vatn & Steinar A. Hestnes

Constructor Summary
FileHandler(java.lang.String filePath)
          Constructor.
 
Method Summary
 void closeFile()
          This method closes and nullifies the input- and ouput streams, and the file connection
 int getBlockSize()
          This method fetches the size of the blocks to read and write
 java.util.Enumeration getFileList()
          This method returns a list of the files in the given file path on the device
 long getFileSize()
          This method returns the size of the this file
 byte[] readFile()
          This method reads the next byte in the file and returns it
 void setFileSize(long fileSize)
          This method sets the size of the this file
 void writeFile(byte theByte)
          Deprecated. The method is substituted by writeFile(byte[] theBytes, int numberOfBytesRead)
 void writeFile(byte[] theBytes, int numberOfBytesRead)
          This method writes the incoming byte block to the file
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHandler

public FileHandler(java.lang.String filePath)
Constructor.

Parameters:
filePath - The path to the file to be handled
Method Detail

getFileList

public java.util.Enumeration getFileList()
This method returns a list of the files in the given file path on the device

Returns:
A Enumeration containing the names of the files in the root directory

getFileSize

public long getFileSize()
This method returns the size of the this file

Returns:
The size as a long

getBlockSize

public int getBlockSize()
This method fetches the size of the blocks to read and write

Returns:
The blocksize

setFileSize

public void setFileSize(long fileSize)
This method sets the size of the this file

Parameters:
fileSize - The size to set

readFile

public byte[] readFile()
                throws java.io.IOException
This method reads the next byte in the file and returns it

Returns:
The next block of bytes
Throws:
java.io.IOException - This exception is thrown when the reading has failed

writeFile

public void writeFile(byte[] theBytes,
                      int numberOfBytesRead)
               throws java.io.IOException
This method writes the incoming byte block to the file

Parameters:
theBytes - The next byte block to write
numberOfBytesRead - The number of bytes in the theBytes[] array
Throws:
java.io.IOException - This exception is thrown when the writing has failed

writeFile

public void writeFile(byte theByte)
               throws java.io.IOException
Deprecated. The method is substituted by writeFile(byte[] theBytes, int numberOfBytesRead)

This method writes the incoming byte to the file

Parameters:
theByte - The next byte to write
Throws:
java.io.IOException - This exception is thrown when the writing has failed

closeFile

public void closeFile()
This method closes and nullifies the input- and ouput streams, and the file connection