de.scheisseichfindemalkeinen.pic
Class Pic

java.lang.Object
  extended by de.scheisseichfindemalkeinen.pic.Pic
All Implemented Interfaces:
IDownloadListener, java.lang.Runnable

public class Pic
extends java.lang.Object
implements java.lang.Runnable, IDownloadListener

Thread which does the download This class is called Pic, because it is an shortcut for Picture. And as is started programming this program it was only for downloading pictures. But this class can not only download pictures, all kind of files can be downloaded. And no, i'm not willing to rename this class ;-)


Field Summary
static int ABORTING
          Download failed
static int COMPLETE
          Download is complete
static int DOWNLOADING
          Download is downloading
static int FAILED
          Download failed
static int FAILED_FILE_NOT_EXIST
          Download failed
static int SLEEPING
          Download is sleeping
static java.lang.String[] STATUS_T
          Strings for status of the download
static int WAITING
          Download is waiting for a free slot
 
Constructor Summary
Pic(java.lang.String urlContainer, java.lang.String targetFilename, java.lang.String targetPath)
          Constructor
 
Method Summary
 void addPicListener(IPicListener listener)
          Adds a listener
static java.util.regex.Pattern compileContentDispositionFilenamePattern()
          This method compiles the pattern for the filename in content-disposition
static java.lang.String createDirectory(java.io.File dir, java.lang.String targetPath)
          Creates a directory If there is already a file of the same name, a number is added at the end of the foldername.
 boolean downloadAllowed()
          Allows a Pic to start the download The Pic should then return true, if it has really started the pic or false if not.
 java.lang.String getContainerURL()
          Returns the Container-URL
 java.lang.String getErrMsg()
          Returns the Error-Message
 int getFailedCount()
          Returns the count of failures
 long getLastModified()
          Returns the timestamp of last modification of the file
 long getSize()
          Returns the filesize
 int getStatus()
          Returns the status Available states: Pic.SLEEPING Pic.WAITING Pic.DOWNLOADING Pic.COMPLETE Pic.FAILED Pic.FAILED_FILE_NOT_EXIST
 java.lang.String getStatusText()
          Returns the status-text for the actual status of the download
 java.lang.String getTarget()
          Returns path and filename Note: There is no set method for this, because path and filename are hold seperated in the class.
 java.lang.String getTargetFilename()
          Returns the filename
 java.lang.String getTargetPath()
          Returns the path
 java.lang.String getThreadURL()
          Returns the ThreadURL (Referrer)
 java.lang.String getThumb()
          Returns the Thumbnail-URL
 boolean isDeactivated()
          Returns if the download is deactivated or not
 boolean isFixedLastModified()
          Returns if lastModified is fixed or not
 boolean isFixedTargetFilename()
          Returns if the filename is fixed or not
 boolean isRenameWithContentDisposition()
          Returns the renameWithContentDisposition
static java.io.File moveFile(java.io.File fileToMove, java.io.File newPath)
          This method moves a file.
static java.io.File moveFileToSubdir(java.lang.String filename, java.lang.String path, java.lang.String subdirName)
          BilderHerunterlader provides options, where the user can set, that files of a specific size-range should be moved to a specific subdirectory.
 void progressBarChanged(long val, java.lang.String s)
          This method fires the progressBarChanged-Method on all listeners
 void removeAllListener()
          Removes all listeners
 void removePicListener(IPicListener listener)
          Removes a listener
 void run()
           
 void setDeactivated(boolean deactivated)
          Sets the download to be deactivated or not This method fires deactivatedChange-Method on all listeners and updates the object in the database.
 void setFixedLastModified(boolean fixedLastModified)
          Sets the last modified timestamp to be fixed.
 void setFixedTargetFilename(boolean fixedTargetFilename)
          Sets the filename to be fixed.
 void setLastModified(long lastModified)
          Set the timestamp of last modification of the file
 void setRecalcutateRate(boolean recalcutateRate)
          Sets the recalculate flag to true or false.
 void setRenameWithContentDisposition(boolean renameWithContentDisposition)
          Sets the renameWithContentDisposition
 void setStatus(int status)
          Attention: You should not use the method from other classes.
 void setTargetFilename(java.lang.String targetFilename)
          Sets the filename If the filename was set to be fixed before and the argument for targetFilename is here an empty string, the filename is set to be not fixed anymore.
 void setTargetPath(java.lang.String targetPath)
          Sets the Path
 void setThreadURL(java.lang.String threadURL)
          Set the threadURL (Referrer)
 void setThumb(java.lang.String thumb)
          Set the Thumbnail-URL
 void startDownload()
          Start the download
 void stopDownload()
          Stop the download This does not immediately stop the download, it only changes the stop-flag to true and the download method will stop if this flag is true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SLEEPING

