Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/main/java/me/piitex/os/FileDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,16 @@ public boolean cancelDownload(String fileUrl) {
return wasRunning;
}

public long getRemoteFileSize(String fileUrl) {
try {
URL url = new URL(fileUrl);
URLConnection connection = url.openConnection();
connection.setConnectTimeout(5000);
if (connection instanceof HttpURLConnection) {
((HttpURLConnection) connection).setRequestMethod("HEAD");
}
connection.connect();

return connection.getContentLengthLong();
} catch (Exception e) {
logger.error("Error fetching remote file size", e);
return -1;
public long getRemoteFileSize(String fileUrl) throws IOException {
URL url = new URL(fileUrl);
URLConnection connection = url.openConnection();
connection.setConnectTimeout(5000);
if (connection instanceof HttpURLConnection) {
((HttpURLConnection) connection).setRequestMethod("HEAD");
}
connection.connect();

return connection.getContentLengthLong();
}

public void addDownloadListener(DownloadListener listener) {
Expand Down