public class URLInputStream extends FilterInputStream
To open HTTP resources use standard HTTP URL syntax:
To open FTP resources use standard FTP URL syntax:
To open file use either local file name or standard file URL syntax:
Modifier and Type | Field and Description |
---|---|
protected URLConnection |
connection |
in
Constructor and Description |
---|
URLInputStream(String url)
Creates a URLInputStream for specified URL.
|
Modifier and Type | Method and Description |
---|---|
static void |
checkConnectionResponseCode(URLConnection connection)
Checks connection response code and throws
IOException if it is not Ok. |
void |
close() |
protected void |
finalize() |
long |
getLastModified()
This method returns last modification time from this
URLInputStream . |
static long |
getLastModified(String url)
Returns last modification time for a specified URL.
|
static long |
getLastModified(URL url,
String user,
String password)
Returns last modification time for a specified URL.
|
static URLConnection |
openConnection(String url)
Opens
URLConnection for a specified URL. |
static URLConnection |
openConnection(URL url,
String user,
String password)
Opens
URLConnection for a specified URL with a specified basic user and password credentials. |
static byte[] |
readURL(String url)
Reads content for specified URL and returns it as a byte array.
|
static URL |
resolveURL(String url)
Resolves a given URL in the context of the current file.
|
available, mark, markSupported, read, read, read, reset, skip
protected final URLConnection connection
public URLInputStream(String url) throws IOException
url
- the URL to openIOException
- if an I/O error occurspublic static URL resolveURL(String url) throws MalformedURLException
url
- url, relative, or absolute file name.MalformedURLException
- if url cannot be parsed.public static URLConnection openConnection(String url) throws IOException
URLConnection
for a specified URL. This method resolves
specified URL first, for a proper support of file name.
Use checkConnectionResponseCode
after establishing
connection to ensure that it was Ok.
This is a shortcut for
openConnection
(resolveURL
(url), null, null)
.url
- the URL.IOException
- if an I/O error occurs.public static URLConnection openConnection(URL url, String user, String password) throws IOException
URLConnection
for a specified URL with a specified basic user and password credentials.
Use checkConnectionResponseCode
after establishing
connection to ensure that it was Ok.
Credentials are used only when both user and password are non-null and non-empty.
Specified credentials take precedence over authentication information that is supplied to this method
as part of URL user info like "http://user:password@host:port/path/file"
.url
- the URL.user
- the user name (may be null).password
- the password (may be null).IOException
- if an I/O error occurs.public static void checkConnectionResponseCode(URLConnection connection) throws IOException
IOException
if it is not Ok.connection
- URLConnectionIOException
- if an I/O error occurspublic static byte[] readURL(String url) throws IOException
url
- the URL to readIOException
- if an I/O error occurspublic static long getLastModified(String url) throws IOException
getLastModified
(resolveURL
(url),
null, null)
.url
- the URL.IOException
- if there is some problem retrieving last modification time or it is not known.public static long getLastModified(URL url, String user, String password) throws IOException
url
- the URL.user
- the user name (may be null).password
- the password (may be null).IOException
- if there is some problem retrieving last modification time or it is not known.public long getLastModified()
URLInputStream
.
Returns 0 when last modification time is not known.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterInputStream
IOException
protected void finalize() throws IOException
finalize
in class Object
IOException
Copyright © 2017 Devexperts. All Rights Reserved.