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.ichi2.async.Connection.java

private Payload doInBackgroundSync(Payload data) {
    // for for doInBackgroundLoadDeckCounts if any
    sIsCancellable = true;//ww  w.  ja  va 2  s  .  co m
    Timber.d("doInBackgroundSync()");
    // Block execution until any previous background task finishes, or timeout after 5s
    boolean ok = DeckTask.waitToFinish(5);

    String hkey = (String) data.data[0];
    boolean media = (Boolean) data.data[1];
    String conflictResolution = (String) data.data[2];
    Collection col = CollectionHelper.getInstance().getCol(AnkiDroidApp.getInstance());

    boolean colCorruptFullSync = false;
    if (!CollectionHelper.getInstance().colIsOpen() || !ok) {
        if (conflictResolution != null && conflictResolution.equals("download")) {
            colCorruptFullSync = true;
        } else {
            data.success = false;
            data.result = new Object[] { "genericError" };
            return data;
        }
    }
    try {
        CollectionHelper.getInstance().lockCollection();
        HttpSyncer server = new RemoteServer(this, hkey);
        Syncer client = new Syncer(col, server);

        // run sync and check state
        boolean noChanges = false;
        if (conflictResolution == null) {
            Timber.i("Sync - starting sync");
            publishProgress(R.string.sync_prepare_syncing);
            Object[] ret = client.sync(this);
            data.message = client.getSyncMsg();
            if (ret == null) {
                data.success = false;
                data.result = new Object[] { "genericError" };
                return data;
            }
            String retCode = (String) ret[0];
            if (!retCode.equals("noChanges") && !retCode.equals("success")) {
                data.success = false;
                data.result = ret;
                // Check if there was a sanity check error
                if (retCode.equals("sanityCheckError")) {
                    // Force full sync next time
                    col.modSchemaNoCheck();
                    col.save();
                }
                return data;
            }
            // save and note success state
            if (retCode.equals("noChanges")) {
                // publishProgress(R.string.sync_no_changes_message);
                noChanges = true;
            } else {
                // publishProgress(R.string.sync_database_acknowledge);
            }
        } else {
            try {
                // Disable sync cancellation for full-sync
                sIsCancellable = false;
                server = new FullSyncer(col, hkey, this);
                if (conflictResolution.equals("upload")) {
                    Timber.i("Sync - fullsync - upload collection");
                    publishProgress(R.string.sync_preparing_full_sync_message);
                    Object[] ret = server.upload();
                    if (ret == null) {
                        data.success = false;
                        data.result = new Object[] { "genericError" };
                        CollectionHelper.getInstance().reopenCollection(); // TODO: is this needed?
                        return data;
                    }
                    if (!ret[0].equals(HttpSyncer.ANKIWEB_STATUS_OK)) {
                        data.success = false;
                        data.result = ret;
                        CollectionHelper.getInstance().reopenCollection(); // TODO: is this needed?
                        return data;
                    }
                } else if (conflictResolution.equals("download")) {
                    Timber.i("Sync - fullsync - download collection");
                    publishProgress(R.string.sync_downloading_message);
                    Object[] ret = server.download();
                    if (ret == null) {
                        data.success = false;
                        data.result = new Object[] { "genericError" };
                        CollectionHelper.getInstance().reopenCollection(); // TODO: is this needed?
                        return data;
                    }
                    if (!ret[0].equals("success")) {
                        data.success = false;
                        data.result = ret;
                        if (!colCorruptFullSync) {
                            CollectionHelper.getInstance().reopenCollection(); // TODO: is this needed?
                        }
                        return data;
                    }
                }
                col = CollectionHelper.getInstance().reopenCollection(); // TODO: is this needed?
            } catch (OutOfMemoryError e) {
                AnkiDroidApp.sendExceptionReport(e, "doInBackgroundSync-fullSync");
                data.success = false;
                data.result = new Object[] { "OutOfMemoryError" };
                return data;
            } catch (RuntimeException e) {
                if (timeoutOccured(e)) {
                    data.result = new Object[] { "connectionError" };
                } else if (e.getMessage().equals("UserAbortedSync")) {
                    data.result = new Object[] { "UserAbortedSync" };
                } else {
                    AnkiDroidApp.sendExceptionReport(e, "doInBackgroundSync-fullSync");
                    data.result = new Object[] { "IOException" };
                }
                data.success = false;
                return data;
            }
        }

        // clear undo to avoid non syncing orphans (because undo resets usn too
        if (!noChanges) {
            col.clearUndo();
        }
        // then move on to media sync
        sIsCancellable = true;
        boolean noMediaChanges = false;
        String mediaError = null;
        if (media) {
            server = new RemoteMediaServer(col, hkey, this);
            MediaSyncer mediaClient = new MediaSyncer(col, (RemoteMediaServer) server, this);
            String ret;
            try {
                ret = mediaClient.sync();
                if (ret == null) {
                    mediaError = AnkiDroidApp.getAppResources().getString(R.string.sync_media_error);
                } else {
                    if (ret.equals("noChanges")) {
                        publishProgress(R.string.sync_media_no_changes);
                        noMediaChanges = true;
                    }
                    if (ret.equals("sanityFailed")) {
                        mediaError = AnkiDroidApp.getAppResources()
                                .getString(R.string.sync_media_sanity_failed);
                    } else {
                        publishProgress(R.string.sync_media_success);
                    }
                }
            } catch (RuntimeException e) {
                if (timeoutOccured(e)) {
                    data.result = new Object[] { "connectionError" };
                } else if (e.getMessage().equals("UserAbortedSync")) {
                    data.result = new Object[] { "UserAbortedSync" };
                } else {
                    AnkiDroidApp.sendExceptionReport(e, "doInBackgroundSync-mediaSync");
                }
                mediaError = e.getLocalizedMessage();
            }
        }
        if (noChanges && (!media || noMediaChanges)) {
            data.success = false;
            data.result = new Object[] { "noChanges" };
            return data;
        } else {
            data.success = true;
            data.data = new Object[] { conflictResolution, col, mediaError };
            return data;
        }
    } catch (MediaSyncException e) {
        Timber.e("Media sync rejected by server");
        data.success = false;
        data.result = new Object[] { "mediaSyncServerError" };
        AnkiDroidApp.sendExceptionReport(e, "doInBackgroundSync");
        return data;
    } catch (UnknownHttpResponseException e) {
        Timber.e("doInBackgroundSync -- unknown response code error");
        e.printStackTrace();
        data.success = false;
        Integer code = e.getResponseCode();
        String msg = e.getLocalizedMessage();
        data.result = new Object[] { "error", code, msg };
        return data;
    } catch (Exception e) {
        // Global error catcher.
        // Try to give a human readable error, otherwise print the raw error message
        Timber.e("doInBackgroundSync error");
        e.printStackTrace();
        data.success = false;
        if (timeoutOccured(e)) {
            data.result = new Object[] { "connectionError" };
        } else if (e.getMessage().equals("UserAbortedSync")) {
            data.result = new Object[] { "UserAbortedSync" };
        } else {
            AnkiDroidApp.sendExceptionReport(e, "doInBackgroundSync");
            data.result = new Object[] { e.getLocalizedMessage() };
        }
        return data;
    } finally {
        // Close collection to roll back any sync failures and
        Timber.d("doInBackgroundSync -- closing collection on outer finally statement");
        col.close(false);
        CollectionHelper.getInstance().unlockCollection();
        Timber.d("doInBackgroundSync -- reopening collection on outer finally statement");
        CollectionHelper.getInstance().reopenCollection();
    }
}

