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:svxconv.SVXConv.java

public static final void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
        System.out.println("   " + args[i]);
    }/*from  w  ww.j a  v a 2  s .  c o  m*/
    if (args.length == 0) {
        printf(USAGE_MSG);
        System.exit(6);
    }

    ImageIO.setUseCache(false);
    SVXConv conv = new SVXConv();

    try {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];

            if (arg.charAt(0) != '-') {
                printf("invalid key:%s\n", arg);
                printf(USAGE_MSG);
                System.exit(6);
            }

            if (arg.equals(VOXELSIZE)) {
                conv.setVoxelSize(Double.parseDouble(args[++i]));
            } else if (arg.equals(INPUT)) {
                conv.setInput(args[++i]);
            } else if (arg.equals(OUTPUT)) {
                conv.setOutput(args[++i]);
            } else if (arg.equals(MESH_ERROR_FACTOR)) {
                conv.setMeshErrorFactor(Double.parseDouble(args[++i]));
            } else if (arg.equals(MESH_MIN_PART_VOLUME)) {
                conv.setMeshMinVolume(Double.parseDouble(args[++i]));
            } else if (arg.equals(MESH_MAX_PARTS_COUNT)) {
                conv.setMeshMaxPartsCount(Integer.parseInt(args[++i]));
            } else if (arg.equals(MAX_TRIANGLES)) {
                conv.setMaxTriangles(Integer.parseInt(args[++i]));
            } else if (arg.equals(THREAD_COUNT)) {
                conv.setThreadCount(Integer.parseInt(args[++i]));
            } else if (arg.equals(MESH_SMOOTHING_WIDTH)) {
                conv.setMeshSmoothingWidth(Double.parseDouble(args[++i]));
            } else {

                System.out.println("Unknown parameter: " + arg);
                printf(USAGE_MSG);
                System.exit(6);
            }
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        printf(USAGE_MSG);
        System.exit(6);
    }

    try {
        conv.execute();
    } catch (IOException ioe) {
        System.out.println("Input file not found.");
        ioe.printStackTrace();
        System.exit(1);
    } catch (OutOfMemoryError oom) {
        System.out.println("Out of memory error.");
        oom.printStackTrace();
        System.exit(102);
    } catch (Exception e) {
        // something unexpected...
        System.out.println("Software crash.");
        e.printStackTrace();
        System.exit(101);
    }
}

From source file:com.zacwolf.commons.crypto._CRYPTOfactory.java

public static void main(String[] args) {

    final File myaeskey = new File("CypherUtilsTest_AES.key");
    final File mybfkey = new File("CypherUtilsTest_Blowfish.key");
    final File myrsakey = new File("CyperUtilsTest_RSA.key");

    try {//  w  ww  .  j  a  va2s .c o  m

        /*         if (!myrsakey.exists())
                    Crypter_RSA.generateNewKeyFile(myrsakey);
                         
                 if (!myaeskey.exists())
                    Crypter_AES.generateNewKeyFile(myaeskey);
                         
                 if (!mybfkey.exists())
                    Crypter_Blowfish.generateNewKeyFile(mybfkey);
                         
              //_CRYPTOfactory.dumpCiphers();
                         
                         
        final   Logger         logger      =   Logger.getAnonymousLogger();
          logger.setLevel(Level.ALL);
                         
        final   _CRYPTOfactory   rsacypher   =   new _CRYPTOfactory(new Crypter_RSA(myrsakey)).test(logger,args);      
                
        final   _CRYPTOfactory   aescypher   =   new   _CRYPTOfactory(new Crypter_AES(myaeskey)).test(logger,args);
              System.out.println("Crypt the AES crypter via RSA, then backagain to a new AES crypter...");
                 _CRYPTOfactory.getInstance(rsacypher.decrypt(rsacypher.encrypt(aescypher.getAsBytes()))).test(logger,args);
                
        final   _CRYPTOfactory   blocypher   =   new   _CRYPTOfactory(new Crypter_Blowfish(mybfkey)).test(logger,args);
              System.out.println("Crypt the Blowfish crypter RSA rsa, then backagain to a new Blowfish crypter...");
                 _CRYPTOfactory.getInstance(rsacypher.decrypt(rsacypher.encrypt(blocypher.getAsBytes()))).test(logger,args);
                
        final   File   keystorefile      =   new File("keystore.jks");
        final   String   keystorepass      =   args[0];
              _CRYPTOfactory.genNewKeyStore(keystorefile,keystorepass);
                    rsacypher.addCrypterToKeyStore(keystorefile, keystorepass);
                    aescypher.addCrypterToKeyStore(keystorefile, keystorepass);
                    blocypher.addCrypterToKeyStore(keystorefile, keystorepass);
                      
        */ } catch (OutOfMemoryError oom) {
        System.err.println(JVM.getMemoryStats());
        oom.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        myaeskey.delete();
        mybfkey.delete();
        myrsakey.delete();
    }
}

