List of usage examples for java.lang OutOfMemoryError printStackTrace
public void printStackTrace()
From source file:com.javielinux.utils.LinksUtils.java
static public String largeLink(String link) { /*/*from ww w .j a v a 2 s . c o m*/ if ( (link.contains("bit.ly")) || (link.contains("short.ie")) || (link.contains("tinyurl.com")) || (link.contains("ow.ly")) || (link.contains("ff.im")) || (link.contains("post.ly")) || (link.contains("j.mp")) || (link.contains("t.co")) ) { String url = "http://www.longurlplease.com/api/v1.1?q=" + link; HttpGet request = new HttpGet(url); HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; try { httpResponse = client.execute(request); String xml = EntityUtils.toString(httpResponse.getEntity()); JSONObject jsonObject = new JSONObject(xml); String t = jsonObject.getString(link); if ( (t!=null) && t!="") link = t; } catch (Exception e) { e.printStackTrace(); } }*/ boolean done = false; if (link.contains("goo.gl")) { try { String url = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=" + link; HttpGet request = new HttpGet(url); HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; httpResponse = client.execute(request); String xml = EntityUtils.toString(httpResponse.getEntity()); JSONObject jsonObject = new JSONObject(xml); String t = jsonObject.getString("longUrl"); if ((t != null) && t != "") { link = t; done = true; } } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } if (link.contains("kcy.me")) { //http://karmacracy.com/api/v1/kcy/2e10?appkey=tweet!t0pic try { String id = link.substring(link.lastIndexOf("/") + 1); String url = "http://karmacracy.com/api/v1/kcy/" + id + "?appkey=tweet!t0pic"; HttpGet request = new HttpGet(url); HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; httpResponse = client.execute(request); String xml = EntityUtils.toString(httpResponse.getEntity()); JSONObject jsonObject = new JSONObject(xml); String t = jsonObject.getJSONObject("data").getJSONObject("kcy").getString("url"); //Log.d(Utils.TAG, "URL: " +t); if ((t != null) && t != "") { link = t; done = true; } } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } if (!done) { try { String url = "http://www.longurlplease.com/api/v1.1?q=" + link; HttpGet request = new HttpGet(url); HttpClient client = new DefaultHttpClient(); HttpResponse httpResponse; httpResponse = client.execute(request); String xml = EntityUtils.toString(httpResponse.getEntity()); JSONObject jsonObject = new JSONObject(xml); String t = jsonObject.getString(link); if ((t != null) && t != "" && !t.equals("null")) link = t; } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } return link; }
From source file:kilim.WorkerThread.java
public void run() { try {//from w w w . ja v a 2 s. co m while (true) { Task t = getNextTask(this); // blocks until task available runningTask = t; t._runExecute(this); runningTask = null; } } catch (ShutdownException se) { // nothing to do. } catch (OutOfMemoryError ex) { log.error("Out of memory"); System.exit(1); } catch (Throwable ex) { ex.printStackTrace(); log.error(runningTask); } runningTask = null; }
From source file:com.rafamaya.imagesearch.fragment.FullImageViewFragment.java
public void setFullImage() { try {//w w w . j a v a 2 s .c o m final boolean isLocalFile = !imagePath.startsWith("http"); ImageLoader.getInstance().displayImage( !isLocalFile ? imagePath : "file://" + (new File(imagePath)).getAbsolutePath(), ivImage, options, new ImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { progress.setIndeterminate(true); progress.setVisibility(View.VISIBLE); ivImage.setImageBitmap(null); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { progress.setVisibility(View.GONE); } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { ivImage.setImageBitmap(bitmapUtils.scaleBitmap( bitmapUtils.autoRotateBitmap(loadedImage, imagePath, isLocalFile, false), view, true)); try { Bitmap bitmap = ((BitmapDrawable) ivImage.getDrawable()).getBitmap(); Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch vibrant = palette.getVibrantSwatch(); Palette.Swatch vibrantText = palette.getLightVibrantSwatch(); Palette.Swatch vibrant2Text = palette.getLightMutedSwatch(); if (vibrantText != null || vibrant2Text != null) { color = vibrantText != null ? vibrantText.getRgb() : vibrant2Text.getRgb(); colors.put(imagePath, color); if (listener != null) listener.OnImageReady(imagePath); descTextView.setTextColor(color); } if (vibrant != null) mainLayout.setBackgroundColor(vibrant.getRgb()); } }); } catch (Exception ex) { } progress.setVisibility(View.GONE); } @Override public void onLoadingCancelled(String imageUri, View view) { progress.setVisibility(View.GONE); } }); } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); progress.setVisibility(View.GONE); } }
From source file:anomalyDetector.activities.MainFeaturesActivity.java
/** * Read currently collected data//from w ww . java2 s . c o m * from external storage * @return Data that was read */ public String readCollectedData() { StringBuilder sb = new StringBuilder(); try { fInputStream = new FileInputStream(externalFile); Log.d("direktorij", externalFile.getName()); BufferedReader reader = new BufferedReader(new InputStreamReader(fInputStream, "UTF-8")); String line = null; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } fInputStream.close(); } catch (OutOfMemoryError om) { om.printStackTrace(); } catch (FileNotFoundException ex) { return null; } catch (Exception ex) { ex.printStackTrace(); } String result = sb.toString(); return result; }
From source file:com.opensource.bitmapfun.util.ImageCache.java
/** * Get from disk cache.//from ww w. ja va 2s . c om * * @param data Unique identifier for which item to get * @return The bitmap if found in cache, null otherwise */ public Bitmap getBitmapFromDiskCache(String data, Bitmap.Config config) { if (mDiskCache != null) { try { return mDiskCache.get(data, config); } catch (OutOfMemoryError error) { error.printStackTrace(); cleanMemCache(); } } return null; }
From source file:com.yunmall.ymsdk.net.http.AsyncHttpRequest.java
private CacheData loadCache(ResponseHandlerInterface responseHandlerInterface) { String cacheFileName = responseHandlerInterface.getCacheFileName(); if (TextUtils.isEmpty(cacheFileName)) { return null; }/*from w w w .j a v a2s. com*/ CacheData cacheData = new CacheData(); File file = new File(cacheFileName); cacheData.time = file.lastModified(); if (!file.exists()) { return null; } long fileSize = file.length(); if (fileSize == 0) { clearCache(cacheFileName); return null; } long time = System.currentTimeMillis() - cacheData.time; if (time > AsyncHttpClient.DEFAULT_CACHE_EXPIRATION_TIME) { clearCache(cacheFileName); return null; } FileInputStream fis = null; try { fis = new FileInputStream(file); byte[] fileData = new byte[(int) fileSize]; if (fis.read(fileData) != fileSize) { clearCache(cacheFileName); return null; } if (fileData.length <= 0) { clearCache(cacheFileName); return null; } cacheData.cacheData = fileData; return cacheData; } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); clearCache(cacheFileName); } finally { try { if (fis != null) { fis.close(); fis = null; } } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:org.repodriller.RepositoryMining.java
private void processRepos(SCMRepository repo) { log.info("Git repository in " + repo.getPath()); List<ChangeSet> allCs = range.get(repo.getScm()); if (!reverseOrder) Collections.reverse(allCs); log.info("Total of commits: " + allCs.size()); log.info("Starting threads: " + threads); ExecutorService exec = Executors.newFixedThreadPool(threads); List<List<ChangeSet>> partitions = Lists.partition(allCs, threads); for (List<ChangeSet> partition : partitions) { exec.submit(() -> {//ww w.j a va2 s . c om for (ChangeSet cs : partition) { try { processChangeSet(repo, cs); } catch (OutOfMemoryError e) { System.err.println("Commit " + cs.getId() + " in " + repo.getLastDir() + " caused OOME"); e.printStackTrace(); System.err.println("goodbye :/"); log.fatal("Commit " + cs.getId() + " in " + repo.getLastDir() + " caused OOME", e); log.fatal("Goodbye! ;/"); System.exit(-1); } catch (Throwable t) { log.error(t); } } }); } try { exec.shutdown(); exec.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException e) { log.error("error waiting for threads to terminate in " + repo.getLastDir(), e); } }
From source file:cl.ipp.katbag.fragment.SlidePageBookFragment.java
@SuppressWarnings("deprecation") public void setPictureBackground(String type_world, int scaleFactor, long id_world) { // Get the dimensions of the View int targetW = backgroundView.getWidth(); int targetH = backgroundView.getHeight(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image if (scaleFactor == -1) { if (photoW != 0 && targetW != 0 && photoH != 0 && targetH != 0) scaleFactor = Math.min(photoW / targetW, photoH / targetH); else// w w w. ja v a2s . c o m scaleFactor = 1; mainActivity.katbagHandler.updateWorld(id_world, type_world, mCurrentPhotoPath, scaleFactor); } // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true; Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); } catch (OutOfMemoryError e) { e.printStackTrace(); System.gc(); try { bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath); } catch (OutOfMemoryError e2) { e2.printStackTrace(); // handle gracefully. } } BitmapDrawable background = new BitmapDrawable(mainActivity.context.getResources(), bitmap); backgroundView.setBackgroundDrawable(background); }
From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java
public Bitmap createBitmapSafely(int width, int height, Bitmap.Config config, int retryCount) { try {//w ww .j a v a 2 s . com return Bitmap.createBitmap(width, height, config); } catch (OutOfMemoryError e) { e.printStackTrace(); if (retryCount > 0) { System.gc(); return createBitmapSafely(width, height, config, retryCount - 1); } return null; } }
From source file:com.klinker.android.twitter.activities.compose.Compose.java
public static Bitmap rotateBitmap(Bitmap bitmap, int orientation) { Log.v("talon_composing_image", "rotation: " + orientation); try {//from w w w.j a va 2 s. c om Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_NORMAL: return bitmap; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.setScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.setRotate(180); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.setRotate(180); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.setRotate(90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.setRotate(90); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.setRotate(-90); break; default: return bitmap; } try { Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.recycle(); return bmRotated; } catch (OutOfMemoryError e) { e.printStackTrace(); return null; } } catch (Exception e) { e.printStackTrace(); } return bitmap; }