Package com.marcpg.libpg.web
Class Downloads
java.lang.Object
com.marcpg.libpg.web.Downloads
Provides utility methods for downloading files in various ways.
Please keep in mind that these methods won't reach the speeds of very optimized download methods that web browsers for example use.
Please keep in mind that these methods won't reach the speeds of very optimized download methods that web browsers for example use.
- Since:
- 0.0.5
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default buffer size that's used indownload(URL, File)
, if the buffer size isn't specified. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Downloads a file from a specified URL and saves it to a system file using byte buffers, for improved speed and reliability.static void
Downloads a file from a specified URL and buffer size and saves it to a system file using byte buffers, for improved speed and reliability.static void
simpleDownload
(@NotNull URL url, File destination) Downloads a file from a specified URL and saves it to a system file using a simple output stream without any buffers.
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe default buffer size that's used indownload(URL, File)
, if the buffer size isn't specified.- See Also:
-
-
Constructor Details
-
Downloads
public Downloads()
-
-
Method Details
-
download
Downloads a file from a specified URL and saves it to a system file using byte buffers, for improved speed and reliability. When the connection is reset while the download is still running, it will stop and throw an IO Exception.- Parameters:
url
- The file's path as a URL.destination
- Where the downloaded file should be stored.- Throws:
IOException
- if there is an error while downloading the file, such as a connection reset.- See Also:
-
download
Downloads a file from a specified URL and buffer size and saves it to a system file using byte buffers, for improved speed and reliability. When the connection is reset while the download is still running, it will stop and throw an IO Exception.
The buffer size impacts performance and memory usage. A higher buffer size is faster in most cases, but also uses more memory.- Parameters:
url
- The file's path as a URL.destination
- Where the downloaded file should be stored.bufferSize
- The size of the buffer to use. Bigger buffers may be faster, but also use more memory.- Throws:
IOException
- if there is an error while downloading the file, such as a connection reset.- See Also:
-
simpleDownload
Downloads a file from a specified URL and saves it to a system file using a simple output stream without any buffers. In some cases, this can turn out faster thandownload(URL, File)
, but in most, it will not be faster, as it doesn't use buffers.- Parameters:
url
- The file's path as a URL.destination
- Where the downloaded file should be stored.- Throws:
IOException
- if there is an error while downloading the file, such as a connection reset.
-