Example usage for java.lang OutOfMemoryError printStackTrace

List of usage examples for java.lang OutOfMemoryError printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.mklodoss.SexyGirl.displayingbitmaps.ui.ImageDetailActivity.java

private void downloadLargePic() {
    position = mPager.getCurrentItem();/*from   w  w w .j  av a  2  s.  c  o  m*/
    if (ImageGridFragment.list != null && ImageGridFragment.list.size() > position) {
        LocalBelle belle = ImageGridFragment.list.get(position);
        final String rawUrl = belle.getRawUrl();
        final String fileFullPath = AppRuntime.RAW_URL_CACHE_DIR + rawUrl.hashCode();
        new Thread() {
            @Override
            public void run() {
                try {
                    File localFile = new File(fileFullPath);
                    if ((localFile != null) && (localFile.exists())) { // ????
                        String str1 = MediaStore.Images.Media.insertImage(getContentResolver(),
                                localFile.getAbsolutePath(), "belle" + rawUrl, "belle" + rawUrl);
                        String[] arrayOfString = { "_data" };
                        Cursor localCursor = getContentResolver().query(Uri.parse(str1), arrayOfString, null,
                                null, null);
                        String str2 = null;
                        if (localCursor != null) {
                            int i = localCursor.getColumnIndexOrThrow("_data");
                            localCursor.moveToFirst();
                            str2 = localCursor.getString(i);
                            localCursor.close();
                        }
                        if (str2 != null) {
                            sendBroadcast(new Intent("android.intent.action.MEDIA_SCANNER_SCAN_FILE",
                                    Uri.fromFile(new File(str2))));
                            ImageDetailActivity.this.mHandler.sendEmptyMessage(WHAT_SAVE_SUCCESS);
                        }
                    } else { //?
                        ImageDetailActivity.this.mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                if (ImageDetailActivity.this.mProgressDialog == null) {
                                    ImageDetailActivity.this.mProgressDialog = new ProgressDialog(
                                            ImageDetailActivity.this);
                                    ImageDetailActivity.this.mProgressDialog.setProgressStyle(0);
                                    ImageDetailActivity.this.mProgressDialog.setCanceledOnTouchOutside(false);
                                }
                                ImageDetailActivity.this.mProgressDialog
                                        .setMessage("??...");
                                ImageDetailActivity.this.mProgressDialog.show();

                                new AsyncHttpClient().get(rawUrl,
                                        new RangeFileAsyncHttpResponseHandler(new File(fileFullPath)) {
                                            @Override
                                            public void onFailure(int i, Header[] headers, Throwable throwable,
                                                    File file) {
                                                ImageDetailActivity.this.mProgressDialog.dismiss();
                                            }

                                            @Override
                                            public void onSuccess(int i, Header[] headers, File file) {
                                                ImageDetailActivity.this.mProgressDialog.dismiss();
                                                downloadLargePic();
                                            }
                                        });
                            }
                        });
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    ImageDetailActivity.this.mHandler.sendEmptyMessage(WHAT_SAVE_FAIL);
                } catch (OutOfMemoryError outOfMemoryError) {
                    outOfMemoryError.printStackTrace();
                    System.gc();
                }
            }
        }.start();

    }
}

From source file:com.eviware.soapui.SoapUI.java

public static void logError(Throwable e, String message) {
    String msg = e.getMessage();/*from ww w.  j  a  va2s .com*/
    if (msg == null)
        msg = e.toString();

    log.error("An error occured [" + msg + "], see error log for details");

    try {
        if (message != null)
            errorLog.error(message);

        errorLog.error(e.toString(), e);
    } catch (OutOfMemoryError e1) {
        e1.printStackTrace();
        System.gc();
    }
    if (!isStandalone() || "true".equals(System.getProperty("soapui.stacktrace")))
        e.printStackTrace();
}

From source file:com.developer4droid.contactslister.backend.image_load.EnhancedImageDownloader.java

