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.ibuildapp.romanblack.CataloguePlugin.imageloader.Utils.java

public static Bitmap processBitmap(String fileName, Bitmap.Config config, int widthLimit) {
    Bitmap bitmap = null;/*  w  ww  .j a va 2  s  . c o m*/

    try {
        File tempFile = new File(fileName);
        BitmapFactory.Options opts = new BitmapFactory.Options();
        BufferedInputStream fileInputStream = new BufferedInputStream(new FileInputStream(tempFile));

        opts.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(fileInputStream, null, opts);
        fileInputStream.close();
        fileInputStream = new BufferedInputStream(new FileInputStream(tempFile));

        //Find the correct scale value. It should be the power of 2.
        int width = opts.outWidth;
        int scale = 1;

        while (true) {
            int halfWidth = width / 2;

            if (halfWidth < widthLimit && (widthLimit - halfWidth) > widthLimit / 4)
                break;

            width = halfWidth;
            scale *= 2;
        }

        opts = new BitmapFactory.Options();
        opts.inSampleSize = scale;
        opts.inPreferredConfig = config;

        try {
            System.gc();
            bitmap = BitmapFactory.decodeStream(fileInputStream, null, opts);

            if (bitmap != null)
                return bitmap;
        } catch (Exception ex) {
        } catch (OutOfMemoryError e) {
        }

        fileInputStream.close();
        fileInputStream = new BufferedInputStream(new FileInputStream(tempFile));

        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        try {
            System.gc();
            bitmap = BitmapFactory.decodeStream(fileInputStream, null, opts);

            if (bitmap != null)
                return bitmap;
        } catch (Exception ex) {
        } catch (OutOfMemoryError ex) {
        }

        fileInputStream.close();
        fileInputStream = new BufferedInputStream(new FileInputStream(tempFile));

        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        try {
            System.gc();
            bitmap = BitmapFactory.decodeStream(fileInputStream, null, opts);
        } catch (Exception ex) {
        } catch (OutOfMemoryError ex) {
        }

        fileInputStream.close();
    } catch (Exception exception) {
        exception.printStackTrace();
    }

    return bitmap;
}

From source file:specminers.referenceparser.graphvizdot.Main.java

public static void performConversion(Map<String, String> options)
        throws IOException, TransformerException, ParserConfigurationException {

    File dotFilesFolder = new File(options.get(PATH_OPTION));
    String[] extensions = new String[] { "dot" };
    boolean directConversion = options.containsKey(DIRECT_CONVERSION_OPTION);
    File outputDir = null;//from   w  w  w. j ava2  s  .  c o  m

    if (options.containsKey(OUTPUT_OPTION)) {
        outputDir = new File(options.get(OUTPUT_OPTION));
    }

    List<File> specFiles = FileUtils.listFiles(dotFilesFolder, extensions, true).stream()
            .collect(Collectors.toList());

    for (File specFile : specFiles) {
        PradelsDotFilesToJffConverter converter = new PradelsDotFilesToJffConverter(specFile);
        converter.convert();
        File tempFile = File.createTempFile("jflap_", ".jff");

        if (directConversion) {

            try {
                converter.saveToFile(tempFile.getAbsolutePath());
                JffToRegexConverter regexGen = new JffToRegexConverter(tempFile);
                String classSpec = regexGen.getRegularExpression();

                if (outputDir != null && outputDir.exists()) {
                    File regexSpecFile;
                    regexSpecFile = java.nio.file.Paths.get(outputDir.getAbsolutePath(),
                            specFile.getName().replace(".dot", "") + "_regex.txt").toFile();
                    FileUtils.writeStringToFile(regexSpecFile, classSpec);
                } else {
                    System.out.println("Specification for file " + specFile.getName());
                    System.out.println(classSpec);
                }
            } catch (RuntimeException exception) {
                System.err.println("The automaton corresponding to the file " + specFile.getPath()
                        + " seems to have some problems, like the lack of initial or final states, or multiple final states. Check this before trying to convert this file. Error message sent by the converter "
                        + exception);
                exception.printStackTrace();
            } catch (OutOfMemoryError t) {
                System.err.println("The automaton corresponding to the file " + specFile.getPath()
                        + " seems to have some problems, like the lack of initial or final states, or multiple final states. Check this before trying to convert this file. Error message sent by the converter "
                        + t);
                t.printStackTrace();
            }
        } else {
            // Just want to save the jflap files
            if (outputDir != null && outputDir.exists()) {
                File jffFile;
                jffFile = java.nio.file.Paths.get(outputDir.getAbsolutePath(),
                        specFile.getName().replace(".dot", "") + "_jflap_automaton.jff").toFile();
                converter.saveToFile(jffFile.getAbsolutePath());
            } else {
                System.out.println("JFlap file for dot file " + specFile.getName());
                System.out.println(converter.getAsJffFormat());
            }
        }
    }
}

