|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.net.Downloader
public class Downloader
Downloads a URL or URLCache object into a file. You can either download the URL synchronously using the provided static method or asynchronously in a separate thread. When doing the latter, you can first instanciate this Runnable, register a listener (in case you want to be notified upon completion) and then start the thread. If in a separate thread, you can also monitor the progress of the download using getReadSoFar() or cancel the download.
JDownloader| Nested Class Summary | |
|---|---|
static interface |
Downloader.Listener
|
| Field Summary | |
|---|---|
static int |
LENGTH_NOT_OBTAINED_YET
|
static int |
THREAD_NOT_STARTED_YET
|
static int |
UNKNOWN_LENGTH
|
| Constructor Summary | |
|---|---|
Downloader(URLCache uc,
File file)
|
|
Downloader(URLCache uc,
OutputStream out)
closes the stream on completion |
|
Downloader(URLCache uc,
OutputStream out,
boolean closeOnCompletion)
|
|
Downloader(URLCache uc,
OutputStream out,
boolean closeOnCompletion,
Monitor monitor)
|
|
Downloader(URL url,
File file)
|
|
Downloader(URL url,
OutputStream out)
closes the stream on completion |
|
| Method Summary | |
|---|---|
void |
addListener(Downloader.Listener listener)
|
void |
cancel()
cancels the current download; the listeners will be called with an IOException containing the message that canced() was called or that the input stream was closed |
static void |
download(URLCache uc,
File file)
synchronously downloads the given uc to the given file |
static void |
download(URLCache uc,
OutputStream out)
synchronously downloads the given url to the given output stream |
static void |
download(URLCache uc,
OutputStream out,
String user,
char[] password)
synchronously downloads the given url to the given output stream using basic authorization mechanism |
static void |
download(URL url,
File file)
synchronously downloads the given url to the given file |
static void |
download(URL url,
OutputStream out)
synchronously downloads the given url to the given output stream |
int |
getBufferSize()
|
boolean |
getCloseOnCompletion()
|
int |
getContentLength()
returns the content length or LENGTH_NOT_OBTAINED_YET if the download hasn't been started, yet;
UNKNOWN_LENGTH is returned if the length is unknown |
OutputStream |
getOutputStream()
|
int |
getReadSoFar()
returns the bytes that have been read by the thread; returns THREAD_NOT_STARTED_YET if the thread hasn't been started, yet |
URL |
getURL()
|
void |
run()
downloads the URL to the file and calls any listeners upon completion |
void |
setBasicAuthorization(String user,
char[] password)
if the user is non-null, the InputStream will be obtained via basic authorization |
void |
setBufferSize(int size)
|
void |
setCloseOnCompletion(boolean flag)
|
void |
setMonitor(Monitor monitor)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int UNKNOWN_LENGTH
public static final int LENGTH_NOT_OBTAINED_YET
public static final int THREAD_NOT_STARTED_YET
| Constructor Detail |
|---|
public Downloader(URL url,
File file)
throws FileNotFoundException
FileNotFoundException
public Downloader(URLCache uc,
File file)
throws FileNotFoundException
FileNotFoundException
public Downloader(URL url,
OutputStream out)
public Downloader(URLCache uc,
OutputStream out)
public Downloader(URLCache uc,
OutputStream out,
boolean closeOnCompletion)
public Downloader(URLCache uc,
OutputStream out,
boolean closeOnCompletion,
Monitor monitor)
| Method Detail |
|---|
public void setMonitor(Monitor monitor)
public void setBasicAuthorization(String user,
char[] password)
public void setCloseOnCompletion(boolean flag)
throws IllegalStateException
IllegalStateExceptionpublic boolean getCloseOnCompletion()
public static void download(URL url,
File file)
throws IOException
IOException
public static void download(URLCache uc,
File file)
throws IOException
IOException
public static void download(URL url,
OutputStream out)
throws IOException
IOException
public static void download(URLCache uc,
OutputStream out)
throws IOException
IOException
public static void download(URLCache uc,
OutputStream out,
String user,
char[] password)
throws IOException
IOExceptionpublic void cancel()
public void setBufferSize(int size)
throws IllegalStateException
IllegalStateExceptionpublic int getBufferSize()
public void run()
run in interface RunnableDownloader.Listener,
addListener(Downloader.Listener)public OutputStream getOutputStream()
public URL getURL()
public int getReadSoFar()
THREAD_NOT_STARTED_YET if the thread hasn't been started, yet
public int getContentLength()
LENGTH_NOT_OBTAINED_YET if the download hasn't been started, yet;
UNKNOWN_LENGTH is returned if the length is unknown
public void addListener(Downloader.Listener listener)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||