public final class GetTask extends TransportTask
Transporter.get(GetTask)
Constructor and Description |
---|
GetTask(URI location)
Creates a new task for the specified remote resource.
|
Modifier and Type | Method and Description |
---|---|
Map<String,String> |
getChecksums()
Gets the checksums which the remote repository advertises for the resource.
|
byte[] |
getDataBytes()
Gets the data that was downloaded into memory.
|
File |
getDataFile()
Gets the file (if any) where the downloaded data should be stored.
|
String |
getDataString()
Gets the data that was downloaded into memory as a string.
|
long |
getResumeOffset()
Gets the byte offset within the resource from which the download should resume if supported.
|
OutputStream |
newOutputStream()
Opens an output stream to store the downloaded data.
|
OutputStream |
newOutputStream(boolean resume)
Opens an output stream to store the downloaded data.
|
GetTask |
setChecksum(String algorithm,
String value)
Sets a checksum which the remote repository advertises for the resource.
|
GetTask |
setDataFile(File dataFile)
Sets the file where the downloaded data should be stored.
|
GetTask |
setDataFile(File dataFile,
boolean resume)
Sets the file where the downloaded data should be stored.
|
GetTask |
setListener(TransportListener listener)
Sets the listener that is to be notified during the transfer.
|
String |
toString() |
getListener, getLocation
public OutputStream newOutputStream() throws IOException
getDataFile()
, this stream writes
either to a file on disk or a growable buffer in memory. It's the responsibility of the caller to close the
provided stream.null
. The stream is unbuffered.IOException
- If the stream could not be opened.public OutputStream newOutputStream(boolean resume) throws IOException
getDataFile()
, this stream writes
either to a file on disk or a growable buffer in memory. It's the responsibility of the caller to close the
provided stream.resume
- true
if the download resumes from the byte offset given by getResumeOffset()
,
false
if the download starts at the first byte of the resource.null
. The stream is unbuffered.IOException
- If the stream could not be opened.public File getDataFile()
null
if the data will be buffered in memory.public GetTask setDataFile(File dataFile)
dataFile
- The file to store the downloaded data, may be null
to store the data in memory.null
.public GetTask setDataFile(File dataFile, boolean resume)
resume
argument and the capabilities of the transporter.
Unless the caller can reasonably expect the resource to be small, use of a data file is strongly recommended to
avoid exhausting heap memory during the download.dataFile
- The file to store the downloaded data, may be null
to store the data in memory.resume
- true
to request resuming a previous download attempt, starting from the current length of
the data file, false
to download the resource from its beginning.null
.public long getResumeOffset()
0
for a full download from the start of the
resource, never negative.public byte[] getDataBytes()
getDataFile()
is null
as otherwise the downloaded data has been written directly to disk.null
.public String getDataString()
getDataFile()
is null
as
otherwise the downloaded data has been written directly to disk.null
.public GetTask setListener(TransportListener listener)
listener
- The listener to notify of progress, may be null
.null
.public Map<String,String> getChecksums()
MessageDigest
) and the values are hexadecimal representations of
the corresponding value. Note: This is optional data that a transporter may return if the underlying
transport protocol provides metadata (e.g. HTTP headers) along with the actual resource data.null
.public GetTask setChecksum(String algorithm, String value)
algorithm
- The name of the checksum algorithm (e.g. "SHA-1"
, cf.
MessageDigest
), may be null
.value
- The hexadecimal representation of the checksum, may be null
.null
.Copyright © 2010–2017 The Apache Software Foundation. All rights reserved.