private Bitmap downloadBitmap(String url) {
    // AndroidHttpClient is not allowed to be used from the main thread
    final HttpClient client = (mode == Mode.NO_ASYNC_TASK) ? new DefaultHttpClient()
            : AndroidHttpClient.newInstance("Android");
    url = url.replace(" ", "%20");
    final HttpGet getRequest = new HttpGet(url);

    try {/*from  www. jav a 2  s.  com*/
        HttpResponse response = client.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.e("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url);
            return null;
        }

        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = null;
            try {
                inputStream = entity.getContent();
                // return BitmapFactory.decodeStream(inputStream);
                // Bug on slow connections, fixed in future release.

                // create descriptor
                String filename = String.valueOf(url.hashCode());
                File f = new File(cacheDir, filename);

                InputStream is = new URL(url).openStream();
                // copy stream to file
                OutputStream os = new FileOutputStream(f); // save stream to
                // SD
                copyStream(is, os);
                os.close();

                // decode image size
                BitmapFactory.Options o = new BitmapFactory.Options();
                o.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(new FileInputStream(f), null, o);

                // Find the correct scale value. It should be the power of 2.

                int width_tmp = o.outWidth, height_tmp = o.outHeight;
                int scale = 1;
                while (true) {
                    if (width_tmp / 2 < REQUIRED_IMAGE_SIZE || height_tmp / 2 < REQUIRED_IMAGE_SIZE)
                        break;
                    width_tmp /= 2;
                    height_tmp /= 2;
                    scale *= 2;
                }

                // decode with inSampleSize
                BitmapFactory.Options o2 = new BitmapFactory.Options();
                o2.inSampleSize = scale;
                return BitmapFactory.decodeStream(new FlushedInputStream(inputStream), null, o2);
                //               return BitmapFactory.decodeStream(inputStream);
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                entity.consumeContent();
            }
        }
    } catch (OutOfMemoryError error) {
        error.printStackTrace();
    } catch (IOException e) {
        getRequest.abort();
        Log.e(LOG_TAG, "I/O error while retrieving bitmap from " + url, e);
    } catch (IllegalStateException e) {
        getRequest.abort();
        Log.e(LOG_TAG, "Incorrect URL: " + url);
    } catch (Exception e) {
        getRequest.abort();
        Log.e(LOG_TAG, "Error while retrieving bitmap from " + url, e);
    } finally {
        if ((client instanceof AndroidHttpClient)) {
            ((AndroidHttpClient) client).close();
        }
    }
    return null;
}

From source file:de.baumann.hhsmoodle.fragmentsMain.FragmentBrowser.java

