Simple HTTP downloads.
- Java 99.9%
- CSS 0.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo | ||
| com.io7m.jdownload.core | ||
| com.io7m.jdownload.tests | ||
| src/site/resources | ||
| .gitignore | ||
| .gitmodules | ||
| doc7m-books.json | ||
| pom.xml | ||
| README-CHANGES.xml | ||
| README-LICENSE.txt | ||
| README.in | ||
| README.md | ||
jdownload
jdownload
The jdownload package implements a trivial wrapper around the JDK HTTP client
providing downloads, checksum verification, and transfer statistics.
Features
- Trivial HTTP file downloader providing transfer statistics.
- Automatic checksum verification for downloads.
- Low dependency: Requires Java 21 and uses SLF4J for logging.
- High coverage test suite.
- OSGi-ready.
- JPMS-ready.
- ISC license.
Usage
HttpClient client;
URI targetURI;
Path outputFile;
Path outputFileTemp;
Download a file from targetURI, writing the data temporarily to
outputFileTemp and then atomically replacing outputFile with
outputFileTemp if the download succeeds:
final var result =
JDownloadRequests.builder(client, targetURI, outputFile, outputFileTemp)
.build()
.execute();
Perform the same download operation, but receive transfer statistics during the download:
Consumer<STTransferStatistics> receiver;
final var result =
JDownloadRequests.builder(client, targetURI, outputFile, outputFileTemp)
.setTransferStatisticsReceiver(receiver)
.build()
.execute();
Perform the same download operation, but reject the download if the resulting file does not match the given checksum:
final byte[] checksum =
HexFormat.of()
.parseHex("2d8bd7d9bb5f85ba643f0110d50cb506a1fe439e769a22503193ea6046bb87f7");
final var result =
JDownloadRequests.builder(client, targetURI, outputFile, outputFileTemp)
.setChecksumStatically("SHA-256", checksum)
.build()
.execute();
Perform the same download operation, but reject the download if the resulting file does not match the checksum obtained from the given checksum URI:
Consumer<STTransferStatistics> receiver;
Path checksumFile;
Path checksumFileTemp;
URI checksumURI;
final var result =
JDownloadRequests.builder(client, targetURI, outputFile, outputFileTemp)
.setChecksumFromURL(checksumURI, "SHA-256", checksumFile, checksumFileTemp, receiver)
.build()
.execute();