public static final int SLEEPING
Download is sleeping

See Also:
Constant Field Values

WAITING

public static final int WAITING
Download is waiting for a free slot

See Also:
Constant Field Values

DOWNLOADING

public static final int DOWNLOADING
Download is downloading

See Also:
Constant Field Values

COMPLETE

public static final int COMPLETE
Download is complete

See Also:
Constant Field Values

FAILED

public static final int FAILED
Download failed

See Also:
Constant Field Values

ABORTING

public static final int ABORTING
Download failed

See Also:
Constant Field Values

FAILED_FILE_NOT_EXIST

public static final int FAILED_FILE_NOT_EXIST
Download failed

See Also:
Constant Field Values

STATUS_T

public static final java.lang.String[] STATUS_T
Strings for status of the download

Constructor Detail

Pic

public Pic(java.lang.String urlContainer,
           java.lang.String targetFilename,
           java.lang.String targetPath)
Constructor

Parameters:
urlContainer - Container-URL
targetFilename - Filename
targetPath - Target path
Method Detail

startDownload

public void startDownload()
Start the download


stopDownload

public void stopDownload()
Stop the download This does not immediately stop the download, it only changes the stop-flag to true and the download method will stop if this flag is true. When the download is waiting for the parsed URL, this could take some time...


run

public void run()
Specified by:
run in interface java.lang.Runnable

progressBarChanged

public void progressBarChanged(long val,
                               java.lang.String s)
This method fires the progressBarChanged-Method on all listeners

Parameters:
val - Value
s - Progressbar-Text

addPicListener

public void addPicListener(IPicListener listener)
Adds a listener

Parameters:
listener - Listener

removePicListener

public void removePicListener(IPicListener listener)
Removes a listener

Parameters:
listener - Listener

removeAllListener

public void removeAllListener()
Removes all listeners


downloadAllowed

public boolean downloadAllowed()
Description copied from interface: IDownloadListener
Allows a Pic to start the download The Pic should then return true, if it has really started the pic or false if not. If it does return a wrong value, QueueData would start too many downloads or would not increase the counter and would not increase the slots used.

Specified by:
downloadAllowed in interface IDownloadListener
Returns:
True/False

createDirectory

public static java.lang.String createDirectory(java.io.File dir,
                                               java.lang.String targetPath)
Creates a directory If there is already a file of the same name, a number is added at the end of the foldername. This method returns a File-Object which contains path. If the directory could not be created null is returned

Parameters:
dir - Directory
targetPath - Path
Returns:
Directory

moveFileToSubdir

public static java.io.File moveFileToSubdir(java.lang.String filename,
                                            java.lang.String path,
                                            java.lang.String subdirName)
BilderHerunterlader provides options, where the user can set, that files of a specific size-range should be moved to a specific subdirectory. So this method moves the file. The method will check if there is already a file of same name existing and if so, a number is added to the filename. This is done by call the createFile-Method. The method returns a File-Object which contains path and filename, of where the file was moved. If the file could not be moved null is returned.

Parameters:
filename - Filename
path - Path
subdirName - Name of the subdir
Returns:
File
See Also:
createDirectory(File, String)

moveFile

public static java.io.File moveFile(java.io.File fileToMove,
                                    java.io.File newPath)
This method moves a file. The method will check if there is already a file of same name existing and if so, a number is added to the filename. This is done by call the createFile-Method. The method returns a File-Object which contains path and filename, of where the file was moved. If the file could not be moved null is returned.

Parameters:
fileToMove - Filename
newPath - Path
Returns:
File
See Also:
createDirectory(File, String)

compileContentDispositionFilenamePattern

public static java.util.regex.Pattern compileContentDispositionFilenamePattern()
This method compiles the pattern for the filename in content-disposition

Returns:
Pattern

setRecalcutateRate

public void setRecalcutateRate(boolean recalcutateRate)
Sets the recalculate flag to true or false. If it is set to true, the download class knows that it has to recalculate the download rate.

Parameters:
recalcutateRate - Recalculate flag
See Also:
CalculateRateTimerTask

getContainerURL

public java.lang.String getContainerURL()
Returns the Container-URL

Specified by:
getContainerURL in interface IDownloadListener
Returns:
Container-URL

getTarget

public java.lang.String getTarget()
Returns path and filename Note: There is no set method for this, because path and filename are hold seperated in the class.

