List of usage examples for java.lang OutOfMemoryError getMessage
public String getMessage()
From source file:Main.java
public static Bitmap load(byte[] data, int inSampleSize) { try {// www. j a v a2 s . c o m Options opts = new Options(); opts.inSampleSize = inSampleSize; opts.inDither = false; opts.inPreferredConfig = Config.ARGB_8888; Bitmap result = BitmapFactory.decodeByteArray(data, 0, data.length, opts); return result == null ? EMPTY_BITMAP : result; } catch (OutOfMemoryError e) { Log.e("LoadImage", e.getMessage(), e); } return EMPTY_BITMAP; }
From source file:Main.java
public static Bitmap load(InputStream inputStream, int inSampleSize) { try {/*from w w w.jav a 2 s. co m*/ Options opts = new Options(); opts.inSampleSize = inSampleSize; opts.inDither = false; opts.inPreferredConfig = Config.ARGB_8888; Bitmap result = BitmapFactory.decodeStream(inputStream, null, opts); return result == null ? EMPTY_BITMAP : result; } catch (OutOfMemoryError e) { Log.e("LoadImage", e.getMessage(), e); } return EMPTY_BITMAP; }
From source file:Main.java
public static Bitmap load(ContentResolver contentResolver, Uri uri, int minSideLen, int maxSize) { Bitmap result = EMPTY_BITMAP;/*ww w . j av a2 s . co m*/ try { Options opts = new Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeStream(contentResolver.openInputStream(uri), null, opts); result = load(contentResolver.openInputStream(uri), computeSampleSize(opts, minSideLen, maxSize)); if (isMediaUri(uri) && result != null && result != EMPTY_BITMAP) { result = rotateMediaImage(contentResolver, uri, result); } } catch (OutOfMemoryError e) { Log.e("LoadImage", e.getMessage(), e); } catch (IOException e) { Log.e("LoadImage", e.getMessage(), e); } if (result == null) { result = EMPTY_BITMAP; } return result; }
From source file:com.geekandroid.sdk.pay.utils.Util.java
public static Bitmap extractThumbNail(final String path, final int height, final int width, final boolean crop) { Assert.assertTrue(path != null && !path.equals("") && height > 0 && width > 0); BitmapFactory.Options options = new BitmapFactory.Options(); try {/* w ww .jav a 2s. c om*/ options.inJustDecodeBounds = true; Bitmap tmp = BitmapFactory.decodeFile(path, options); if (tmp != null) { tmp.recycle(); tmp = null; } Log.d(TAG, "extractThumbNail: round=" + width + "x" + height + ", crop=" + crop); final double beY = options.outHeight * 1.0 / height; final double beX = options.outWidth * 1.0 / width; Log.d(TAG, "extractThumbNail: extract beX = " + beX + ", beY = " + beY); options.inSampleSize = (int) (crop ? (beY > beX ? beX : beY) : (beY < beX ? beX : beY)); if (options.inSampleSize <= 1) { options.inSampleSize = 1; } // NOTE: out of memory error while (options.outHeight * options.outWidth / options.inSampleSize > MAX_DECODE_PICTURE_SIZE) { options.inSampleSize++; } int newHeight = height; int newWidth = width; if (crop) { if (beY > beX) { newHeight = (int) (newWidth * 1.0 * options.outHeight / options.outWidth); } else { newWidth = (int) (newHeight * 1.0 * options.outWidth / options.outHeight); } } else { if (beY < beX) { newHeight = (int) (newWidth * 1.0 * options.outHeight / options.outWidth); } else { newWidth = (int) (newHeight * 1.0 * options.outWidth / options.outHeight); } } options.inJustDecodeBounds = false; Log.i(TAG, "bitmap required size=" + newWidth + "x" + newHeight + ", orig=" + options.outWidth + "x" + options.outHeight + ", sample=" + options.inSampleSize); Bitmap bm = BitmapFactory.decodeFile(path, options); if (bm == null) { Log.e(TAG, "bitmap decode failed"); return null; } Log.i(TAG, "bitmap decoded size=" + bm.getWidth() + "x" + bm.getHeight()); final Bitmap scale = Bitmap.createScaledBitmap(bm, newWidth, newHeight, true); if (scale != null) { bm.recycle(); bm = scale; } if (crop) { final Bitmap cropped = Bitmap.createBitmap(bm, (bm.getWidth() - width) >> 1, (bm.getHeight() - height) >> 1, width, height); if (cropped == null) { return bm; } bm.recycle(); bm = cropped; Log.i(TAG, "bitmap croped size=" + bm.getWidth() + "x" + bm.getHeight()); } return bm; } catch (final OutOfMemoryError e) { Log.e(TAG, "decode bitmap failed: " + e.getMessage()); options = null; } return null; }
From source file:com.josephblough.sbt.transport.SbaTransport.java
private static LicenseAndPermitDataCollection getLicenseAndPermitData(final String url) { try {//from w w w . j av a 2s . c o m HttpClient client = new DefaultHttpClient(); Log.d(TAG, "url: " + url); HttpGet httpMethod = new HttpGet(url); ResponseHandler<String> handler = new BasicResponseHandler(); String response = client.execute(httpMethod, handler); JSONObject json = new JSONObject(response); return processLicenseAndPermitData(json); } catch (OutOfMemoryError e) { return null; } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } return null; }
From source file:com.josephblough.sbt.transport.SbaTransport.java
private static List<LoanAndGrantData> getLoansAndGrantsData(final String url) { try {/* www. j a v a2 s . co m*/ HttpClient client = new DefaultHttpClient(); Log.d(TAG, "url: " + url); HttpGet httpMethod = new HttpGet(url); ResponseHandler<String> handler = new BasicResponseHandler(); String response = client.execute(httpMethod, handler); JSONArray array = new JSONArray(response); return processLoansAndGrantsData(array); } catch (OutOfMemoryError e) { return null; } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } return null; }
From source file:com.josephblough.sbt.transport.SbaTransport.java
private static List<RecommendedSite> getRecommendedSites(final String url) { try {/* w w w.j av a2s.c o m*/ HttpClient client = new DefaultHttpClient(); Log.d(TAG, "url: " + url); HttpGet httpMethod = new HttpGet(url); ResponseHandler<String> handler = new BasicResponseHandler(); String response = client.execute(httpMethod, handler); JSONArray array = new JSONArray(response); return processRecommendedSites(array); } catch (OutOfMemoryError e) { return null; } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } return null; }
From source file:com.josephblough.sbt.transport.SbaTransport.java
private static List<LocalityWebData> getWebData(final String url) { try {/*from www.j a va 2s. c om*/ HttpClient client = new DefaultHttpClient(); Log.d(TAG, "url: " + url); HttpGet httpMethod = new HttpGet(url); ResponseHandler<String> handler = new BasicResponseHandler(); String response = client.execute(httpMethod, handler); JSONArray array = new JSONArray(response); return processWebData(array); } catch (OutOfMemoryError e) { return null; } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } return null; }
From source file:im.vector.util.BugReporter.java
/** * Read the file content as String//from w w w . j a v a2 s. c o m * * @param fin the input file * @return the file content as String */ private static String convertStreamToString(File fin) { Reader reader = null; try { Writer writer = new StringWriter(); InputStream inputStream = new FileInputStream(fin); try { reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); int n; char[] buffer = new char[2048]; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { try { if (null != reader) { reader.close(); } } catch (Exception e) { Log.e(LOG_TAG, "## convertStreamToString() failed to close inputStream " + e.getMessage()); } } return writer.toString(); } catch (Exception e) { Log.e(LOG_TAG, "## convertStreamToString() failed " + e.getMessage()); } catch (OutOfMemoryError oom) { Log.e(LOG_TAG, "## convertStreamToString() failed " + oom.getMessage()); } finally { try { if (null != reader) { reader.close(); } } catch (Exception e) { Log.e(LOG_TAG, "## convertStreamToString() failed to close inputStream " + e.getMessage()); } } return ""; }
From source file:org.executequery.gui.text.TextUtilities.java
public static void insertFromFile(JTextComponent textComponent) { StringBuffer buf = null;//from w w w. j a v a 2 s . com String text = null; FileChooserDialog fileChooser = new FileChooserDialog(); fileChooser.setDialogTitle("Insert from file"); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); fileChooser.setDialogType(JFileChooser.OPEN_DIALOG); int result = fileChooser.showDialog(GUIUtilities.getInFocusDialogOrWindow(), "Insert"); if (result == JFileChooser.CANCEL_OPTION) return; File file = fileChooser.getSelectedFile(); try { FileInputStream input = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(input)); buf = new StringBuffer(10000); char newLine = '\n'; while ((text = reader.readLine()) != null) buf.append(text).append(newLine); reader.close(); reader = null; input.close(); input = null; int index = textComponent.getCaretPosition(); StringBuffer sb = new StringBuffer(textComponent.getText()); sb.insert(index, buf.toString()); textComponent.setText(sb.toString()); textComponent.setCaretPosition(index + buf.length()); } catch (OutOfMemoryError e) { buf = null; text = null; System.gc(); GUIUtilities.displayErrorMessage("Out of Memory.\nThe file is " + "too large to\nopen for viewing."); } catch (IOException e) { e.printStackTrace(); StringBuffer sb = new StringBuffer(); sb.append("An error occurred opening the selected file.").append("\n\nThe system returned:\n") .append(e.getMessage()); GUIUtilities.displayExceptionErrorDialog(sb.toString(), e); } }