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 new
URLInputStream instance for specified URL. |
URLInputStream(URL url,
AuthToken token,
long ifModifiedSince)
Creates a new
URLInputStream instance for specified URL with specified credentials
and specified If-Modified-Since request parameter. |
URLInputStream(URL url,
String user,
String password)
Creates a new
URLInputStream instance for specified URL with specified credentials. |
URLInputStream(URL url,
String user,
String password,
long ifModifiedSince)
Creates a new
URLInputStream instance for specified URL with specified credentials
and specified If-Modified-Since request parameter. |
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() |
URLConnection |
getConnection()
Returns
URLConnection for this URLInputStream . |
long |
getLastModified()
Returns last modification time from this
URLInputStream . |
static long |
getLastModified(String url)
Returns last modification time for specified URL.
|
static long |
getLastModified(URL url,
AuthToken token)
Returns last modification time for specified URL with specified credentials.
|
static long |
getLastModified(URL url,
String user,
String password)
Returns last modification time for specified URL with specified credentials.
|
boolean |
isModifiedSince()
Determines whether content of this
URLInputStream was modified according to If-Modified-Since
request parameter specified at creation. |
static URLConnection |
openConnection(String url)
Opens
URLConnection for specified URL. |
static URLConnection |
openConnection(URL url,
AuthToken token)
Opens
URLConnection for specified URL with specified credentials. |
static URLConnection |
openConnection(URL url,
String user,
String password)
Opens
URLConnection for specified URL with specified credentials. |
byte[] |
readAllBytes()
Reads remaining content from this
URLInputStream and returns it as a byte array. |
static byte[] |
readBytes(String url)
Reads content for specified URL and returns it as a byte array.
|
static byte[] |
readBytes(URL url,
AuthToken token)
Reads content for specified URL with specified credentials and returns it as a byte array.
|
static byte[] |
readBytes(URL url,
String user,
String password)
Reads content for specified URL with specified credentials and returns it as a byte array.
|
static byte[] |
readURL(String url)
Deprecated.
use
readBytes instead |
static URL |
resolveURL(String url)
Resolves specified URL in the context of the current user directory.
|
available, mark, markSupported, read, read, read, reset, skip
protected final URLConnection connection
public URLInputStream(String url) throws IOException
URLInputStream
instance for specified URL.
This is a shortcut for
.URLInputStream
(resolveURL
(url),
null, null)
url
- the URLIOException
- if an I/O error occurspublic URLInputStream(URL url, String user, String password) throws IOException
URLInputStream
instance for specified URL with specified credentials.
Credentials are used only if any of user or password is 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 URLuser
- the username, may be nullpassword
- the password, may be nullIOException
- if an I/O error occurspublic URLInputStream(URL url, String user, String password, long ifModifiedSince) throws IOException
URLInputStream
instance for specified URL with specified credentials
and specified If-Modified-Since
request parameter.
Credentials are used only if any of user or password is 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"
.
The If-Modified-Since
time is used only when it is not 0.url
- the URLuser
- the username, may be nullpassword
- the password, may be nullifModifiedSince
- the If-Modified-Since time, may be 0IOException
- if an I/O error occurspublic URLInputStream(URL url, AuthToken token, long ifModifiedSince) throws IOException
URLInputStream
instance for specified URL with specified credentials
and specified If-Modified-Since
request parameter.
Specified non-null token takes precedence over authentication information that is supplied to this method
as part of URL user info like "http://user:password@host:port/path/file"
.
The If-Modified-Since
time is used only when it is not 0.url
- the URLtoken
- the token, may be nullifModifiedSince
- the If-Modified-Since time, may be 0IOException
- if an I/O error occurspublic static URL resolveURL(String url) throws MalformedURLException
url
- the URLMalformedURLException
- if URL cannot be parsedpublic static URLConnection openConnection(String url) throws IOException
URLConnection
for 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 URLIOException
- if an I/O error occurspublic static URLConnection openConnection(URL url, String user, String password) throws IOException
URLConnection
for specified URL with specified credentials.
Credentials are used only if any of user or password is 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"
.
Use checkConnectionResponseCode
after establishing
connection to ensure that it was Ok.
url
- the URLuser
- the username, may be nullpassword
- the password, may be nullIOException
- if an I/O error occurspublic static URLConnection openConnection(URL url, AuthToken token) throws IOException
URLConnection
for specified URL with specified credentials.
Specified non-null token takes precedence over authentication information that is supplied to this method
as part of URL user info like "http://user:password@host:port/path/file"
.
Use checkConnectionResponseCode
after establishing
connection to ensure that it was Ok.
url
- the URLtoken
- the token, may be nullIOException
- if an I/O error occurspublic static void checkConnectionResponseCode(URLConnection connection) throws IOException
IOException
if it is not Ok.connection
- URLConnectionIOException
- if an I/O error occurs or if connection response code is not Ok@Deprecated public static byte[] readURL(String url) throws IOException
readBytes
insteadresolves
specified URL first, for a proper support of file name.
This is a shortcut for
.readBytes
(resolveURL
(url),
null, null)
url
- the URLIOException
- if an I/O error occurspublic static byte[] readBytes(String url) throws IOException
resolves
specified URL first, for a proper support of file name.
This is a shortcut for
.readBytes
(resolveURL
(url),
null, null)
url
- the URLIOException
- if an I/O error occurspublic static byte[] readBytes(URL url, String user, String password) throws IOException
"http://user:password@host:port/path/file"
.url
- the URLuser
- the username, may be nullpassword
- the password, may be nullIOException
- if an I/O error occurspublic static byte[] readBytes(URL url, AuthToken token) throws IOException
"http://user:password@host:port/path/file"
.url
- the URLtoken
- the token, may be nullIOException
- if an I/O error occurspublic static long getLastModified(String url) throws IOException
This is a shortcut for
.getLastModified
(resolveURL
(url),
null, null)
url
- the URLIOException
- if an I/O error occurs or if last modification time is not knownpublic static long getLastModified(URL url, String user, String password) throws IOException
"http://user:password@host:port/path/file"
.url
- the URLuser
- the username, may be nullpassword
- the password, may be nullIOException
- if an I/O error occurs or if last modification time is not knownpublic static long getLastModified(URL url, AuthToken token) throws IOException
"http://user:password@host:port/path/file"
.url
- the URLtoken
- the token, may be nullIOException
- if an I/O error occurs or if last modification time is not knownpublic URLConnection getConnection()
URLConnection
for this URLInputStream
.public long getLastModified()
URLInputStream
.
Returns 0 when last modification time is not known.public boolean isModifiedSince() throws IOException
URLInputStream
was modified according to If-Modified-Since
request parameter specified at creation.true
if content was modified according to If-Modified-Since
parameter,
or parameter was not specified or was 0IOException
- if an I/O error occurspublic byte[] readAllBytes() throws IOException
URLInputStream
and returns it as a byte array.IOException
- if an I/O error occurspublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterInputStream
IOException
Copyright © 2002–2025 Devexperts LLC. All rights reserved.