gov.nih.nci.caarray.services.util.httpfileuploadapplet
Class HttpFileUploader

java.lang.Object
  extended by gov.nih.nci.caarray.services.util.httpfileuploadapplet.HttpFileUploader

public class HttpFileUploader
extends java.lang.Object

This object is the central part of the file upload implementation. It zips all files to be uploaded in one to one relationship before the upload process is started. It contains three ways to do the actual uploading job: using java.net.Socket, java.net.URLConnection and Apatche Jakatar's HttpClient. For the current release HttpClient is used as the way for file upload, since it can upload file as large as up to 300 mk.


Constructor Summary
HttpFileUploader(java.util.Vector files, HttpUploadParameters up)
          constructor
 
Method Summary
 void cleanUp()
          This method is the actual implementation of the cleanup process.
 void cleanUp(java.util.Vector files)
          This method is called to removed all temporary zip files after they have been uploaded from the temp directory.
 long getBytesSent()
          Simply return the current bytsSent value used as part of upload summary.
 java.lang.String getCurrentFileName()
          This method is called by the thread to pass the current uploading file name to the applet for display, so the user knows what file is being uploaded.
 java.lang.StringBuffer getDurationString()
          Calculate the day, hour, minute and second used for uploading this batch of files, and compose a StringBuffer to be used by the applet as part of the summary content.
 java.lang.Object[] getFailFiles()
          returns all failed files to applet so applet can display them as part of the summary popup window.
 java.lang.String getFailureMessage()
          Returns error message derived from the Exception thrown during the uploading process at the time of this method is called.
 java.lang.String getNotifyReply()
          Simply returns a string value received from server as part of response.
 java.lang.Object[] getOkFiles()
          Returns all uploaded files to applet so applet can display them as part of the summary popup window.
 int getPercentage()
          To calculate the percentage of upload that is completed.
 boolean isFailed()
          Returns the value isFailed set dynamically during the cause of file upload.
 boolean isStopped()
           
 boolean isZipped()
           
 void notifyServer(java.lang.String mode)
          After a upload, notify the server to start process uploaded files, or clean up the cache if failed.
 void setFailureMessage()
           
 void setStopped(boolean isStopped)
           
 boolean uploadFilesViaHttpClient()
          Implementation of the file upload using Apatche's HttpClient framework.
 boolean uploadFilesViaSocket()
          The imploemetation of file upload using java.net.Socket.
 boolean uploadFilesViaURLConnection()
          The method using URLConnection to upload files.
 void zipFile(HttpUploadFile uf)
          This method puts a single file into a zip format.
 void zipFiles()
          Zip files into zip file one at a time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpFileUploader

public HttpFileUploader(java.util.Vector files,
                        HttpUploadParameters up)
constructor

Parameters:
files - The Vector containing a batch of file names to be uploaded.
up - the HttpUploadParameters object encapsulating all the parameters passed from the server to the applet.
Method Detail

isZipped

public boolean isZipped()

zipFiles

public void zipFiles()
Zip files into zip file one at a time.


zipFile

public void zipFile(HttpUploadFile uf)
             throws java.lang.Exception
This method puts a single file into a zip format. The zip file is created in a temporary director.

Parameters:
uf - The HttpUploadFile object containing all the information about the file to be uploaded.
Throws:
java.lang.Exception - if an error occurs during zip building

cleanUp

public void cleanUp(java.util.Vector files)
This method is called to removed all temporary zip files after they have been uploaded from the temp directory.

Parameters:
files - The Vector contains all files to be cleaned.

cleanUp

public void cleanUp()
This method is the actual implementation of the cleanup process.


getFailureMessage

public java.lang.String getFailureMessage()
Returns error message derived from the Exception thrown during the uploading process at the time of this method is called.

Returns:
String the error message currently assigned to this variable.

setFailureMessage

public void setFailureMessage()

isFailed

public boolean isFailed()
Returns the value isFailed set dynamically during the cause of file upload.

Returns:
boolean True if upload is so far so good, otherwise false to indicate error occurance.

getNotifyReply

public java.lang.String getNotifyReply()
Simply returns a string value received from server as part of response. The value will be displayed by the applet.

Returns:
an String value returned by the server as part of the response.

getOkFiles

public java.lang.Object[] getOkFiles()
Returns all uploaded files to applet so applet can display them as part of the summary popup window.

Returns:
an Object array that encompasses all uploaded file names.

getFailFiles

public java.lang.Object[] getFailFiles()
returns all failed files to applet so applet can display them as part of the summary popup window.

Returns:
an Object array that encompasses all failed file names.

getBytesSent

public long getBytesSent()
Simply return the current bytsSent value used as part of upload summary.

Returns:
long the bytes sent to the server.

getDurationString

public java.lang.StringBuffer getDurationString()
Calculate the day, hour, minute and second used for uploading this batch of files, and compose a StringBuffer to be used by the applet as part of the summary content.

Returns:
StringBuffer the composed time duration string buffer.

getPercentage

public int getPercentage()
To calculate the percentage of upload that is completed. Due to the nature of upload through Http protocol, it is not possible to obtain the actual bytes of data being sent at a particular time point, So this calculation is based on the files that have been uploaded divided by the sum of the sizes of all files.

Returns:
the percentage number that is completed.

getCurrentFileName

public java.lang.String getCurrentFileName()
This method is called by the thread to pass the current uploading file name to the applet for display, so the user knows what file is being uploaded.

Returns:
String the file name whose bytes are being transfered to the server.

uploadFilesViaURLConnection

public boolean uploadFilesViaURLConnection()
The method using URLConnection to upload files. The largest files this method can handle is about 32 mb. The method always returns true after all files are uploaded regardless of success or failure. Failed ones are kept in the Vector failFiles. NOTE: DO NOT REMOVE THIS METHOD IN CASE OF THE FAILURE OF OTHER METHODS.

Returns:
boolean true. Always true in this case when the file loop is over.

uploadFilesViaHttpClient

public boolean uploadFilesViaHttpClient()
Implementation of the file upload using Apatche's HttpClient framework. This can handle file up to 200 mb. The overhead is that the applet jar file must include HttpClient jar file, logging jar file and encryption jar file. The method always returns true after all files are uploaded regardless of success or failure. Failed ones are kept in the Vector failFiles.

Returns:
boolean true.

uploadFilesViaSocket

public boolean uploadFilesViaSocket()
The imploemetation of file upload using java.net.Socket. This method can upload file up to 120 mb. The method always returns true after all files are uploaded regardless of success or failure. Failed ones are kept in the Vector failFiles. EXCEPTION: if the first try block fails, then it returns false, and no file shall be uploaded at all. NOTE: DO NOT REMOVE THIS METHOD IN CASE OF THE FAILURE OF OTHER METHODS.

Returns:
boolean true if upload successful, otherwise false.

notifyServer

public void notifyServer(java.lang.String mode)
After a upload, notify the server to start process uploaded files, or clean up the cache if failed.

Parameters:
mode - The string value to indicate what to do for the server. mode=stop delete uploaded files and block incoming files to be saved to file system; mode=success, start parsing service; mode=done, moving onto different page (close applet).

isStopped

public boolean isStopped()

setStopped

public void setStopped(boolean isStopped)