java URLDownload dl = new URLDownload(URL); String content = dl.asString(ENCODING); dl.toFile(Path); // available in FILE String contentType = dl.getMimeType();
Almost every call to a public method creates a new HTTP connection (except for asString, which uses an already opened connection).
Nothing is cached.
Implentation note: This relies on https://kong.github.io/unirest-java/configuration/ setting followRedirects to true
and enabling cookie management.
| Modifier and Type | Field and Description |
|---|---|
| private Duration | |
| private static final Duration | |
| private @Nullable ImporterPreferences | |
| private static final Logger | |
| private static final int | |
| private final Map | |
| private String | |
| private final URL | |
| private @Nullable SSLContext | |
| public static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public ProgressInputStream | |
| public ProgressInputStream | asInputStream(HttpURLConnection urlConnection)
Uses the web resource as source and creates a monitored input stream. |
| public String | |
| private static String | Returns: the downloaded stringthe desired String encoding encoding, URLConnection an existing connection connection)Downloads the web resource to a String. |
| public boolean | Returns: the status code of the responseCheck the connection by using the HEAD request. |
| private static void | |
| public Duration | |
| public List | |
| public Optional | |
| public URL | |
| private URLConnection | |
| public boolean | |
| public boolean | |
| public URLConnection | Returns: an open connectionOpen a connection to this object's URL (with specified settings). |
| public void | |
| public void | |
| public void | |
| public String | |
| public Path | Returns: the path of the temporary file.Downloads the web resource to a temporary file. |
| connectTimeout | back to summary |
|---|---|
| private Duration connectTimeout | |
| DEFAULT_CONNECT_TIMEOUT | back to summary |
|---|---|
| private static final Duration DEFAULT_CONNECT_TIMEOUT | |
| importerPreferences | back to summary |
|---|---|
| private @Nullable ImporterPreferences importerPreferences | |
| LOGGER | back to summary |
|---|---|
| private static final Logger LOGGER | |
| MAX_RETRIES | back to summary |
|---|---|
| private static final int MAX_RETRIES | |
| parameters | back to summary |
|---|---|
| private final Map<String, String> parameters | |
| postData | back to summary |
|---|---|
| private String postData | |
| source | back to summary |
|---|---|
| private final URL source | |
| sslContext | back to summary |
|---|---|
| private @Nullable SSLContext sslContext | |
| USER_AGENT | back to summary |
|---|---|
| public static final String USER_AGENT | |
| URLDownload | back to summary |
|---|---|
public URLDownload(String source) throws MalformedURLException
| |
| URLDownload | back to summary |
|---|---|
public URLDownload(URL source)
| |
| URLDownload | back to summary |
|---|---|
| public URLDownload(@NonNull ImporterPreferences importerPreferences, @NonNull URL citationsUrl) | |
| addHeader | back to summary |
|---|---|
| public void addHeader(String key, String value) | |
| asInputStream | back to summary |
|---|---|
| public ProgressInputStream asInputStream() throws FetcherException Uses the web resource as source and creates a monitored input stream. | |
| asInputStream | back to summary |
|---|---|
| public ProgressInputStream asInputStream(HttpURLConnection urlConnection) throws FetcherException Uses the web resource as source and creates a monitored input stream. Exposing the urlConnection is required for dynamic API limiting of CrossRef | |
| asString | back to summary |
|---|---|
| public String asString() throws FetcherException Downloads the web resource to a String. Uses UTF-8 as encoding.
| |
| asString | back to summary |
|---|---|
| private static String asString(Charset encoding, URLConnection connection) throws FetcherException Downloads the web resource to a String.
| |
| canBeReached | back to summary |
|---|---|
| public boolean canBeReached() throws kong.unirest.core.UnirestException Check the connection by using the HEAD request. UnirestException can be thrown for invalid request.
| |
| copy | back to summary |
|---|---|
| private static void copy(InputStream in, Writer out, Charset encoding) throws IOException | |
| getConnectTimeout | back to summary |
|---|---|
| public Duration getConnectTimeout() | |
| getCookieFromUrl | back to summary |
|---|---|
| public List | |
| getMimeType | back to summary |
|---|---|
| public Optional | |
| getSource | back to summary |
|---|---|
| public URL getSource() | |
| getUrlConnection | back to summary |
|---|---|
| private URLConnection getUrlConnection() throws IOException | |
| isMimeType | back to summary |
|---|---|
| public boolean isMimeType(String type) | |
| isPdf | back to summary |
|---|---|
| public boolean isPdf() | |
| openConnection | back to summary |
|---|---|
| public URLConnection openConnection() throws FetcherException Open a connection to this object's URL (with specified settings). If accessing an HTTP URL, remember to close the resulting connection after usage.
| |
| setConnectTimeout | back to summary |
|---|---|
| public void setConnectTimeout(Duration connectTimeout) | |
| setPostData | back to summary |
|---|---|
| public void setPostData(String postData) | |
| toFile | back to summary |
|---|---|
| public void toFile(Path destination) throws FetcherException Downloads the web resource to a file.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| toTemporaryFile | back to summary |
|---|---|
| public Path toTemporaryFile() throws FetcherException Downloads the web resource to a temporary file.
| |