peer2me.message
Class ReceivedFileObject

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

public class ReceivedFileObject
extends FileObject
implements java.lang.Runnable

This class extends FileObject and implements Runnable and is used by the Message class. When the framework receives a file or parts of a file from the network, an instance of this class is created and added to the Message in a MessagePart. Bytes are then constantly written to a FileOutPutStream in this class when new parts of the file is received. An instance of this class should only be created by the framework itself.

Author:
Kim Saxlund

Constructor Summary
ReceivedFileObject(java.lang.String fileName, long fileSize)
          Constructor that starts a thread when called.
 
Method Summary
 void finishedWriting()
          When there are no more bytes to write, this method closes the streams used.
 void run()
          Creates a directory to store the file in if the directory does not exists.
 void setFileName(java.lang.String fileName)
          Sets the name of the file assosiated with this class
 void write(byte[] bytes)
          Appends a number of bytes to the file assosiated with this class
 
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

ReceivedFileObject

public ReceivedFileObject(java.lang.String fileName,
                          long fileSize)
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:
fileName - The name of the file that is created
fileSize - The total size of the file that is created
Method Detail

run

public void run()
Creates a directory to store the file in if the directory does not exists. By default, the directory created is named tmpp2me and is created in one of the root directories of the mobile phone.

Specified by:
run in interface java.lang.Runnable

write

public void write(byte[] bytes)
Appends a number of bytes to the file assosiated with this class

Parameters:
bytes - The bytes that are appended to the file

finishedWriting

public void finishedWriting()
When there are no more bytes to write, this method closes the streams used.


setFileName

public void setFileName(java.lang.String fileName)
Sets the name of the file assosiated with this class

Parameters:
fileName - The name of the file