BAEL-4856 Remove BinaryFileDownloadApplication.java and use correct indentation

This commit is contained in:
Iulian Manda 2021-06-03 18:13:09 +03:00
parent 9e369a8258
commit 91dfad8bec
5 changed files with 117 additions and 149 deletions

View File

@ -1,26 +0,0 @@
package com.baeldung.okhttp.download;
import okhttp3.OkHttpClient;
import java.io.FileOutputStream;
public class BinaryFileDownloadApplication {
public static void main(String[] args) {
String url = args[0];
String file = args[1];
try (BinaryFileDownloader downloader = new BinaryFileDownloader(new OkHttpClient(),
new BinaryFileWriter(new FileOutputStream(file)))) {
long downloadSize = downloader.download(url);
double downloadSizeInMB = convertToMB(downloadSize);
System.out.printf("Successfully downloaded file %s from %s. Total size %.2fMB%n", file, url, downloadSizeInMB);
} catch (Exception ex) {
System.err.printf("Could not download file %s from %s. %nError: %s%n", file, url, ex);
}
}
private static double convertToMB(double downloadSize) {
return downloadSize / (1024.0 * 1024.0);
}
}

View File

@ -68,13 +68,7 @@ public class BinaryFileDownloaderUnitTest {
@NotNull
private Response createResponse(String url, ResponseBody body) {
Request request = new Request.Builder().url(url).build();
return new Response.Builder()
.code(200)
.request(request)
.protocol(Protocol.HTTP_2)
.message("Message")
.body(body)
.build();
return new Response.Builder().code(200).request(request).protocol(Protocol.HTTP_2).message("Message").body(body).build();
}
}