From source file:com.irccloud.android.activity.MainActivity.java

private Uri resize(Uri in) {
    Uri out = null;/*from w w  w .ja v  a2s .  c  o  m*/
    try {
        int MAX_IMAGE_SIZE = Integer
                .parseInt(PreferenceManager.getDefaultSharedPreferences(this).getString("photo_size", "1024"));
        File imageDir = new File(Environment.getExternalStorageDirectory(), "IRCCloud");
        imageDir.mkdirs();
        new File(imageDir, ".nomedia").createNewFile();

        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(IRCCloudApplication.getInstance().getApplicationContext()
                .getContentResolver().openInputStream(in), null, o);
        int scale = 1;

        if (o.outWidth < MAX_IMAGE_SIZE && o.outHeight < MAX_IMAGE_SIZE)
            return in;

        if (o.outWidth > o.outHeight) {
            if (o.outWidth > MAX_IMAGE_SIZE)
                scale = o.outWidth / MAX_IMAGE_SIZE;
        } else {
            if (o.outHeight > MAX_IMAGE_SIZE)
                scale = o.outHeight / MAX_IMAGE_SIZE;
        }

        o = new BitmapFactory.Options();
        o.inSampleSize = scale;
        Bitmap bmp = BitmapFactory.decodeStream(IRCCloudApplication.getInstance().getApplicationContext()
                .getContentResolver().openInputStream(in), null, o);

        //ExifInterface can only work on local files, so make a temporary copy on the SD card
        out = Uri.fromFile(File.createTempFile("irccloudcapture-original", ".jpg", imageDir));
        InputStream is = IRCCloudApplication.getInstance().getApplicationContext().getContentResolver()
                .openInputStream(in);
        OutputStream os = IRCCloudApplication.getInstance().getApplicationContext().getContentResolver()
                .openOutputStream(out);
        byte[] buffer = new byte[8192];
        int len;
        while ((len = is.read(buffer)) != -1) {
            os.write(buffer, 0, len);
        }
        is.close();
        os.close();

        ExifInterface exif = new ExifInterface(out.getPath());
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
        new File(new URI(out.toString())).delete();

        out = Uri.fromFile(File.createTempFile("irccloudcapture-resized", ".jpg", imageDir));
        if (orientation > 1) {
            Matrix matrix = new Matrix();
            switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                matrix.postRotate(90);
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                matrix.postRotate(180);
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                matrix.postRotate(270);
                break;
            }
            try {
                Bitmap oldbmp = bmp;
                bmp = Bitmap.createBitmap(oldbmp, 0, 0, oldbmp.getWidth(), oldbmp.getHeight(), matrix, true);
                oldbmp.recycle();
            } catch (OutOfMemoryError e) {
                Log.e("IRCCloud", "Out of memory rotating the photo, it may look wrong on imgur");
            }
        }

        if (bmp == null || !bmp.compress(android.graphics.Bitmap.CompressFormat.JPEG, 90, IRCCloudApplication
                .getInstance().getApplicationContext().getContentResolver().openOutputStream(out))) {
            out = null;
        }
        if (bmp != null)
            bmp.recycle();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        Crashlytics.logException(e);
    } catch (OutOfMemoryError e) {
        Log.e("IRCCloud", "Out of memory rotating the photo, it may look wrong on imgur");
    }
    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("keep_photos", false)
            && in.toString().contains("irccloudcapture")) {
        try {
            new File(new URI(in.toString())).delete();
        } catch (Exception e) {
        }
    }
    if (out != null)
        return out;
    else
        return in;
}

