org.omnaest.utils.download
Class DownloadConnection

java.lang.Object
  extended by org.omnaest.utils.download.DownloadConnection
All Implemented Interfaces:
Runnable

public class DownloadConnection
extends Object
implements Runnable

A download connection offers a connection to a set url, opens a stream and loads the content into a stream.

Author:
Omnaest

Nested Class Summary
static interface DownloadConnection.DownloadMonitor
           
 
Constructor Summary
DownloadConnection()
           
 
Method Summary
 void abortDownload()
          Interrupts and cancels the current download immediately.
 DownloadConnection download()
          Loads the content from the set url source.
 DownloadConnection download(URL url)
          Loads the content from a given url source.
 String getAuthenticationPassword()
           
 String getAuthenticationUser()
           
 byte[] getContentAsBytes()
          Returns the loaded content in a byte[].
 String getContentAsString()
          Returns the content as a String encoded by the determined content encoding.
 long getContentCurrentSize()
          Returns the current size of the loaded amount of content.
 String getContentEncoding()
           
 long getContentEstimatedSize()
          Returns the size that was estimated to receive, by the http content size determined.
 long getContentSize()
          Returns the current size of the downloaded content.
 String getContentType()
           
 DownloadManager getDownloadManager()
           
 long getDownloadSpeed()
           
 int getHTTPStatusCode()
           
 String getStandardEncoding()
           
 long getTimeExpired()
           
 URL getUrl()
           
 String getUsedStringEncoding()
           
 boolean isAlive()
          If the download is initiated in threaded mode, this indicates if the current download thread is still active.
 boolean isDownloadSuccessful()
          Returns true, if no error has occurred during the download.
 int processStatePercentage()
          Returns the percentage of the currently loaded bytes towards the estimated bytes to load.
 void run()
           
 boolean saveContentToFile(File file)
          Saves the content into the given file.
 void setAuthenticationPassword(String authenticationPassword)
           
 void setAuthenticationUser(String authenticationUser)
           
 void setContentEncoding(String contentEncoding)
           
 void setContentType(String contentType)
           
 void setDownloadManager(DownloadManager downloadManager)
           
 DownloadConnection setDownloadMonitor(DownloadConnection.DownloadMonitor downloadMonitor)
           
 void setStandardEncoding(String standardEncoding)
           
 DownloadConnection setUrl(URL url)
           
 void setUsedStringEncoding(String usedStringEncoding)
           
 DownloadConnection threadedDownload()
          Downloads the set url source through a single thread created.
 DownloadConnection threadedDownload(URL url)
          Downloads the given url through a single thread created for this purpose.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DownloadConnection

public DownloadConnection()
Method Detail

setUrl

public DownloadConnection setUrl(URL url)

run

public void run()
Specified by:
run in interface Runnable

threadedDownload

public DownloadConnection threadedDownload()
Downloads the set url source through a single thread created. To find out, if the thread still runs, use isAlive()

Returns:

threadedDownload

public DownloadConnection threadedDownload(URL url)
Downloads the given url through a single thread created for this purpose. Use isAlive() to find out, if the download is still in progress.

Parameters:
url -
Returns:

abortDownload

public void abortDownload()
Interrupts and cancels the current download immediately.


isAlive

public boolean isAlive()
If the download is initiated in threaded mode, this indicates if the current download thread is still active.

Returns:

processStatePercentage

public int processStatePercentage()
Returns the percentage of the currently loaded bytes towards the estimated bytes to load.

Returns:

download

public DownloadConnection download(URL url)
Loads the content from a given url source.

Parameters:
url -

download

public DownloadConnection download()
Loads the content from the set url source.


getHTTPStatusCode

public int getHTTPStatusCode()

getContentAsBytes

public byte[] getContentAsBytes()
Returns the loaded content in a byte[]. This can be accessed while a threaded download is still running.

Returns:

getContentAsString

public String getContentAsString()
Returns the content as a String encoded by the determined content encoding.

Returns:

isDownloadSuccessful

public boolean isDownloadSuccessful()
Returns true, if no error has occurred during the download.

Returns:

saveContentToFile

public boolean saveContentToFile(File file)
Saves the content into the given file. The destination file will be overwritten or created if possible.

Returns true if no error occurred.

Parameters:
file -

getContentEstimatedSize

public long getContentEstimatedSize()
Returns the size that was estimated to receive, by the http content size determined.

Returns:

getContentCurrentSize

public long getContentCurrentSize()
Returns the current size of the loaded amount of content.

Returns:

getContentSize

public long getContentSize()
Returns the current size of the downloaded content. If the download is in progress, this size is not available.

Returns:

getAuthenticationUser

public String getAuthenticationUser()

setAuthenticationUser

public void setAuthenticationUser(String authenticationUser)

getAuthenticationPassword

public String getAuthenticationPassword()

setAuthenticationPassword

public void setAuthenticationPassword(String authenticationPassword)

getDownloadManager

public DownloadManager getDownloadManager()

setDownloadManager

public void setDownloadManager(DownloadManager downloadManager)

getContentEncoding

public String getContentEncoding()

setContentEncoding

public void setContentEncoding(String contentEncoding)

getContentType

public String getContentType()

setContentType

public void setContentType(String contentType)

getTimeExpired

public long getTimeExpired()

getDownloadSpeed

public long getDownloadSpeed()

getStandardEncoding

public String getStandardEncoding()

setStandardEncoding

public void setStandardEncoding(String standardEncoding)

getUsedStringEncoding

public String getUsedStringEncoding()

setUsedStringEncoding

public void setUsedStringEncoding(String usedStringEncoding)

getUrl

public URL getUrl()

setDownloadMonitor

public DownloadConnection setDownloadMonitor(DownloadConnection.DownloadMonitor downloadMonitor)


Copyright © 2013. All Rights Reserved.