From source file:org.openbel.framework.tools.PhaseApplication.java

/**
 * Directs phase application lifecycle./*from  w w  w . jav  a2  s  .  c o m*/
 *
 * @param phase Phase application
 */
protected static void harness(PhaseApplication phase) {
    try {
        phase.start();
        phase.stop();
        phase.end();
    } catch (BELRuntimeException bre) {
        err.println(bre.getUserFacingMessage());
        systemExit(bre.getExitCode());
    } catch (OutOfMemoryError oom) {
        err.println();
        oom.printStackTrace();
        long upperlimit = getRuntime().maxMemory();
        double ulMB = upperlimit * 9.53674316e-7;
        final NumberFormat fmt = new DecimalFormat("#0");
        String allocation = fmt.format(ulMB);
        err.println("\n(current allocation is " + allocation + " MB)");
        systemExit(ExitCode.OOM_ERROR);
    }
}

From source file:edu.harvard.i2b2.analysis.queryClient.CRCQueryClient.java

public static String sendPDOQueryRequestREST(String XMLstr) {
    try {//  w  w w  .  j  av  a 2 s  .com
        MessageUtil.getInstance().setRequest("URL: " + getPDOServiceName() + "\n" + XMLstr);
        OMElement payload = getQueryPayLoad(XMLstr);
        Options options = new Options();

        targetEPR = new EndpointReference(getPDOServiceName());
        options.setTo(targetEPR);

        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(600000));
        options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(600000));

        ServiceClient sender = new ServiceClient();
        sender.setOptions(options);

        OMElement responseElement = sender.sendReceive(payload);
        // log.debug("Client Side response " + responseElement.toString());
        MessageUtil.getInstance()
                .setResponse("URL: " + getPDOServiceName() + "\n" + responseElement.toString());

        return responseElement.toString();

    } catch (AxisFault axisFault) {
        axisFault.printStackTrace();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null,
                        "Trouble with connection to the remote server, "
                                + "this is often a network error, please try again",
                        "Network Error", JOptionPane.INFORMATION_MESSAGE);
            }
        });

        return null;
    } catch (java.lang.OutOfMemoryError e) {
        e.printStackTrace();
        return "memory error";
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.linhnv.apps.maxim.utils.ImageWorker.java

public static Bitmap rotate(Bitmap b, int degrees) {
    if (degrees != 0 && b != null) {
        Matrix m = new Matrix();
        m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2);
        try {/*from   w  w  w .j av a  2s. com*/
            Bitmap b1 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true);

            // Bitmap b2 =Bitmap.c(b1, 1280, 1024, true);

            b.recycle();
            return b1;
        } catch (OutOfMemoryError ex) {
            ex.printStackTrace();
        }
    }
    return b;
}

From source file:org.executequery.gui.text.TextUtilities.java

public static void insertFromFile(JTextComponent textComponent) {
    StringBuffer buf = null;//from  w  ww  .  ja  v a2 s.co  m
    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);
    }

}

From source file:edu.harvard.i2b2.explorer.serviceClient.PDOQueryClient.java

