org.alltimeflashdreamer.filelister
Class ZipBuilderThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.alltimeflashdreamer.filelister.ZipBuilderThread
All Implemented Interfaces:
Runnable

class ZipBuilderThread
extends Thread

Title: ZipBuilderThread

Description: Starts and controls the generation of a zip file using the ZipBuilder class. While the zip builder runs it's job, this thread collects the created output and provides it to the FileListerDownloadServlet which then shows a comment site to the client.

Organization: All Time Flash Dreamer

Version:
0.5.1
Author:
Copyright (c) 2002-2004 by Florian Steinsiepe

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
(package private) ZipBuilderThread(FileListerConfig fileListerConfig, ArrayList arrayFileListerEntries)
          The constructor stores the given pointers and generates a random-based zip file name.
 
Method Summary
protected  void finalize()
          Override of Object's finalize method: Makes sure that the generated zip is deleted before this class is finalized.
(package private)  ArrayList getComments()
          Returns the list of the collected comments of the ZipBuilder while zipping directories and adding file to the zip.
(package private)  long getCurrentArchiveSize()
          Simple accessor method for ZipBuilder's getCurrentArchiveSize() method.
(package private)  String getCurrentlyAdding()
          Simple accessor method for ZipBuilder's getCurrentlyAddedFile() method.
(package private)  String getFilesDone()
          Returns the amount of processed files and the total amount of files to be added to the zip.
(package private)  double getOverallPackingRatio()
          Simple accessor method for ZipBuilder's getOverallPackingRatio() method.
(package private)  double getProgressPercentage()
          Returns the result of the division of the size of the processed files and the total size of files to be processed.
(package private)  String getSizeDone()
          Returns the amount of bytes already processed and the total amount of bytes to be processed.
(package private)  String getTimeElapsed()
          Returns the amount of elapsed time and the expected amount or remaining time.
(package private)  ArrayList getWarnings()
           
(package private)  String getZipFileName()
          Returns the name of the generated zip file for having access to it before streaming it to the client.
(package private)  boolean hasHundredPercentPageBeenShown()
          Returns whether the final / 100% page has already been shown or not.
(package private)  boolean isReadyToStream()
          Returns whether the run method successfully completed the zip file.
(package private)  void markForCleanUp()
          Sets the "mark for clean-up" boolean.
 void run()
          Opens a buffered file output stream to the file having the previously generated zip file name and calls the ZipBuilder constructor using this output stream as well as the file list and the config object received in the constructor.
(package private)  void setHundredPercentPageWasShown()
          Tells that the final / 100% page has now been shown.
(package private)  void streamZipFile(HttpServletResponse response)
          Opens a buffered file input stream and connects it to the given response's output stream.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ZipBuilderThread

ZipBuilderThread(FileListerConfig fileListerConfig,
                 ArrayList arrayFileListerEntries)
           throws FileListerException
The constructor stores the given pointers and generates a random-based zip file name.

Parameters:
fileListerConfig - the magic config object
arrayFileListerEntries - list of selected FileListerEntry objects
Throws:
FileListerException - if the list of entries can't be transformed into a list of File objects
Method Detail

run

public void run()
Opens a buffered file output stream to the file having the previously generated zip file name and calls the ZipBuilder constructor using this output stream as well as the file list and the config object received in the constructor. The thread is running/alive as long as the ZipBuilder hasn't finished. If an exception occurs, it's wrapped into a FileListerException and set to the FileListerConfig.

See Also:
getZipFileName()

finalize

protected void finalize()
                 throws Throwable
Override of Object's finalize method: Makes sure that the generated zip is deleted before this class is finalized.

Throws:
Throwable - as defined in Object, but not used

getComments

ArrayList getComments()
Returns the list of the collected comments of the ZipBuilder while zipping directories and adding file to the zip. If the ZipBuilder couldn't be instantiated, an empty list is returned, but not null.

Returns:
a list of String comments

getZipFileName

String getZipFileName()
Returns the name of the generated zip file for having access to it before streaming it to the client.

Returns:
the zip file name generated during construction

streamZipFile

void streamZipFile(HttpServletResponse response)
             throws IOException
Opens a buffered file input stream and connects it to the given response's output stream. After the file has been streamed (or some exceptionoccurred), the method closes the input stream, deletes the streamedfile and marks the class as !isReadyToStream, indicating that this file can't be streamed anymore.

Parameters:
response - where to get the output stream from
Throws:
IOException - only if the redirect to the error site throws an IOException, i.e. within the method's own catch block

isReadyToStream

boolean isReadyToStream()
Returns whether the run method successfully completed the zip file.

Returns:
zip file streamable?

getProgressPercentage

double getProgressPercentage()
Returns the result of the division of the size of the processed files and the total size of files to be processed.

Returns:
e.g. 0.18, indicating that 18% of the total byte count is already packed into the archive

getCurrentArchiveSize

long getCurrentArchiveSize()
Simple accessor method for ZipBuilder's getCurrentArchiveSize() method.

Returns:
same as getCurrentArchiveSize() in ZipBuilder class
See Also:
ZipBuilder.getCurrentArchiveSize()

getOverallPackingRatio

double getOverallPackingRatio()
Simple accessor method for ZipBuilder's getOverallPackingRatio() method.

Returns:
same as getOverallPackingRatio() in ZipBuilder class
See Also:
ZipBuilder.getOverallPackingRatio()

getFilesDone

String getFilesDone()
Returns the amount of processed files and the total amount of files to be added to the zip.

Returns:
something like "29 / 314"

getSizeDone

String getSizeDone()
Returns the amount of bytes already processed and the total amount of bytes to be processed.

Returns:
something like "2.34 MB / 9.789 MB"

getCurrentlyAdding

String getCurrentlyAdding()
Simple accessor method for ZipBuilder's getCurrentlyAddedFile() method.

Returns:
same as getCurrentlyAddedFile() in ZipBuilder class
See Also:
ZipBuilder.getCurrentlyAddedFile()

getTimeElapsed

String getTimeElapsed()
Returns the amount of elapsed time and the expected amount or remaining time. There are two special cases:

Returns:
something like "1 min 27 sec (less than 1 minute remaining)"

getWarnings

ArrayList getWarnings()

hasHundredPercentPageBeenShown

boolean hasHundredPercentPageBeenShown()
Returns whether the final / 100% page has already been shown or not.

Returns:
last page was shown?

setHundredPercentPageWasShown

void setHundredPercentPageWasShown()
Tells that the final / 100% page has now been shown.


markForCleanUp

void markForCleanUp()
Sets the "mark for clean-up" boolean. This leads to an invalidation of the whole thread, i.e. it's never ready to be streamed, and the zip file is deleted immediately after the creation.