From source file:Main.java

static Bitmap createBitmapSafely(int width, int height, Bitmap.Config config, int retryCount) {
    while (retryCount-- > 0) {
        try {/*w  w  w. j  a  va2  s .c o m*/
            return Bitmap.createBitmap(width, height, config);
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
            System.gc();
        }
    }
    return null;
}

From source file:Main.java

private static Bitmap rotateImage(Bitmap source, float angle) {

    Bitmap bitmap = null;/*w w w  . java  2s.c  o m*/
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    try {
        bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
    } catch (OutOfMemoryError err) {
        err.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap DrawableToBitmap(Drawable drawable) {
    try {//from  www.  j  a v  a2 s . c o m
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        // canvas.setBitmap(bitmap);  
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.draw(canvas);

        return bitmap;
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static final Bitmap getBitmap(String fileName) {
    Bitmap bitmap = null;//  www . j  av  a 2s. c o  m
    try {
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(fileName, options);
        options.inSampleSize = Math.max(1, (int) Math
                .ceil(Math.max((double) options.outWidth / 1024f, (double) options.outHeight / 1024f)));
        options.inJustDecodeBounds = false;
        bitmap = BitmapFactory.decodeFile(fileName, options);
    } catch (OutOfMemoryError error) {
        error.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap takeScreenShot(View view) {
    if (null == view) {
        return null;
    }//  w  ww .j a v  a  2 s.  com

    assert view.getWidth() > 0 && view.getHeight() > 0;
    Bitmap.Config config = Bitmap.Config.ARGB_8888;

    Bitmap bitmap = null;
    try {
        bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), config);
        Canvas canvas = new Canvas(bitmap);
        view.draw(canvas);
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
    }

    return bitmap;
}

From source file:Main.java

public final static Bitmap rotationBitmap(Bitmap srcBitmap, float degrees) {
    Bitmap result = null;/* w ww . j  a v  a  2 s. c  o  m*/
    if (degrees != 0 && srcBitmap != null) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) srcBitmap.getWidth() / 2, (float) srcBitmap.getHeight() / 2);
        try {
            Bitmap b2 = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), m,
                    true);
            if (srcBitmap != b2) {
                srcBitmap.recycle();
                srcBitmap = b2;
            }
            result = b2;
        } catch (OutOfMemoryError ex) {
            ex.printStackTrace();
        }
    }
    return result;
}

From source file:Main.java

public static Bitmap decodeImage(String path) {
    try {//w w w  . ja  v  a 2  s  .  c  o m
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(path, options);
        options.inJustDecodeBounds = false;
        int be = (int) (options.outWidth / (float) ZEN_IMAGE_WIDTH);

        if (be <= 0) {
            be = 1;
        }

        options.inSampleSize = be;
        Bitmap bitmap = BitmapFactory.decodeFile(path, options);
        return bitmap;
    } catch (OutOfMemoryError error) {
        error.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Bitmap loadImage(int bitmapId, Resources resources, int tries) {
    Bitmap bitmap;//from ww w.j  a  v a  2s . co m

    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inDither = true;
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;

        bitmap = BitmapFactory.decodeResource(resources, bitmapId, options);
    } catch (OutOfMemoryError e) {
        e.printStackTrace();

        System.gc();

        if (--tries > 0) {
            return loadImage(bitmapId, resources, tries);
        } else {
            return null;
        }
    }

    return bitmap;
}