From source file:com.peterbochs.PeterBochsDebugger.java

public static int[] getMemory(long address, int totalByte, boolean isPhysicalAddress) {
    try {// w w  w .ja v  a 2 s . co  m
        commandReceiver.clearBuffer();
        commandReceiver.shouldShow = false;
        if (isPhysicalAddress) {
            sendCommand("xp /" + totalByte + "bx " + address);
        } else {
            sendCommand("x /" + totalByte + "bx " + address);
        }
        int bytes[] = new int[totalByte];

        if (totalByte > 0) {
            float totalByte2 = totalByte - 1;
            totalByte2 = totalByte2 / 8;
            int totalByte3 = (int) Math.floor(totalByte2);
            String realEndAddressStr;
            String realStartAddressStr;
            long realStartAddress = address;
            realStartAddressStr = String.format("%08x", realStartAddress);
            long realEndAddress = realStartAddress + totalByte3 * 8;
            realEndAddressStr = String.format("%08x", realEndAddress);
            String result = commandReceiver.getCommandResult(realStartAddressStr, realEndAddressStr, null);
            if (result != null) {
                String[] lines = result.split("\n");
                int offset = 0;
                // System.out.println(result);
                for (int y = 0; y < lines.length; y++) {
                    String[] b = lines[y].replaceFirst("^.*:", "").split("\t");
                    // System.out.println(lines[y]);

                    for (int x = 1; x < b.length && offset < totalByte; x++) {
                        // System.out.println(offset + "==" + x);
                        bytes[offset] = (int) CommonLib.string2long(b[x]);
                        offset++;
                    }
                }
            }
        }
        return bytes;
    } catch (OutOfMemoryError ex) {
        System.gc();
        ex.printStackTrace();
        return null;
    }

}

From source file:com.peterbochs.PeterBochsDebugger.java

protected void updateOSDebugInfo() {
    long size = 0;
    try {//from   w w w.ja v a  2  s.c  om
        String magicByte = getMemoryStr(Global.osDebug, 8, true);
        CardLayout cl = (CardLayout) (jOSDebugStandardPanel.getLayout());
        if (magicByte.equals("PETER---")) {
            size = CommonLib.getInt(getMemory(Global.osDebug + 8, 4, true), 0);
            String xml = getMemoryStr(Global.osDebug + 12, (int) size, true).trim();
            // xml = CommonLib.readFile("test.xml");
            OSDebugInfoHelper.jOSDebugInformationPanel = jOSDebugInformationPanel1;

            OSDebugInfoHelper.addData(magicByte, size, xml);
            this.jOSDebugInformationPanel1.jXMLEditorPane.setText(xml);
            cl.show(jOSDebugStandardPanel, "jOSDebugInformationPanel1");
        } else {
            cl.show(jOSDebugStandardPanel, "OS debug error label");
        }
    } catch (OutOfMemoryError ex) {
        System.gc();
        System.out.println("Size probably too large? size=" + size);
        ex.printStackTrace();
    }
}

