qdown.quickDownloader.downloadStreamHandlers
Class ResumeStream

java.lang.Object
  extended byqdown.quickDownloader.downloadStreamHandlers.ResumeStream

public class ResumeStream
extends java.lang.Object

The Main ResumeStream class which downloads files which need to be resumed


Constructor Summary
ResumeStream(NewDownloadControl downloadControl, java.lang.String urlLocation, java.lang.String saveFileTo, java.lang.String id, javax.swing.JProgressBar progress, javax.swing.JTextField statusField, NewDownloadGUI newDownload)
          Constructor is used to build the class in order to resume a download
 
Method Summary
static boolean deletePropFileOnCompletion()
          Deletes all temp files which were used by application
 boolean downloadTheFile(int startAt, java.lang.String nameOfFile, java.lang.String tempDirectory, int totalSize)
          Once the connection has been established the downloading of the file starts
 java.lang.String findOldResumeFile(java.lang.String fileId, java.lang.String tempDirectory)
          The method is used to find the old resume file containing the contents of the previous download
static java.lang.String findPropertiesFile(java.lang.String id, java.lang.String tempDirectory)
          Searches for the properties file for the download
 int getSize(java.io.BufferedReader in)
          Used to return the size of the download to be resumed
 int getTotalSize(java.io.BufferedReader in)
          The method is used to return the size of the download by searching the properties file
static boolean messages(java.lang.String message)
          Used display messages in the system logs and application logs
 java.net.HttpURLConnection openConnection(int startAt)
          The method is used to open a connection to the internet and to get an inputstream which will be used for the download
static java.io.File[] openTempDirectory(java.lang.String tempDirectory)
          Used to open the temp directory and return an array of File objects representing the contents of the directory
 boolean renameTempFile(java.lang.String file, java.lang.String temp1)
          Once the resume has completed the temp file is renames to the correct file name
 boolean setProgressBar(double value)
          Sets the progress bar
 boolean startDownload()
          The main method which initialises the download
 boolean writeCounter(int counter)
          Method is used to write to the temp file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResumeStream

public ResumeStream(NewDownloadControl downloadControl,
                    java.lang.String urlLocation,
                    java.lang.String saveFileTo,
                    java.lang.String id,
                    javax.swing.JProgressBar progress,
                    javax.swing.JTextField statusField,
                    NewDownloadGUI newDownload)
Constructor is used to build the class in order to resume a download

Parameters:
downloadControl - The control class
progress - The progress bar
statusField - The status field
newDownload - The main download GUI
urlLocation - The url to be resumed
saveFileTo - The location where the url will be saved to
id - The id of the resumable file
Method Detail

messages

public static boolean messages(java.lang.String message)
Used display messages in the system logs and application logs

Parameters:
message - The message to be displayed
Returns:
Success of writing to the log file

startDownload

public boolean startDownload()
The main method which initialises the download

Returns:
The success of the download is resumed

findOldResumeFile

public java.lang.String findOldResumeFile(java.lang.String fileId,
                                          java.lang.String tempDirectory)
The method is used to find the old resume file containing the contents of the previous download

Parameters:
fileId - The id used to find the previous resume file
tempDirectory - The location of where the temp directory is located
Returns:
If the file is found or not

renameTempFile

public boolean renameTempFile(java.lang.String file,
                              java.lang.String temp1)
Once the resume has completed the temp file is renames to the correct file name

Parameters:
file - The file that will be renamed to
temp1 - The name of the file to be renamed
Returns:
success of renaming the file

deletePropFileOnCompletion

public static boolean deletePropFileOnCompletion()
Deletes all temp files which were used by application

Returns:
success of deleting the temp file

openConnection

public java.net.HttpURLConnection openConnection(int startAt)
The method is used to open a connection to the internet and to get an inputstream which will be used for the download

Parameters:
startAt - when to start a download
Returns:
The HttpURLConnection representing a connection to the internet is returned

getSize

public int getSize(java.io.BufferedReader in)
Used to return the size of the download to be resumed

Parameters:
in - An inputstream to the properties file containing the information
Returns:
Return the size

getTotalSize

public int getTotalSize(java.io.BufferedReader in)
The method is used to return the size of the download by searching the properties file

Parameters:
in - The Buffered Reader pointing to the properties file
Returns:
Return the size of the download from the properties file

downloadTheFile

public boolean downloadTheFile(int startAt,
                               java.lang.String nameOfFile,
                               java.lang.String tempDirectory,
                               int totalSize)
Once the connection has been established the downloading of the file starts

Parameters:
startAt - The location from the download should resume from
nameOfFile - The name of the file that the download will be renamed to
tempDirectory - The location of where the temp file will be saved to
totalSize - The total size of the file
Returns:
success of the download

setProgressBar

public boolean setProgressBar(double value)
Sets the progress bar

Parameters:
value - The value for the progress bar
Returns:
success of writing to the progress bar

writeCounter

public boolean writeCounter(int counter)
Method is used to write to the temp file

Parameters:
counter - The size currently downloaded
Returns:
success of writing the counter

findPropertiesFile

public static java.lang.String findPropertiesFile(java.lang.String id,
                                                  java.lang.String tempDirectory)
Searches for the properties file for the download

Parameters:
id - The ID of the download
tempDirectory - The location of the temp directory
Returns:
The name of the properties file and the location

openTempDirectory

public static java.io.File[] openTempDirectory(java.lang.String tempDirectory)
Used to open the temp directory and return an array of File objects representing the contents of the directory

Parameters:
tempDirectory - The temp directory
Returns:
The array of files