private void screenshot() {

    shareFile = helper_main.newFile();// ww  w. ja v a  2s  .  co m

    try {
        mWebView.measure(
                View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        mWebView.layout(0, 0, mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight());
        mWebView.setDrawingCacheEnabled(true);
        mWebView.buildDrawingCache();

        bitmap = Bitmap.createBitmap(mWebView.getMeasuredWidth(), mWebView.getMeasuredHeight(),
                Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint();
        int iHeight = bitmap.getHeight();
        canvas.drawBitmap(bitmap, 0, iHeight, paint);
        mWebView.draw(canvas);

    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        Snackbar.make(mWebView, R.string.toast_screenshot_failed, Snackbar.LENGTH_SHORT).show();
    }

    if (bitmap != null) {
        try {
            OutputStream fOut;
            fOut = new FileOutputStream(shareFile);

            bitmap.compress(Bitmap.CompressFormat.PNG, 50, fOut);
            fOut.flush();
            fOut.close();
            bitmap.recycle();

            Snackbar.make(mWebView,
                    getString(R.string.context_saveImage_toast) + " " + helper_main.newFileName(),
                    Snackbar.LENGTH_SHORT).show();

            Uri uri = Uri.fromFile(shareFile);
            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
            getActivity().sendBroadcast(intent);

        } catch (Exception e) {
            e.printStackTrace();
            Snackbar.make(mWebView, R.string.toast_perm, Snackbar.LENGTH_SHORT).show();
        }
    }
}

From source file:com.letsdoitworld.wastemapper.utils.ImageDownloader.java

Bitmap downloadBitmap(String url) {
    BitmapFactory.Options bfOptions = new BitmapFactory.Options();

    // AndroidHttpClient is not allowed to be used from the main thread
    final HttpClient client = (mode == Mode.NO_ASYNC_TASK) ? new DefaultHttpClient()
            : AndroidHttpClient.newInstance("Android");
    final HttpGet getRequest = new HttpGet(url);

    try {//from   ww w.j a va  2s. c  o m
        HttpResponse response = client.execute(getRequest);
        final int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_OK) {
            Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url);
            return null;
        }

        final HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = null;
            try {
                inputStream = entity.getContent();
                // return BitmapFactory.decodeStream(inputStream);
                // Bug on slow connections, fixed in future release.
                return BitmapFactory.decodeStream(new FlushedInputStream(inputStream));
            } finally {
                if (inputStream != null) {
                    inputStream.close();
                }
                entity.consumeContent();
            }
        }
    } catch (IOException e) {
        getRequest.abort();
        Log.w(LOG_TAG, "I/O error while retrieving bitmap from " + url, e);
    } catch (IllegalStateException e) {
        getRequest.abort();
        Log.w(LOG_TAG, "Incorrect URL: " + url);
        if (url.contains("content")) {

            InputStream inputStream = null;

            //MediaStore.Images.Media.EXTERNAL_CONTENT_URI
            bfOptions.inDither = false; //Disable Dithering mode

            bfOptions.inPurgeable = true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared

            bfOptions.inInputShareable = true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future

            bfOptions.inTempStorage = new byte[32 * 1024];

            Bitmap bitmap = null;

            try {
                inputStream = mContext.getContentResolver().openInputStream(Uri.parse(url));
                // return BitmapFactory.decodeStream(inputStream);
                // Bug on slow connections, fixed in future release.
                bitmap = BitmapFactory.decodeStream(new FlushedInputStream(inputStream), null, bfOptions);
                return rezise(bitmap);
            } catch (FileNotFoundException fnfe) {
                fnfe.printStackTrace();
            } catch (OutOfMemoryError out) {
                if (bitmap != null) {
                    bitmap.recycle();
                    bitmap = null;
                }

                out.printStackTrace();
            } finally {
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }

            //InputStream input = 
            //Bitmap bitmap = BitmapFactory.decodeFile(MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString(),bfOptions);

            Log.w(LOG_TAG, "sdcard URL: ");
        }
    } catch (Exception e) {
        getRequest.abort();
        Log.w(LOG_TAG, "Error while retrieving bitmap from " + url, e);
    } finally {
        if ((client instanceof AndroidHttpClient)) {
            ((AndroidHttpClient) client).close();
        }
    }
    return null;
}

From source file:com.akop.bach.ImageCache.java

public Bitmap getCachedBitmap(String imageUrl, CachePolicy cachePol) {
    if (imageUrl == null || imageUrl.length() < 1)
        return null;

    // Returns the cached image, or NULL if the image is not yet cached
    File file = getCacheFile(imageUrl, cachePol);

    // Return NULL if we don't have a cached copy
    if (!file.canRead())
        return null;

    if (cachePol != null && cachePol.expired(System.currentTimeMillis(), file.lastModified()))
        return null;

    try {//from   w w  w  .  ja  v  a  2s .  co  m
        return BitmapFactory.decodeFile(file.getAbsolutePath());
    } catch (OutOfMemoryError e) {
        return null;
    } catch (Exception e) {
        if (App.getConfig().logToConsole()) {
            App.logv("error decoding %s", file.getAbsolutePath());
            e.printStackTrace();
        }

        return null;
    }
}

From source file:com.filemanager.free.activities.TextReader.java

