|
1 | 1 | # JDL |
2 | 2 | A java library to download files and process the download speed,progress and other things |
| 3 | + |
| 4 | +Features: |
| 5 | + |
| 6 | +- Download files easy |
| 7 | +- Check download speed |
| 8 | +- Check download progress |
| 9 | +- Directly cast download objects |
| 10 | +- Download Text |
| 11 | +- Convert file sizes (MB;GB;KB...) |
| 12 | + |
| 13 | +# Download: |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +# Getting Started: |
| 18 | + |
| 19 | +# Download File: |
| 20 | + |
| 21 | +``` |
| 22 | +Downloader downloader = new Downloader(false); |
| 23 | +downloader.downloadFileToLocation("https://github.com/MrMarnic/JIconExtract/releases/download/1.0/JIconExtract.jar","C:\\Downloads\\download.zip"); |
| 24 | +``` |
| 25 | +# Add Handler (Check Speed,progress...): |
| 26 | + |
| 27 | +``` |
| 28 | +Downloader downloader = new Downloader(false); |
| 29 | +downloader.setDownloadHandler(new CombinedSpeedProgressDownloadHandler(downloader) { |
| 30 | + @Override |
| 31 | + public void onDownloadSpeedProgress(int downloaded, int maxDownload, int percent, int bytesPerSec) { |
| 32 | + System.out.println(SizeUtil.toMBFB(bytesPerSec)+"/s " + percent + "%"); |
| 33 | + } |
| 34 | +
|
| 35 | + @Override |
| 36 | + public void onDownloadFinish() { |
| 37 | + super.onDownloadFinish(); |
| 38 | + System.out.println("Download finished"); |
| 39 | + } |
| 40 | + }); |
| 41 | +downloader.downloadFileToLocation("https://github.com/MrMarnic/JIconExtract/releases/download/1.0/JIconExtract.jar","C:\\Downloads\\download.zi"); |
| 42 | +``` |
| 43 | + |
| 44 | +# Handler |
| 45 | + |
| 46 | +- DownloadSpeedDownloadHandler (check speed) |
| 47 | +- DownloadProgressDownloadHandler (check progress) |
| 48 | +- CombinedSpeedProgressDownloadHandler (check speed and progress) |
| 49 | + |
| 50 | +# Create own Handler |
| 51 | + |
| 52 | +``` |
| 53 | +public class ExampleDownloadHandler extends DownloadHandler{ |
| 54 | +
|
| 55 | + public DownloadProgressDownloadHandler(Downloader downloader) { |
| 56 | + super(downloader); |
| 57 | + } |
| 58 | +
|
| 59 | +
|
| 60 | + @Override |
| 61 | + public void onDownloadStart() { |
| 62 | + |
| 63 | + } |
| 64 | +
|
| 65 | + @Override |
| 66 | + public void onDownloadFinish() { |
| 67 | + timer.cancel(); |
| 68 | + } |
| 69 | +
|
| 70 | + @Override |
| 71 | + public void onDownloadError() { |
| 72 | + timer.cancel(); |
| 73 | + } |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +# Convert File sizes |
| 78 | + |
| 79 | +Syntax: SizeUtil.toMBFB() = toMegaBytesFromBytes |
| 80 | + SizeUtil.toGBFB() = toGigiaBytesFromBytes |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +``` |
| 85 | +double mb = SizeUtil.toMBFB(2000000000); |
| 86 | +double kb = SizeUtil.toKBFB(1000000); |
| 87 | +``` |
0 commit comments