public static String sendPDOQueryRequestREST(String XMLstr) {
    try {//from   w ww .j av a 2 s  . com

        SAXBuilder parser = new SAXBuilder();
        String xmlContent = XMLstr;
        java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
        org.jdom.Document tableDoc = parser.build(xmlStringReader);
        XMLOutputter o = new XMLOutputter();
        o.setFormat(Format.getPrettyFormat());
        StringWriter str = new StringWriter();
        o.output(tableDoc, str);
        //jMessageTextArea.setText(str.toString());
        //text.setText(str.toString());

        MessageUtil.getInstance().setRequest("URL: " + getPDOServiceName() + "\n" + str);
        OMElement payload = getQueryPayLoad(XMLstr);
        Options options = new Options();

        targetEPR = new EndpointReference(getPDOServiceName());
        options.setTo(targetEPR);

        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(600000));
        options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(600000));

        ServiceClient sender = new ServiceClient();
        sender.setOptions(options);

        OMElement responseElement = sender.sendReceive(payload);
        // log.debug("Client Side response " + responseElement.toString());
        xmlStringReader = new java.io.StringReader(responseElement.toString());
        tableDoc = parser.build(xmlStringReader);
        o = new XMLOutputter();
        o.setFormat(Format.getPrettyFormat());
        str = new StringWriter();
        o.output(tableDoc, str);
        MessageUtil.getInstance().setResponse("URL: " + getPDOServiceName() + "\n" + str); //responseElement.toString());

        return responseElement.toString();

    } catch (AxisFault axisFault) {
        axisFault.printStackTrace();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null,
                        "Trouble with connection to the remote server, "
                                + "this is often a network error, please try again",
                        "Network Error", JOptionPane.INFORMATION_MESSAGE);
            }
        });

        return null;
    } catch (java.lang.OutOfMemoryError e) {
        e.printStackTrace();
        return "memory error";
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.evosuite.regression.ObjectFields.java

private static Object getFieldValue(Field field, Object p) {
    try {/* w w w .  ja v  a 2 s.c om*/
        /*Class objClass = p.getClass();
        if(p instanceof java.lang.String){
           ((String) p).hashCode();
        }*/
        Class<?> fieldType = field.getType();
        field.setAccessible(true);
        if (fieldType.isPrimitive()) {
            if (fieldType.equals(Boolean.TYPE)) {
                return field.getBoolean(p);
            }
            if (fieldType.equals(Integer.TYPE)) {
                return field.getInt(p);
            }
            if (fieldType.equals(Byte.TYPE)) {
                return field.getByte(p);
            }
            if (fieldType.equals(Short.TYPE)) {
                return field.getShort(p);
            }
            if (fieldType.equals(Long.TYPE)) {
                return field.getLong(p);
            }
            if (fieldType.equals(Double.TYPE)) {
                return field.getDouble(p);
            }
            if (fieldType.equals(Float.TYPE)) {
                return field.getFloat(p);
            }
            if (fieldType.equals(Character.TYPE)) {
                return field.getChar(p);
            }
            throw new UnsupportedOperationException("Primitive type " + fieldType + " not implemented!");
        }
        return field.get(p);
    } catch (IllegalAccessException exc) {
        throw new RuntimeException(exc);
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        if (MAX_RECURSION != 0)
            MAX_RECURSION = 0;
        else
            throw new RuntimeErrorException(e);
        return getFieldValue(field, p);
    }
}

From source file:com.applozic.mobicommons.file.FileUtils.java

/**
 * This method will compressed Image to a pre-configured files.
 *
 * @param filePath//from   w  w  w.  j  a va2 s. com
 * @param newFileName
 * @param maxFileSize
 * @return
 */
public static File compressImageFiles(String filePath, String newFileName, int maxFileSize) {

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);

    int actualHeight = options.outHeight;
    int actualWidth = options.outWidth;
    float imgRatio = actualWidth / actualHeight;
    int maxHeight = (2 * actualHeight) / 3;
    int maxWidth = (2 * actualWidth) / 3;

    float maxRatio = maxWidth / maxHeight;
    if (actualHeight > maxHeight || actualWidth > maxWidth) {
        if (imgRatio < maxRatio) {
            imgRatio = maxHeight / actualHeight;
            actualWidth = (int) (imgRatio * actualWidth);
            actualHeight = (int) maxHeight;
        } else if (imgRatio > maxRatio) {
            imgRatio = maxHeight / actualWidth;
            actualHeight = (int) (imgRatio * actualHeight);
            actualWidth = (int) maxWidth;
        } else {
            actualHeight = (int) maxHeight;
            actualWidth = (int) maxWidth;
        }
    }
    options.inSampleSize = ImageUtils.calculateInSampleSize(options, actualWidth, actualHeight);
    options.inJustDecodeBounds = false;

    options.inTempStorage = new byte[16 * 1024];

    try {
        bitmap = BitmapFactory.decodeFile(filePath, options);
    } catch (OutOfMemoryError exception) {
        exception.printStackTrace();

    }

    int streamLength = maxFileSize;
    int compressQuality = 100;// Maximum 20 loops to retry to maintain quality.
    ByteArrayOutputStream bmpStream = new ByteArrayOutputStream();
    while (streamLength >= maxFileSize && compressQuality > 50) {

        try {
            bmpStream.flush();
            bmpStream.reset();
        } catch (IOException e) {
            e.printStackTrace();
        }
        bitmap.compress(Bitmap.CompressFormat.JPEG, compressQuality, bmpStream);
        byte[] bmpPicByteArray = bmpStream.toByteArray();
        streamLength = bmpPicByteArray.length;
        if (BuildConfig.DEBUG) {
            Log.i("test upload", "Quality: " + compressQuality);
            Log.i("test upload", "Size: " + streamLength);
        }
        compressQuality -= 3;

    }

    FileOutputStream fo;
    try {
        fo = new FileOutputStream(newFileName);
        fo.write(bmpStream.toByteArray());
        fo.flush();
        fo.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new File(newFileName);
}

From source file:edu.harvard.i2b2.patientMapping.serviceClient.IMQueryClient.java

public static String sendValidateKeyQueryRequestREST(String XMLstr) {
    try {/*from w w  w. j  a va  2s  .c om*/

        SAXBuilder parser = new SAXBuilder();
        String xmlContent = XMLstr;
        java.io.StringReader xmlStringReader = new java.io.StringReader(xmlContent);
        org.jdom.Document tableDoc = parser.build(xmlStringReader);
        XMLOutputter o = new XMLOutputter();
        o.setFormat(Format.getPrettyFormat());
        StringWriter str = new StringWriter();
        o.output(tableDoc, str);
        //jMessageTextArea.setText(str.toString());
        //text.setText(str.toString());

        MessageUtil.getInstance().setRequest("URL: " + getValidateKeyServiceName() + "\n" + str);
        OMElement payload = getQueryPayLoad(XMLstr);
        Options options = new Options();

        targetEPR = new EndpointReference(getValidateKeyServiceName());
        options.setTo(targetEPR);

        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
        options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(600000));
        options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(600000));

        ServiceClient sender = new ServiceClient();
        sender.setOptions(options);

        OMElement responseElement = sender.sendReceive(payload);
        // log.debug("Client Side response " + responseElement.toString());
        xmlStringReader = new java.io.StringReader(responseElement.toString());
        tableDoc = parser.build(xmlStringReader);
        o = new XMLOutputter();
        o.setFormat(Format.getPrettyFormat());
        str = new StringWriter();
        o.output(tableDoc, str);
        MessageUtil.getInstance().setResponse("URL: " + getValidateKeyServiceName() + "\n" + str); //responseElement.toString());

        return responseElement.toString();

    } catch (AxisFault axisFault) {
        axisFault.printStackTrace();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JOptionPane.showMessageDialog(null,
                        "Trouble with connection to the remote server, "
                                + "this is often a network error, please try again",
                        "Network Error", JOptionPane.INFORMATION_MESSAGE);
            }
        });

        return null;
    } catch (java.lang.OutOfMemoryError e) {
        e.printStackTrace();
        return "memory error";
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}