private void load(final File mFile) {
    setProgress(true);// w  w w. j a  va  2 s .  c  o m
    this.mFile = mFile;
    mInput.setHint(R.string.loading);
    new Thread(new Runnable() {
        @Override
        public void run() {

            try {
                InputStream inputStream = getInputStream(uri, path);
                if (inputStream != null) {
                    String str = null;
                    //if(texts==null)texts=new ArrayList<>();
                    StringBuilder stringBuilder = new StringBuilder();
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                    if (bufferedReader != null) {
                        //   int i=0,k=0;
                        //     StringBuilder stringBuilder1=new StringBuilder("");
                        while ((str = bufferedReader.readLine()) != null) {
                            stringBuilder.append(str + "\n");
                            /*       if(k<maxlength){
                            stringBuilder1.append(str+"\n");
                            k++;
                                   }else {
                            texts.add(i,stringBuilder1);
                            i++;
                            stringBuilder1=new StringBuilder("");
                            stringBuilder1.append(str+"\n");
                            k=1;
                                   }
                            */
                        }
                        //  texts.add(i,stringBuilder1);
                    }
                    mOriginal = stringBuilder.toString();
                    inputStream.close();
                } else {
                    mOriginal = "";
                    StringBuilder stringBuilder = new StringBuilder();
                    ArrayList<String> arrayList = RootHelper.runAndWait1("cat " + mFile.getPath(), true);
                    //  int i=0,k=0;
                    //StringBuilder stringBuilder1=new StringBuilder("");
                    for (String str : arrayList) {
                        stringBuilder.append(str + "\n");
                        /*    if(k<maxlength){
                        stringBuilder1.append(str+"\n");
                        k++;
                            }else {
                        texts.add(i,stringBuilder1);
                        i++;
                        stringBuilder1=new StringBuilder("");
                        stringBuilder1.append(str+"\n");
                        k=1;
                            }
                        */
                    }
                    // texts.add(i,stringBuilder1);
                    mOriginal = stringBuilder.toString();
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            mInput.setText(mOriginal);
                            if (mOriginal.isEmpty()) {

                                mInput.setHint(R.string.file_empty);
                            } else
                                mInput.setHint(null);
                        } catch (OutOfMemoryError e) {
                            mInput.setHint(R.string.error);
                        }
                        setProgress(false);
                    }
                });
            } catch (final Exception e) {
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        mInput.setHint(R.string.error);
                    }
                });
            }
        }
    }).start();
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

/**
 * Creates and returns a Bitmap from an InputStream.
 * @param stream an InputStream to read bitmap data.
 * @param opts BitmapFactory options//from w  w w .  ja  v a2s  .  c  o m
 * @return a new bitmap instance.
 * @module.api
 */
public static Bitmap createBitmap(InputStream stream, BitmapFactory.Options opts) {
    Rect pad = new Rect();
    if (opts == null) {
        opts = TiBitmapPool.defaultBitmapOptions();
    }
    Bitmap b = null;
    try {
        MarkableInputStream markStream = new MarkableInputStream(stream);
        stream = markStream;

        long mark = markStream.savePosition(65536); // TODO fix this crap.
        markStream.reset(mark);
        TiApplication.getBitmapOptionsTransformer().transformOptions(markStream, opts, mark);
        b = BitmapFactory.decodeResourceStream(null, null, stream, pad, opts);
    } catch (OutOfMemoryError e) {
        Log.e(TAG, "Unable to load bitmap. Not enough memory: " + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return b;
}

From source file:com.zhongsou.souyue.activity.SplashActivity.java

private void setImage(String key, String filePath) {
    Bitmap cacheBitmap = getBitmapFromMemCache(key);
    if (cacheBitmap == null) {
        try {//from  www .j a  v a2 s .  c o  m
            if (StringUtils.isEmpty(filePath)) {
                //TODO 
                cacheBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.splash_default);
            } else {
                cacheBitmap = BitmapFactory.decodeFile(filePath);
            }
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
        }
        addBitmapToMemoryCache(key, cacheBitmap);
    }
    if (cacheBitmap != null) {
        mSplashAdImg.setImageBitmap(cacheBitmap);
    }
}

From source file:me.aerovulpe.crawler.ui.GifImageView.java

private void playGif() {
    try {//from  w  w  w  .j  a  v a2  s  .c  o  m
        mGifThread.start();
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        System.gc();
    }
}