Example usage for java.net URLConnection setUseCaches

List of usage examples for java.net URLConnection setUseCaches

Introduction

In this page you can find the example usage for java.net URLConnection setUseCaches.

Prototype

public void setUseCaches(boolean usecaches) 

Source Link

Document

Sets the value of the useCaches field of this URLConnection to the specified value.

Usage

From source file:com.tweetlanes.android.core.URLFetch.java

public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) {

    Thread t = new Thread() {

        public void run() {
            URL url;/*from www. j a  v a 2s.c  o  m*/
            Bitmap bitmap = null;
            try {
                url = new URL(urlAsString);
                // Log.d("tweetlanes url fetch", urlAsString);
                URLConnection connection = url.openConnection();
                connection.setUseCaches(true);
                Object response = connection.getContent();
                if (response instanceof Bitmap) {
                    bitmap = (Bitmap) response;
                } else {
                    InputStream inputStream = connection.getInputStream();
                    bitmap = BitmapFactory.decodeStream(inputStream);
                }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (callback != null) {
                callback.finished(bitmap != null ? true : false, bitmap);
            }
        }
    };
    t.start();
}

From source file:com.shafiq.mytwittle.URLFetch.java

public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) {

    Thread t = new Thread() {

        @Override//from   w ww  .  j  ava2  s .c om
        public void run() {
            URL url;
            Bitmap bitmap = null;
            try {
                url = new URL(urlAsString);
                // Log.d("mytwittle url fetch", urlAsString);
                URLConnection connection = url.openConnection();
                connection.setUseCaches(true);
                Object response = connection.getContent();
                if (response instanceof Bitmap) {
                    bitmap = (Bitmap) response;
                } else {
                    InputStream inputStream = connection.getInputStream();
                    bitmap = BitmapFactory.decodeStream(inputStream);
                }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (callback != null) {
                callback.finished(bitmap != null ? true : false, bitmap);
            }
        }
    };
    t.start();
}

From source file:skinsrestorer.utils.DataUtils.java

public static SkinProperty getProp(String id) throws IOException, ParseException, SkinFetchFailedException {
    URL url = new URL(skullbloburl + id + "?unsigned=false");
    URLConnection connection = url.openConnection();
    connection.setConnectTimeout(10000);
    connection.setReadTimeout(10000);//from  w w  w .j av a  2s .  co m
    connection.setUseCaches(false);
    InputStream is = connection.getInputStream();
    String result = IOUtils.toString(is, Charsets.UTF_8);
    IOUtils.closeQuietly(is);
    JSONArray properties = (JSONArray) ((JSONObject) new JSONParser().parse(result)).get("properties");
    for (int i = 0; i < properties.size(); i++) {
        JSONObject property = (JSONObject) properties.get(i);
        String name = (String) property.get("name");
        String value = (String) property.get("value");
        String signature = (String) property.get("signature");
        if (name.equals("textures")) {
            return new SkinProperty(name, value, signature);
        }
    }
    throw new SkinFetchFailedException(SkinFetchFailedException.Reason.NO_SKIN_DATA);
}

From source file:com.tweetlanes.android.URLFetch.java

public static void fetchBitmap(final String urlAsString, final FetchBitmapCallback callback) {

    Thread t = new Thread() {
        public void run() {
            URL url;/*from  w  w w  . j  a v a2  s  .  co m*/
            Bitmap bitmap = null;
            try {
                url = new URL(urlAsString);
                //Log.d("tweetlanes url fetch", urlAsString);
                URLConnection connection = url.openConnection();
                connection.setUseCaches(true);
                Object response = connection.getContent();
                if (response instanceof Bitmap) {
                    bitmap = (Bitmap) response;
                } else {
                    InputStream inputStream = connection.getInputStream();
                    bitmap = BitmapFactory.decodeStream(inputStream);
                }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            if (callback != null) {
                callback.finished(bitmap != null ? true : false, bitmap);
            }
        }
    };
    t.start();
}

From source file:com.github.cc007.headsinventory.locale.Translator.java

private static InputStream getTranslationsFileStream(String fileName, ClassLoader classLoader) {
    try {//from   w  w w  .ja  v  a 2 s.  c o m
        URL url = classLoader.getResource(fileName);

        if (url == null) {
            return null;
        }

        URLConnection connection = url.openConnection();
        connection.setUseCaches(false);
        return connection.getInputStream();
    } catch (IOException ex) {
        return null;
    }
}

From source file:Main.java

private static InputStream openStream(URL url) throws IOException {
    URLConnection connection = url.openConnection();
    if (connection instanceof JarURLConnection) {
        // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5041014
        connection.setUseCaches(false);
    }// w  w w. j a v a2 s  . com
    InputStream is = connection.getInputStream();
    return is;
}

From source file:skinsrestorer.shared.utils.MojangAPI.java

private static URLConnection setupConnection(URL url) throws IOException {
    URLConnection connection = url.openConnection();
    connection.setConnectTimeout(10000);
    connection.setReadTimeout(10000);/*from  w  w  w .  j a  v a 2s.  co  m*/
    connection.setUseCaches(false);
    connection.setDoInput(true);
    connection.setDoOutput(true);
    return connection;
}

From source file:sh.isaac.provider.sync.git.gitblit.utils.ConnectionUtils.java

/**
 * Open connection./*from  w  w  w.j  av  a  2 s.co m*/
 *
 * @param url the url
 * @param username the username
 * @param password the password
 * @return the URL connection
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static URLConnection openConnection(String url, String username, char[] password) throws IOException {
    final URL urlObject = new URL(url);
    final URLConnection conn = urlObject.openConnection();

    setAuthorization(conn, username, password);
    conn.setUseCaches(false);
    conn.setDoOutput(true);
    return conn;
}

From source file:be.solidx.hot.utils.IOUtils.java

public static InputStream loadResourceNoCache(URL path) throws IOException {
    URLConnection resConn = path.openConnection();
    // !!! needed to avoid jvm resource catching
    resConn.setUseCaches(false);
    return resConn.getInputStream();
}

From source file:Downloader.java

/**
 * Creates an URL connection for the specified URL and data.
 * //  w ww  .ja  va2  s .  c o  m
 * @param url The URL to connect to
 * @param postData The POST data to pass to the URL
 * @return An URLConnection for the specified URL/data
 * @throws java.net.MalformedURLException If the specified URL is malformed
 * @throws java.io.IOException If an I/O exception occurs while connecting
 */
private static URLConnection getConnection(final String url, final String postData)
        throws MalformedURLException, IOException {
    final URL myUrl = new URL(url);
    final URLConnection urlConn = myUrl.openConnection();

    urlConn.setUseCaches(false);
    urlConn.setDoInput(true);
    urlConn.setDoOutput(postData.length() > 0);
    urlConn.setConnectTimeout(10000);

    if (postData.length() > 0) {
        urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

        final DataOutputStream out = new DataOutputStream(urlConn.getOutputStream());
        out.writeBytes(postData);
        out.flush();
        out.close();
    }

    return urlConn;
}