From source file:com.android.vending.billing.InAppBillingService.LACK.listAppsFragment.java

public void contextcreateapk() {
      ArrayList localArrayList = new ArrayList();
      if (pli.custom) {
          localArrayList.add(Integer.valueOf(2131165385));
      }/*  ww w  .  ja  v a  2  s . co  m*/
      localArrayList.add(Integer.valueOf(2131165386));
      localArrayList.add(Integer.valueOf(2131165384));
      localArrayList.add(Integer.valueOf(2131165389));
      localArrayList.add(Integer.valueOf(2131165263));
      menu_adapt = new ArrayAdapter(getContext(), 2130968623, localArrayList) {
          public View getView(int paramAnonymousInt, View paramAnonymousView, ViewGroup paramAnonymousViewGroup) {
              Object localObject = paramAnonymousView;
              paramAnonymousView = (View) localObject;
              if (localObject == null) {
                  paramAnonymousView = ((LayoutInflater) listAppsFragment.getInstance()
                          .getSystemService("layout_inflater")).inflate(2130968623, paramAnonymousViewGroup,
                                  false);
              }
              paramAnonymousViewGroup = (TextView) paramAnonymousView.findViewById(2131558462);
              localObject = (ImageView) paramAnonymousView.findViewById(2131558461);
              ((ImageView) localObject).setImageDrawable(null);
              paramAnonymousViewGroup.setTextAppearance(getContext(), listAppsFragment.getSizeText());
              paramAnonymousViewGroup.setTextColor(-1);
              for (;;) {
                  try {
                      int i = ((Integer) getItem(paramAnonymousInt)).intValue();
                      switch (i) {
                      }
                  } catch (OutOfMemoryError localOutOfMemoryError) {
                      localOutOfMemoryError.printStackTrace();
                      System.gc();
                      continue;
                      localOutOfMemoryError.setImageDrawable(listAppsFragment.getRes().getDrawable(2130837536));
                      localOutOfMemoryError.setColorFilter(Color.parseColor("#66cc66"), PorterDuff.Mode.MULTIPLY);
                      paramAnonymousViewGroup.setTextColor(Color.parseColor("#66cc66"));
                      continue;
                  } catch (Exception localException) {
                      localException.printStackTrace();
                      continue;
                      localException.setImageDrawable(listAppsFragment.getRes().getDrawable(2130837530));
                      localException.setColorFilter(Color.parseColor("#99cccc"), PorterDuff.Mode.MULTIPLY);
                      paramAnonymousViewGroup.setTextColor(Color.parseColor("#99cccc"));
                      continue;
                      localException.setImageDrawable(listAppsFragment.getRes().getDrawable(2130837536));
                      localException.setColorFilter(Color.parseColor("#66cc66"), PorterDuff.Mode.MULTIPLY);
                      paramAnonymousViewGroup.setTextColor(Color.parseColor("#66cc66"));
                      continue;
                      localException.setImageDrawable(listAppsFragment.getRes().getDrawable(2130837540));
                      localException.setColorFilter(Color.parseColor("#cc99cc"), PorterDuff.Mode.MULTIPLY);
                      paramAnonymousViewGroup.setTextColor(Color.parseColor("#cc99cc"));
                      continue;
                  }
                  paramAnonymousViewGroup.setCompoundDrawablePadding(
                          (int) (5.0F * listAppsFragment.getRes().getDisplayMetrics().density + 0.5F));
                  paramAnonymousViewGroup
                          .setText(Utils.getText(((Integer) getItem(paramAnonymousInt)).intValue()));
                  paramAnonymousViewGroup.setTypeface(null, 1);
                  return paramAnonymousView;
                  ((ImageView) localObject).setImageDrawable(listAppsFragment.getRes().getDrawable(2130837534));
                  ((ImageView) localObject).setColorFilter(Color.parseColor("#ffff99"), PorterDuff.Mode.MULTIPLY);
                  paramAnonymousViewGroup.setTextColor(Color.parseColor("#ffff99"));
              }
          }
      };
  }