public class Url extends Object
Modifier and Type | Field and Description |
---|---|
protected okhttp3.Call |
call |
protected static okhttp3.OkHttpClient |
client |
protected List<Pair<String,String>> |
headersRequest |
protected okhttp3.Headers |
headersResponse |
static List<String> |
KNOWN_HEADERS |
protected okhttp3.Request |
request |
protected okhttp3.Response |
response |
protected Charset |
responseCharset |
protected int |
responseCode |
protected long |
responseContentLength |
protected String |
responseContentType |
protected String |
responseMessage |
protected URI |
uri |
protected String |
url |
protected static String |
USER_AGENT |
Modifier | Constructor and Description |
---|---|
protected |
Url()
A constructor for inherited classes which needs a special setup
|
|
Url(String url)
Instantiates a new url / httpclient with default user-agent.
|
Modifier and Type | Method and Description |
---|---|
void |
addHeader(Pair<String,String> header)
Adds the header.
|
void |
addHeader(String key,
String value)
Adds the header.
|
void |
addHeaders(List<Pair<String,String>> headers)
Adds the headers.
|
protected void |
cleanup()
Cleanup the connection
|
boolean |
download(File file)
Download an Url to a file via NIO FileChannel (synchron)
|
boolean |
download(Path file)
Download an Url to a file via NIO FileChannel (synchron)
|
byte[] |
getBytes()
Gets the bytes.
|
byte[] |
getBytesWithRetry(int retries)
Gets the bytes with the given amount of retries
|
Charset |
getCharset()
Gets the charset.
|
String |
getContentEncoding()
Gets the content encoding.
|
long |
getContentLength()
the number of bytes of the content, or a negative number if unknown.
|
String |
getHeader(String header)
gets the specified header value from this connection
You need to call this AFTER getInputstream(). |
okhttp3.Headers |
getHeadersResponse()
get all response headers
|
InputStream |
getInputStream()
Gets the input stream.
|
InputStream |
getInputStream(boolean headRequest)
Gets the input stream.
|
InputStream |
getInputStreamWithRetry(int retries)
gets the url with the given amount of retries
|
int |
getStatusCode()
http status code
|
String |
getStatusLine()
http status string
|
URL |
getUrl()
Gets the url.
|
boolean |
isFault()
is the HTTP status code a 4xx/5xx?
|
protected URI |
morphStringToUri(String urlToMorph)
morph the url (string) to an URI to check the syntax and escape the path
|
void |
setUserAgent(String userAgent)
set a specified User-Agent
|
protected void |
splitHeadersFromUrl()
pipe could be delimiter for header values (like seen in Kodi)
http://www.asdfcom/page? |
String |
toString() |
protected static okhttp3.OkHttpClient client
protected static final String USER_AGENT
protected int responseCode
protected String responseMessage
protected Charset responseCharset
protected String responseContentType
protected long responseContentLength
protected String url
protected okhttp3.Headers headersResponse
protected URI uri
protected okhttp3.Call call
protected okhttp3.Request request
protected okhttp3.Response response
public Url(String url) throws MalformedURLException
url
- the urlMalformedURLException
protected Url()
public String getHeader(String header)
header
- the header you want to know (like Content-Length)public okhttp3.Headers getHeadersResponse()
protected void splitHeadersFromUrl()
protected URI morphStringToUri(String urlToMorph) throws MalformedURLException, URISyntaxException
urlToMorph
- the url to morphMalformedURLException
URISyntaxException
public void setUserAgent(String userAgent)
userAgent
- the user agent to be setpublic URL getUrl() throws IOException, InterruptedException
IOException
- Signals that an I/O exception has occurred.InterruptedException
public void addHeader(String key, String value)
key
- the keyvalue
- the valuepublic void addHeader(Pair<String,String> header)
header
- the headerpublic void addHeaders(List<Pair<String,String>> headers)
headers
- the headerspublic InputStream getInputStream() throws IOException, InterruptedException
IOException
- Signals that an I/O exception has occurred.InterruptedException
public InputStream getInputStream(boolean headRequest) throws IOException, InterruptedException
headRequest
- do you just want to send a HEAD request, for checking file availability?IOException
InterruptedException
- Signals that an I/O exception has occurred.public InputStream getInputStreamWithRetry(int retries)
retries
- the amount of retries (>0)protected void cleanup()
public boolean isFault()
public int getStatusCode()
public String getStatusLine()
public byte[] getBytes() throws IOException, InterruptedException
IOException
- Signals that an I/O exception has occurred.InterruptedException
public byte[] getBytesWithRetry(int retries) throws IOException
retries
- the amount of retries (>0)IOException
- Signals that an I/O exception has occurred.public boolean download(File file)
file
- public boolean download(Path file)
file
- public Charset getCharset()
public String getContentEncoding()
public long getContentLength()
Copyright © 2012–2019 tinyMediaManager. All rights reserved.