peer2me.message
Class SendFileObject

java.lang.Object
  extended by peer2me.message.FileObject
      extended by peer2me.message.SendFileObject
All Implemented Interfaces:
java.lang.Runnable

public class SendFileObject
extends FileObject
implements java.lang.Runnable

This class extends FileObject and implements Runnable and is used by the Message class. When a file is attached to a Message that is to be sent, a MessagePart with this SendFileObject class is added to the Message. This class is capable of reading a file from the filesystem in chunks.

Author:
Kim Saxlund

Constructor Summary
SendFileObject(java.lang.String fullPathToFile)
          Constructor that starts a thread when called.
 
Method Summary
 long getBytesLeft()
          Returns the number of bytes that has not be read from the file yet
 int getNumberOfBytesJustRead()
          Returns how many bytes was read during the last call to read()
 int numberOfChunksNeeded()
          Calculates and returns how many chunks the file must be read in.
 byte[] read()
          Reads a chunk of a file and returns the data in an array.
 void run()
          Retrives information about the size of the file and sets private variables.
 
Methods inherited from class peer2me.message.FileObject
getFileName, getFileSize, getFullPathToFile, isAccessGranted
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SendFileObject

public SendFileObject(java.lang.String fullPathToFile)
Constructor that starts a thread when called. The thread is started to avoid blocking of the Midlet. The thread creates a connection to the filesystem, which is a operation which must be done in a separate thread than the Midlet itself.

Parameters:
fullPathToFile - The full path to the file
Method Detail

run

public void run()
Retrives information about the size of the file and sets private variables. Also opens an FileInputStream to the file.

Specified by:
run in interface java.lang.Runnable

read

public byte[] read()
Reads a chunk of a file and returns the data in an array. The chunk is determined by the private variable chunkSize. This method continues to read from the file form where it last stopped. If the end of the file is reached, the fileconnection and fileinputstream is closed and the last bytes are returned.

Returns:
A chunk of the file in a byte array. variable chunkSize

numberOfChunksNeeded

public int numberOfChunksNeeded()
Calculates and returns how many chunks the file must be read in. For instance, if this method returns 20, the method read() must be called 20 times before the entire file has been read.

Returns:
The number of times the read() method must be called before the entire file has been read

getBytesLeft

public long getBytesLeft()
Returns the number of bytes that has not be read from the file yet

Returns:
The number of bytes that remains to be read from the file

getNumberOfBytesJustRead

public int getNumberOfBytesJustRead()
Returns how many bytes was read during the last call to read()

Returns:
How many bytes was last read