public class DownloadReusableResponse extends ReusableResponse<InputStream>
ReusableResponse for handling file download responses.
Provides convenience methods for saving files to the local file system.
ReusableResponse.Skipped<K>| Constructor and Description |
|---|
DownloadReusableResponse(javax.ws.rs.core.Response response,
String filename)
Creates a new download response wrapper.
|
| Modifier and Type | Method and Description |
|---|---|
File |
save()
Saves the downloaded content to a local file using default options.
|
File |
save(File destinationDir,
Map<String,Object> options)
Saves the downloaded content to a new file inside the given directory.
|
File |
save(Map<String,Object> options)
Saves the downloaded content to a local file using the given options.
|
File |
save(String destinationDir)
Saves the downloaded content to a file in the specified directory using
default options.
|
File |
save(String destinationDir,
Map<String,Object> options)
Saves the downloaded content to a file in the specified directory using the
given options.
|
getBody, getBody, getResponse, getStatus, ok, skipped, success, toStringpublic DownloadReusableResponse(javax.ws.rs.core.Response response,
String filename)
response - the underlying JAX-RS responsepublic File save()
Because no destination directory is given, the file is written to the
system temporary directory (the location reported by the
java.io.tmpdir system property). The file is saved under the
original filename and the method fails if a file with that name
already exists there.
RuntimeException - if the content cannot be written to disksave(File, Map)public File save(File destinationDir, Map<String,Object> options)
By default the file is written using the original filename, and the
method fails if a file with that name already exists. This behavior can be
changed through the options map (see below).
The caller owns the returned file and is responsible for deleting it once it is no longer needed.
destinationDir - the directory where the file should be saved; must be
an existing directoryoptions - optional behavior overrides; may be null or empty.
Recognized keys:
String) — the name to
save the file as, instead of the original
filename.boolean, default false)
— controls what happens on a name collision.
When false, the method throws if the target
name already exists. When true, both files
are kept: a unique suffix is appended so the existing
file is never overwritten.autoRename is
true and a collision occurrs, the returned filename will
differ from the requested one (a suffix is added to keep it unique),
so callers should rely on the returned File rather than
reconstructing the path.RuntimeException - if destinationDir is null, is not an
existing directory, if the target file already exists
and autoRename is false, or if the
content cannot be written to diskpublic File save(Map<String,Object> options)
Because no destination directory is given, the file is written to the
system temporary directory (the location reported by the
java.io.tmpdir system property). The options map controls
the target name and collision behavior — see save(File, Map)
for the full list of recognized keys.
options - optional behavior overrides; may be null or empty.
See save(File, Map) for recognized keys.RuntimeException - if the content cannot be written to disksave(File, Map)public File save(String destinationDir)
The file is saved under the original filename and the method fails
if a file with that name already exists in the directory. If
destinationDir is null, the file is written to the system
temporary directory (the location reported by the java.io.tmpdir
system property) instead.
The caller owns the returned file and is responsible for deleting it once it is no longer needed.
destinationDir - the path of the directory where the file should be
saved; if null, the system temporary
directory is usedRuntimeException - if the content cannot be written to disk or the
destination directory is invalidsave(File, Map)public File save(String destinationDir, Map<String,Object> options)
If destinationDir is null, the file is written to the system
temporary directory (the location reported by the java.io.tmpdir
system property) instead. The options map controls the target name
and collision behavior — see save(File, Map) for the full
list of recognized keys.
The caller owns the returned file and is responsible for deleting it once it is no longer needed.
destinationDir - the path of the directory where the file should be
saved; if null, the system temporary
directory is usedoptions - optional behavior overrides; may be null or
empty. See save(File, Map) for recognized keys.RuntimeException - if the content cannot be written to disk or the
destination directory is invalidsave(File, Map)Copyright © 2021 Cult Of Bits, lda