|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.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
DOCUMENT ME! |
| Field Summary | |
|---|---|
static int |
LENGTH_NOT_OBTAINED_YET
DOCUMENT ME! |
static int |
THREAD_NOT_STARTED_YET
DOCUMENT ME! |
static int |
UNKNOWN_LENGTH
DOCUMENT ME! |
| Constructor Summary | |
|---|---|
Downloader(URLCache uc,
java.io.File file)
Creates a new Downloader object. |
|
Downloader(URLCache uc,
java.io.OutputStream out)
closes the stream on completion |
|
Downloader(URLCache uc,
java.io.OutputStream out,
boolean closeOnCompletion)
Creates a new Downloader object. |
|
Downloader(java.net.URL url,
java.io.File file)
Creates a new Downloader object. |
|
Downloader(java.net.URL url,
java.io.OutputStream out)
closes the stream on completion |
|
| Method Summary | |
|---|---|
void |
addListener(Downloader.Listener listener)
DOCUMENT ME! |
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,
java.io.File file)
synchronously downloads the given uc to the given file |
static void |
download(URLCache uc,
java.io.OutputStream out)
synchronously downloads the given url to the given output stream |
static void |
download(java.net.URL url,
java.io.File file)
synchronously downloads the given url to the given file |
static void |
download(java.net.URL url,
java.io.OutputStream out)
synchronously downloads the given url to the given output stream |
int |
getBufferSize()
DOCUMENT ME! |
boolean |
getCloseOnCompletion()
DOCUMENT ME! |
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 |
java.io.OutputStream |
getOutputStream()
DOCUMENT ME! |
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 |
java.net.URL |
getURL()
DOCUMENT ME! |
void |
run()
downloads the URL to the file and calls any listeners upon completion |
void |
setBufferSize(int size)
DOCUMENT ME! |
void |
setCloseOnCompletion(boolean flag)
DOCUMENT ME! |
| 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(java.net.URL url,
java.io.File file)
throws java.io.FileNotFoundException
url - DOCUMENT ME!file - DOCUMENT ME!
java.io.FileNotFoundException - DOCUMENT ME!
public Downloader(URLCache uc,
java.io.File file)
throws java.io.FileNotFoundException
uc - DOCUMENT ME!file - DOCUMENT ME!
java.io.FileNotFoundException - DOCUMENT ME!
public Downloader(java.net.URL url,
java.io.OutputStream out)
public Downloader(URLCache uc,
java.io.OutputStream out)
public Downloader(URLCache uc,
java.io.OutputStream out,
boolean closeOnCompletion)
uc - DOCUMENT ME!out - DOCUMENT ME!closeOnCompletion - DOCUMENT ME!| Method Detail |
|---|
public void setCloseOnCompletion(boolean flag)
throws java.lang.IllegalStateException
flag - DOCUMENT ME!
java.lang.IllegalStateException - DOCUMENT ME!public boolean getCloseOnCompletion()
public static void download(java.net.URL url,
java.io.File file)
throws java.io.IOException
url - DOCUMENT ME!file - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
public static void download(URLCache uc,
java.io.File file)
throws java.io.IOException
uc - DOCUMENT ME!file - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
public static void download(java.net.URL url,
java.io.OutputStream out)
throws java.io.IOException
url - DOCUMENT ME!out - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
public static void download(URLCache uc,
java.io.OutputStream out)
throws java.io.IOException
uc - DOCUMENT ME!out - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!public void cancel()
public void setBufferSize(int size)
throws java.lang.IllegalStateException
size - DOCUMENT ME!
java.lang.IllegalStateException - DOCUMENT ME!public int getBufferSize()
public void run()
run in interface java.lang.Runnablejava.lang.IllegalStateException - DOCUMENT ME!Downloader.Listener,
addListener(Downloader.Listener)public java.io.OutputStream getOutputStream()
public java.net.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)
listener - DOCUMENT ME!
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||