Returns:
Path and filename

getSize

public long getSize()
Returns the filesize

Returns:
Filesize

getStatusText

public java.lang.String getStatusText()
Returns the status-text for the actual status of the download

Returns:
Statustext

getStatus

public int getStatus()
Returns the status Available states: Pic.SLEEPING Pic.WAITING Pic.DOWNLOADING Pic.COMPLETE Pic.FAILED Pic.FAILED_FILE_NOT_EXIST

Returns:
Status

setStatus

public void setStatus(int status)
Attention: You should not use the method from other classes. It could produce errors if set while download is running are so on. I used this method only from other classes when reading them from the database, because if the program was crashed the object could have DOWNLOADING as status and that is terrible. Sets the status of the download Available states: Pic.SLEEPING Pic.WAITING Pic.DOWNLOADING Pic.COMPLETE Pic.FAILED Pic.FAILED_FILE_NOT_EXIST If the status-argument is not one of those, the method will not set anything! This method fires the statusChanged-Method on all listeners.

Parameters:
status - Status

getLastModified

public long getLastModified()
Returns the timestamp of last modification of the file

Returns:
Last modification timestamp

setLastModified

public void setLastModified(long lastModified)
Set the timestamp of last modification of the file

Parameters:
lastModified - Last modification timestamp

isFixedLastModified

public boolean isFixedLastModified()
Returns if lastModified is fixed or not

Returns:
Fixed lastModified

setFixedLastModified

public void setFixedLastModified(boolean fixedLastModified)
Sets the last modified timestamp to be fixed. Only if this is set to true, the download-class will set the last modified timestamp on the file.

Parameters:
fixedLastModified - Fixed lastModified

getTargetPath

public java.lang.String getTargetPath()
Returns the path

Returns:
Path

setTargetPath

public void setTargetPath(java.lang.String targetPath)
Sets the Path

Parameters:
targetPath - Path

getTargetFilename

public java.lang.String getTargetFilename()
Returns the filename

Returns:
Filename

setTargetFilename

public void setTargetFilename(java.lang.String targetFilename)
Sets the filename If the filename was set to be fixed before and the argument for targetFilename is here an empty string, the filename is set to be not fixed anymore. This methods fires the targetChanged-Method on all listeners

Parameters:
targetFilename - Filename

getThumb

public java.lang.String getThumb()
Returns the Thumbnail-URL

Returns:
Thumbnail-URL

setThumb

public void setThumb(java.lang.String thumb)
Set the Thumbnail-URL

Parameters:
thumb - Thumbnail-URL

isFixedTargetFilename

public boolean isFixedTargetFilename()
Returns if the filename is fixed or not

Returns:
the fixedTargetFilename
See Also:
setFixedTargetFilename(boolean)

setFixedTargetFilename

public void setFixedTargetFilename(boolean fixedTargetFilename)
Sets the filename to be fixed. So the download or the hostclasses are not overwriting it! Note: When adding URLs to BilderHerunterlader, then the filenames are most only grabbed from the URL. But maybe hostclasses has methods to restore the original filename or get a better one. If not, when the direct link is known by the download, the download-class could, grab a nicer filename, as the ones in the Download-Selection-Dialog. So a filename should only set to fixed, when a user changes the filename in the GUI.

Parameters:
fixedTargetFilename - Fixed filename

getThreadURL

public java.lang.String getThreadURL()
Returns the ThreadURL (Referrer)

Returns:
ThreadURL (Referrer)

setThreadURL

public void setThreadURL(java.lang.String threadURL)
Set the threadURL (Referrer)

Parameters:
threadURL - ThreadURL (Referrer)

getFailedCount

public int getFailedCount()
Returns the count of failures

Returns:
Count of failures

isDeactivated

public boolean isDeactivated()
Returns if the download is deactivated or not

Returns:
Deactivated

setDeactivated

public void setDeactivated(boolean deactivated)
Sets the download to be deactivated or not This method fires deactivatedChange-Method on all listeners and updates the object in the database. But does not commit the database!

Parameters:
deactivated - Deactivated

getErrMsg

public java.lang.String getErrMsg()
Returns the Error-Message

Returns:
Error-Message

isRenameWithContentDisposition

public boolean isRenameWithContentDisposition()
Returns the renameWithContentDisposition

Returns:
renameWithContentDisposition

setRenameWithContentDisposition

public void setRenameWithContentDisposition(boolean renameWithContentDisposition)
Sets the renameWithContentDisposition

Parameters:
renameWithContentDisposition - renameWithContentDisposition