Java URL to InputStream openStreamUseCache(URL url)

Here you can find the source of openStreamUseCache(URL url)

Description

Similar to url.openStream except that the accessed resource may be a cached copy.

License

Open Source License

Parameter

Parameter Description
url URL for which an input stream must be opened

Return

opened input stream

Declaration

public static InputStream openStreamUseCache(URL url) throws IOException 

Method Source Code


//package com.java2s;
import java.io.IOException;

import java.io.InputStream;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    /**/*  ww w .  j  a  v  a 2 s. c  o m*/
     * Similar to <code>url.openStream</code> except that the accessed
     * resource may be a cached copy.
     * 
     * @param url URL for which an input stream must be opened
     * @return opened input stream
     * @exception IOException if the input stream cannot be opened
     * @see #openConnectionUseCache(URL)
     */
    public static InputStream openStreamUseCache(URL url) throws IOException {
        URLConnection connection = openConnectionUseCache(url);
        return connection.getInputStream();
    }

    /**
     * Similar to <code>url.openConnection</code> except that the accessed
     * resource may be a cached copy.
     * 
     * @param url URL for which an URLConnection must be opened
     * @exception IOException if URLConnection cannot be opened
     * @see #openStreamUseCache(URL)
     */
    public static URLConnection openConnectionUseCache(URL url) throws IOException {
        URLConnection connection = url.openConnection();
        connection.setUseCaches(true); // Normally the default, so just in case.
        return connection;
    }
}

Related

  1. openStream(URL url)
  2. openStream(URL url)
  3. openStream(URL url)
  4. openStream(URL url)
  5. openStream(URL url, int connectTimeout, int readTimeout)
  6. openURL(String url)
  7. openURLStream(String in)