`Импорт java.io.*;
import java.net.httpurlconnection;
import java.net.url; < /p>
public class resumabledThanThloader { /p> p> p> p> p> p> p> p> p> psumbledathlorulter { /p>
public class
Код: Выделить всё
public static void downloadFile(String fileURL, String savePath) throws IOException {
File file = new File(savePath);
File rangeFile = new File(savePath + ".range");
long downloadedBytes = 0;
if (rangeFile.exists()) {
try (BufferedReader reader = new BufferedReader(new FileReader(rangeFile))) {
downloadedBytes = Long.parseLong(reader.readLine());
}
}
HttpURLConnection conn = (HttpURLConnection) new URL(fileURL).openConnection();
conn.setRequestProperty("Range", "bytes=" + downloadedBytes + "-");
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_PARTIAL || responseCode == HttpURLConnection.HTTP_OK) {
try (InputStream in = conn.getInputStream();
RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
raf.seek(downloadedBytes);
byte[] buffer = new byte[8192];
int bytesRead;
long totalDownloaded = downloadedBytes;
while ((bytesRead = in.read(buffer)) != -1) {
raf.write(buffer, 0, bytesRead);
totalDownloaded += bytesRead;
// Save progress
try (BufferedWriter writer = new BufferedWriter(new FileWriter(rangeFile))) {
writer.write(String.valueOf(totalDownloaded));
}
}
// Cleanup if complete
if (totalDownloaded == conn.getHeaderFieldLong("Content-Length", -1) + downloadedBytes) {
rangeFile.delete();
System.out.println("Download complete.");
} else {
System.out.println("Download interrupted. Progress saved.");
}
}
} else {
System.out.println("Server did not support partial content. Response code: " + responseCode);
}
}
public static void main(String[] args) throws IOException {
String fileURL = "https://example.com/largefile.zip";
String savePath = "largefile.zip";
downloadFile(fileURL, savePath);
}
Я хочу скрыть некоторые услуги, такие как администратор в Swagger UI, но сохраните их в файле Swagger json. Предотвращение всех запросов во время первого действия
Подробнее здесь: https://stackoverflow.com/questions/797 ... le-in-java