public final class GetTask extends TransportTask
Transporter.get(GetTask)
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.String> |
checksums |
private java.io.ByteArrayOutputStream |
dataBytes |
private java.io.File |
dataFile |
private boolean |
resume |
EMPTY, NOOP
Constructor and Description |
---|
GetTask(java.net.URI location)
Creates a new task for the specified remote resource.
|
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.String,java.lang.String> |
getChecksums()
Gets the checksums which the remote repository advertises for the resource.
|
byte[] |
getDataBytes()
Gets the data that was downloaded into memory.
|
java.io.File |
getDataFile()
Gets the file (if any) where the downloaded data should be stored.
|
java.lang.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.
|
java.io.OutputStream |
newOutputStream()
Opens an output stream to store the downloaded data.
|
java.io.OutputStream |
newOutputStream(boolean resume)
Opens an output stream to store the downloaded data.
|
GetTask |
setChecksum(java.lang.String algorithm,
java.lang.String value)
Sets a checksum which the remote repository advertises for the resource.
|
GetTask |
setDataFile(java.io.File dataFile)
Sets the file where the downloaded data should be stored.
|
GetTask |
setDataFile(java.io.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.
|
java.lang.String |
toString() |
getListener, getLocation, setLocation
private java.io.File dataFile
private boolean resume
private java.io.ByteArrayOutputStream dataBytes
private java.util.Map<java.lang.String,java.lang.String> checksums
public GetTask(java.net.URI location)
location
- The relative location of the resource in the remote repository, must not be null
.public java.io.OutputStream newOutputStream() throws java.io.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.java.io.IOException
- If the stream could not be opened.public java.io.OutputStream newOutputStream(boolean resume) throws java.io.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.java.io.IOException
- If the stream could not be opened.public java.io.File getDataFile()
null
if the data will be buffered in memory.public GetTask setDataFile(java.io.File dataFile)
dataFile
- The file to store the downloaded data, may be null
to store the data in memory.null
.public GetTask setDataFile(java.io.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 java.lang.String getDataString()
getDataFile()
is null
as
otherwise the downloaded data has been written directly to disk.null
.public GetTask setListener(TransportListener listener)
setListener
in class TransportTask
listener
- The listener to notify of progress, may be null
.null
.public java.util.Map<java.lang.String,java.lang.String> getChecksums()
MessageDigest.getInstance(String)
) 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(java.lang.String algorithm, java.lang.String value)
algorithm
- The name of the checksum algorithm (e.g. "SHA-1"
, cf.
MessageDigest.getInstance(String)
), may be null
.value
- The hexadecimal representation of the checksum, may be null
.null
.public java.lang.String toString()
toString
in class java.lang.Object