Java Utililty Methods URL to InputStream

List of utility methods to do URL to InputStream

Description

The list of methods to do URL to InputStream are organized into topic(s).

Method

InputStreamopenFileOrURL(String name)
open File Or URL
if (name.startsWith("resource:")) {
    URL url = Thread.currentThread().getContextClassLoader().getResource(name.substring(9));
    if (url == null)
        throw new FileNotFoundException(name);
    return url.openStream();
if (name.indexOf(':') < 2)
    return new FileInputStream(name);
...
InputStreamopenInputStream(URL url)
open Input Stream
try {
    return url.openStream();
} catch (IOException e) {
    System.out.println("#URL: " + url);
    System.out.println(e.toString());
    throw e;
InputStreamopenStream(String urlStr)
open Stream
URL url;
try {
    url = new URL(urlStr);
} catch (MalformedURLException e) {
    throw new RuntimeException(e);
InputStream in;
try {
...
InputStreamopenStream(URL url)
open Stream
return openStream(url, URL_TIMEOUT);
InputStreamopenStream(URL url)
open Stream
File file = toFile(url);
if (file != null) {
    return new FileInputStream(file);
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
    connection.setUseCaches(false);
InputStream is = connection.getInputStream();
return is;
InputStreamopenStream(URL url)
open Stream
try {
    return url.openStream();
} catch (IOException e) {
    throw new UncheckedIOException(e);
InputStreamopenStream(URL url)
open Stream
try {
    URLConnection connection = url.openConnection();
    connection.setUseCaches(false);
    return connection.getInputStream();
} catch (IOException e) {
    String msg = "Failed to open the stream: url=" + url;
    throw new IllegalStateException(msg, e);
InputStreamopenStream(URL url)
open Stream
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
    connection.setUseCaches(false);
InputStream is = connection.getInputStream();
return is;
InputStreamopenStream(URL url)
Open a stream for the given URL with the CONNECT_TIMEOUT and READ_TIMEOUT.
URLConnection conn = url.openConnection();
conn.setConnectTimeout(CONNECT_TIMEOUT);
conn.setReadTimeout(READ_TIMEOUT);
return conn.getInputStream();
InputStreamopenStream(URL url)
convenience method, directly returns a prepared stream
return getInputStream(openConnection(url));