Top Description Fields Constructors Methods
org.jabref.logic.net

public Class URLDownload

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedReader, .ByteArrayInputStream, .DataOutputStream, .IOException, .InputStream, .InputStreamReader, .Reader, .StringWriter, .Writer, java.net.CookieHandler, .CookieManager, .CookiePolicy, .HttpCookie, .HttpURLConnection, .MalformedURLException, .URISyntaxException, .URL, .URLConnection, java.nio.charset.Charset, .StandardCharsets, java.nio.file.Files, .Path, .StandardCopyOption, java.security.SecureRandom, java.security.cert.X509Certificate, java.time.Duration, java.util.Collections, .HashMap, .List, .Map, .Map.Entry, javax.net.ssl.HostnameVerifier, .HttpsURLConnection, .SSLContext, .SSLSocketFactory, .TrustManager, .X509TrustManager, org.jabref.logic.importer.FetcherClientException, .FetcherServerException, org.jabref.logic.util.io.FileUtil, kong.unirest.core.Unirest, kong.unirest.core.UnirestException, org.slf4j.Logger, .LoggerFactory

URL download to a string.

Example: URLDownload dl = new URLDownload(URL); String content = dl.asString(ENCODING); dl.toFile(Path); // available in FILE String contentType = dl.getMimeType();

Almost each call to a public method creates a new HTTP connection (except for asString, which uses an already opened connection). Nothing is cached.

Field Summary

Modifier and TypeField and Description
private Duration
private static final Duration
private static final Logger
private final Map<String, String>
private String
private final URL
public static final String

Constructor Summary

AccessConstructor and Description
public
URLDownload(String
the URL to download from
source
)

public
URLDownload(URL
The URL to download.
source
)

Method Summary

Modifier and TypeMethod and Description
public void
addHeader(String key, String value)

public ProgressInputStream
asInputStream()

Takes the web resource as the source for a monitored input stream.

public String

Returns:

the downloaded string
asString
()

Downloads the web resource to a String.

public String

Returns:

the downloaded string
asString
(Charset
the desired String encoding
encoding
)

Downloads the web resource to a String.

public static String

Returns:

the downloaded string
asString
(URLConnection
an existing connection
existingConnection
)

Downloads the web resource to a String from an existing connection.

public static String

Returns:

the downloaded string
asString
(Charset
the desired String encoding
encoding
,
URLConnection
an existing connection
connection
)

Downloads the web resource to a String.

public static void
bypassSSLVerification()
Deprecated

Older java VMs does not automatically trust the zbMATH certificate.

public boolean

Returns:

the status code of the response
canBeReached
()

Check the connection by using the HEAD request.

private static void
copy(InputStream in, Writer out, Charset encoding)

public Duration
public List<HttpCookie>
public String
public URL
public boolean
public boolean
public URLConnection

Returns:

an open connection
openConnection
()

Open a connection to this object's URL (with specified settings).

public void
setConnectTimeout(Duration connectTimeout)

public void
setPostData(String postData)

public static void
setSSLVerification(SSLSocketFactory
trust manager
socketFactory
,
HostnameVerifier
host verifier
verifier
)

public void
toFile(Path
the destination file path.
destination
)

Downloads the web resource to a file.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Path

Returns:

the path of the temporary file.
toTemporaryFile
()

Downloads the web resource to a temporary file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

connectTimeoutback to summary
private Duration connectTimeout
DEFAULT_CONNECT_TIMEOUTback to summary
private static final Duration DEFAULT_CONNECT_TIMEOUT
LOGGERback to summary
private static final Logger LOGGER
parametersback to summary
private final Map<String, String> parameters
postDataback to summary
private String postData
sourceback to summary
private final URL source
USER_AGENTback to summary
public static final String USER_AGENT

Constructor Detail

URLDownloadback to summary
public URLDownload(String source) throws MalformedURLException
Parameters
source:String

the URL to download from

Exceptions
MalformedURLException:
if no protocol is specified in the source, or an unknown protocol is found
URLDownloadback to summary
public URLDownload(URL source)
Parameters
source:URL

The URL to download.

Method Detail

addHeaderback to summary
public void addHeader(String key, String value)
asInputStreamback to summary
public ProgressInputStream asInputStream() throws IOException

Takes the web resource as the source for a monitored input stream.

asStringback to summary
public String asString() throws IOException

Downloads the web resource to a String. Uses UTF-8 as encoding.

Returns:String

the downloaded string

asStringback to summary
public String asString(Charset encoding) throws IOException

Downloads the web resource to a String.

Parameters
encoding:Charset

the desired String encoding

Returns:String

the downloaded string

asStringback to summary
public static String asString(URLConnection existingConnection) throws IOException

Downloads the web resource to a String from an existing connection. Uses UTF-8 as encoding.

Parameters
existingConnection:URLConnection

an existing connection

Returns:String

the downloaded string

asStringback to summary
public static String asString(Charset encoding, URLConnection connection) throws IOException

Downloads the web resource to a String.

Parameters
encoding:Charset

the desired String encoding

connection:URLConnection

an existing connection

Returns:String

the downloaded string

bypassSSLVerificationback to summary
public static void bypassSSLVerification()

Deprecated

Older java VMs does not automatically trust the zbMATH certificate. In this case the following exception is thrown: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target JM > 8u101 may trust the certificate by default according to http://stackoverflow.com/a/34111150/873661

We will fix this issue by accepting all (!) certificates. This is ugly; but as JabRef does not rely on security-relevant information this is kind of OK (no, actually it is not...).

Taken from http://stackoverflow.com/a/6055903/873661 and https://stackoverflow.com/a/19542614/873661

Annotations
@Deprecated
canBeReachedback 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.

Returns:boolean

the status code of the response

copyback to summary
private static void copy(InputStream in, Writer out, Charset encoding) throws IOException
getConnectTimeoutback to summary
public Duration getConnectTimeout()
getCookieFromUrlback to summary
public List<HttpCookie> getCookieFromUrl() throws IOException
getMimeTypeback to summary
public String getMimeType()
getSourceback to summary
public URL getSource()
isMimeTypeback to summary
public boolean isMimeType(String type)
isPdfback to summary
public boolean isPdf()
openConnectionback to summary
public URLConnection openConnection() throws IOException

Open a connection to this object's URL (with specified settings). If accessing an HTTP URL, don't forget to close the resulting connection after usage.

Returns:URLConnection

an open connection

setConnectTimeoutback to summary
public void setConnectTimeout(Duration connectTimeout)
setPostDataback to summary
public void setPostData(String postData)
setSSLVerificationback to summary
public static void setSSLVerification(SSLSocketFactory socketFactory, HostnameVerifier verifier)
Parameters
socketFactory:SSLSocketFactory

trust manager

verifier:HostnameVerifier

host verifier

toFileback to summary
public void toFile(Path destination) throws IOException

Downloads the web resource to a file.

Parameters
destination:Path

the destination file path.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
toTemporaryFileback to summary
public Path toTemporaryFile() throws IOException

Downloads the web resource to a temporary file.

Returns:Path

the path of the temporary file.