|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.downloader.HTTPDownloader
Downloads a file over an HTTP connection. This class is as simple as possible. It does not deal with retries, prioritizing hosts, etc. Nor does it check whether a file already exists; it just writes over anything on disk.
It is necessary to explicitly initialize an HTTPDownloader with the connectTCP(..) followed by a connectHTTP(..) method. (Hence HTTPDownloader behaves much like Connection.) Typical use is as follows:
HTTPDownloader dl=new HTTPDownloader(host, port); dl.connectTCP(timeout); dl.connectHTTP(startByte, stopByte); dl.doDownload();LOCKING: _writtenGoodLocs and _goodLocs are both synchronized on _goodLocs LOCKING: _writtenBadLocs and _badLocs are both synchronized on _badLocs
Field Summary | |
static int |
BUF_LENGTH
The length of the buffer used in downloading. |
Constructor Summary | |
HTTPDownloader(RemoteFileDesc rfd,
java.io.File incompleteFile)
Creates an uninitialized client-side normal download. |
|
HTTPDownloader(java.net.Socket socket,
RemoteFileDesc rfd,
java.io.File incompleteFile)
Creates an uninitialized server-side push download. |
Method Summary | |
boolean |
browseEnabled()
|
boolean |
chatEnabled()
|
void |
connectHTTP(int start,
int stop,
boolean supportQueueing)
Sends a GET request using an already open socket, and reads all headers. |
void |
connectTCP(int timeout)
Initializes this by connecting to the remote host (in the case of a normal client-side download). |
void |
doDownload(VerifyingFile commonOutFile)
|
int |
getAmountRead()
|
int |
getAmountToRead()
|
float |
getAverageBandwidth()
Returns the overall averaged bandwidth between all calls of measureBandwidth |
java.lang.String |
getFileName()
|
byte[] |
getGUID()
|
long |
getIndex()
|
java.net.InetAddress |
getInetAddress()
Forces this to not write past the given byte of the file, if it has not already done so. |
int |
getInitialReadingPoint()
|
float |
getMeasuredBandwidth()
Returns the throughput of this in kilobytes/sec (KB/s) between the last two calls to measureBandwidth, or 0.0 if unknown. |
int |
getPort()
|
RemoteFileDesc |
getRemoteFileDesc()
Returns the RemoteFileDesc passed to this' constructor. |
int |
getTotalAmountRead()
|
java.lang.String |
getVendor()
|
boolean |
isHTTP11()
returns true if we have think that the server supports HTTP1.1 |
boolean |
isPush()
Returns true iff this is a push download. |
void |
measureBandwidth()
Measures the data throughput since the last call to measureBandwidth. |
static java.lang.String |
readServer(java.lang.String serverHeader)
Reads the Server header. |
void |
stop()
Stops this immediately. |
void |
stopAt(int stop)
Instructs this stop just before reading the given byte. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int BUF_LENGTH
Constructor Detail |
public HTTPDownloader(RemoteFileDesc rfd, java.io.File incompleteFile)
rfd
- complete information for the file to download, including
host address and portincompleteFile
- the temp file to use while downloading, which need
not exist.public HTTPDownloader(java.net.Socket socket, RemoteFileDesc rfd, java.io.File incompleteFile)
socket
- the socket to download from. The "GIV..." line must
have been read from socket. HTTP headers may not have been read or
buffered -- this can be nullrfd
- complete information for the file to download, including
host address and portincompleteFile
- the temp file to use while downloading, which need
not exist.Method Detail |
public void connectTCP(int timeout) throws java.io.IOException
timeout
- the timeout to use for connecting, in milliseconds,
or zero if no timeout
CantConnectException
- could not establish a TCP connection
java.io.IOException
public void connectHTTP(int start, int stop, boolean supportQueueing) throws java.io.IOException, TryAgainLaterException, FileNotFoundException, NotSharingException, QueuedException, RangeNotAvailableException, ProblemReadingHeaderException, UnknownCodeException
start
- The byte at which the HTTPDownloader should beginstop
- the index just past the last byte to read;
stop-1 is the last byte the HTTPDownloader should download
TryAgainLaterException
- the host is busy
FileNotFoundException
- the host doesn't recognize the file
NotSharingException
- the host isn't sharing files (BearShare)
java.io.IOException
- miscellaneous error
QueuedException
- uploader has queued us
RangeNotAvailableException
- uploader has ranges
other than requested
ProblemReadingHeaderException
- could not parse headers
UnknownCodeException
- unknown response codepublic static java.lang.String readServer(java.lang.String serverHeader)
public void doDownload(VerifyingFile commonOutFile) throws java.io.IOException
java.io.IOException
public void stop()
public void stopAt(int stop)
stop
- the index just past the last byte to read;
stop-1 is the index of the last byte to be downloadedpublic int getInitialReadingPoint()
public int getAmountRead()
public int getTotalAmountRead()
public int getAmountToRead()
public java.net.InetAddress getInetAddress()
public boolean chatEnabled()
public boolean browseEnabled()
public java.lang.String getVendor()
public long getIndex()
public java.lang.String getFileName()
public byte[] getGUID()
public int getPort()
public RemoteFileDesc getRemoteFileDesc()
public boolean isPush()
public boolean isHTTP11()
public void measureBandwidth()
BandwidthTracker
measureBandwidth
in interface BandwidthTracker
public float getMeasuredBandwidth() throws InsufficientDataException
BandwidthTracker
getMeasuredBandwidth
in interface BandwidthTracker
InsufficientDataException
public float getAverageBandwidth()
BandwidthTracker
getAverageBandwidth
in interface BandwidthTracker
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |