Example usage for java.lang OutOfMemoryError getClass

List of usage examples for java.lang OutOfMemoryError getClass

Introduction

In this page you can find the example usage for java.lang OutOfMemoryError getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.handlerexploit.news.utils.BitmapLruCache.java

/**
 * Convenience method to retrieve a bitmap image from a URL over the
 * network. The built-in methods do not seem to work, as they return a
 * FileNotFound exception.// www  . j ava2 s. c o  m
 * 
 * Note that this does not perform any threading -- it blocks the call while
 * retrieving the data.
 * 
 * @param url
 *            The URL to read the bitmap from.
 * @return A Bitmap image or null if an error occurs.
 */
public static Bitmap readBitmapFromNetwork(String url) {
    InputStream inputStream = null;
    BufferedInputStream bufferedInputStream = null;
    Bitmap bitmap = null;

    try {
        URLConnection conn = new URL(url).openConnection();
        conn.connect();
        inputStream = conn.getInputStream();
        bufferedInputStream = new BufferedInputStream(inputStream, 8192);
        bitmap = BitmapFactory.decodeStream(bufferedInputStream);
    } catch (OutOfMemoryError e) {
        Log.d(TAG, "Ran out of memory.", e);
    } catch (Throwable e) {
        if (!e.getClass().equals(UnknownHostException.class)) {
            Log.d(TAG, "Could not get remote image : " + e.getClass().getSimpleName(), e);
        }
    } finally {
        try {
            if (inputStream != null) {
                inputStream.close();
            }
            if (bufferedInputStream != null) {
                bufferedInputStream.close();
            }
        } catch (IOException e) {
            Log.d(TAG, "Error closing stream.", e);
        }
    }
    return bitmap;
}