Example usage for org.apache.commons.lang.exception ExceptionUtils getStackTrace

List of usage examples for org.apache.commons.lang.exception ExceptionUtils getStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.lang.exception ExceptionUtils getStackTrace.

Prototype

public static String getStackTrace(Throwable throwable) 

Source Link

Document

Gets the stack trace from a Throwable as a String.

The result of this method vary by JDK version as this method uses Throwable#printStackTrace(java.io.PrintWriter) .

Usage

From source file:ShowImage.java

public static void main(String args[]) throws IOException {
    List<File> files = ImageIOUtils.getFiles(args, new String[] { "ntf", "nsf" });

    for (Iterator iter = files.iterator(); iter.hasNext();) {
        try {//from w w  w .  ja v  a 2 s  . c om
            File file = (File) iter.next();
            log.debug("Reading: " + file.getAbsolutePath());
            NITFReader imageReader = (NITFReader) ImageIOUtils.getImageReader("nitf", file);

            for (int i = 0; i < imageReader.getRecord().getImages().length; ++i) {
                log.debug(file.getName() + "[" + i + "]");

                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                ImageSubheader subheader = imageReader.getRecord().getImages()[i].getSubheader();
                subheader.print(new PrintStream(stream));
                log.debug(stream.toString());

                try {
                    int numBands = subheader.getBandCount();
                    String irep = subheader.getImageRepresentation().getStringData().trim();
                    int bitsPerPixel = subheader.getNumBitsPerPixel().getIntData();
                    int nBytes = (bitsPerPixel - 1) / 8 + 1;

                    if (irep.equals("RGB") && numBands == 3) {
                        BufferedImage image = imageReader.read(i);
                        ImageIOUtils.showImage(image, file.getName() + "[" + i + "]", true);
                    } else {
                        // read each band, separately
                        for (int j = 0; j < numBands; ++j) {
                            if (nBytes == 1 || nBytes == 2 || nBytes == 4 || nBytes == 8) {
                                ImageReadParam readParam = imageReader.getDefaultReadParam();
                                readParam.setSourceBands(new int[] { j });
                                BufferedImage image = imageReader.read(i, readParam);
                                ImageIOUtils.showImage(image, file.getName() + "[" + i + "][" + j + "]", true);

                                ImageIO.write(image, "jpg",
                                        new FileOutputStream("image" + i + "_" + j + ".jpg"));

                                // downsample
                                // readParam.setSourceSubsampling(2, 2, 0,
                                // 0);
                                // BufferedImage smallerImage = imageReader
                                // .read(i, readParam);
                                //
                                // ImageIOUtils.showImage(smallerImage,
                                // "DOWNSAMPLED: " + file.getName());

                            }
                        }
                    }
                } catch (Exception e) {
                    System.out.println(ExceptionUtils.getStackTrace(e));
                    log.error(ExceptionUtils.getStackTrace(e));
                }
            }
        } catch (Exception e) {
            log.debug(ExceptionUtils.getStackTrace(e));
        }
    }
}

From source file:com.hortonworks.amstore.view.GenericException.java

protected static Response errorEntity(String message, Throwable e) {
    HashMap<String, Object> response = new HashMap<String, Object>();
    response.put("message", message);
    String trace = null;//from  w  ww .j a v  a2  s . com
    if (e != null)
        trace = ExceptionUtils.getStackTrace(e);
    response.put("trace", trace);
    response.put("status", STATUS);
    return Response.status(STATUS).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON).build();
}

From source file:controllers.AbstractController.java

@ExceptionHandler(Throwable.class)
public ModelAndView panic(Throwable oops) {
    ModelAndView result;/* w  w  w . j av  a  2s  . com*/

    result = new ModelAndView("misc/panic");
    result.addObject("name", ClassUtils.getShortName(oops.getClass()));
    result.addObject("exception", oops.getMessage());
    result.addObject("stackTrace", ExceptionUtils.getStackTrace(oops));

    return result;
}

From source file:com.turn.sorcerer.util.email.Emailer.java

public Emailer(String title, Exception ex) {
    this(title, ExceptionUtils.getStackTrace(ex));
}

From source file:com.mirth.connect.server.builders.ErrorMessageBuilder.java

public String buildErrorMessage(String errorType, String customMessage, Throwable e) {
    String errorSourceLine = null;

    // if the exception occured during execution of the script, get the
    // line of code that caused the error
    if (e instanceof RhinoException) {
        errorSourceLine = ((RhinoException) e).lineSource();
    }/*from w  w w.j a va  2 s .c o m*/

    // construct the error message
    StringBuilder builder = new StringBuilder();
    String stackTrace = new String();

    if (e != null) {
        stackTrace = ExceptionUtils.getStackTrace(e);
    }

    builder.append(errorType + LINE_SEPARATOR);

    if (StringUtils.isNotBlank(errorSourceLine)) {
        builder.append("ERROR SOURCE:\t");
        builder.append(errorSourceLine + LINE_SEPARATOR);
    }

    if (StringUtils.isNotBlank(customMessage)) {
        builder.append("ERROR MESSAGE:\t");
        builder.append(customMessage + LINE_SEPARATOR);
        builder.append(stackTrace + LINE_SEPARATOR);
    } else {
        builder.append(stackTrace + LINE_SEPARATOR);
    }

    return builder.toString();
}

From source file:com.playonlinux.javafx.common.ErrorMessage.java

public ErrorMessage(String message, Exception exception) {
    LOGGER.error(ExceptionUtils.getStackTrace(exception));
    alert = new Alert(Alert.AlertType.ERROR);
    alert.setTitle(translate(message));//from w w w.j  a v  a 2s .c  om
    alert.setContentText(String.format("The error was: %s", ExceptionUtils.getStackTrace(exception)));
}

From source file:com.hortonworks.amstore.view.GenericException.java

protected static String prettyTrace(Throwable e) {
    String trace = null;/* w  ww .j a va 2  s  .  com*/
    if (e != null)
        trace = ExceptionUtils.getStackTrace(e);
    return trace;
}

From source file:com.haulmont.cuba.core.sys.javacl.ClassLoaderManager.java

@Override
public String loadClass(String className) {
    try {/*from   w w w  . j  a  v a2 s  .  c  o  m*/
        Class<?> aClass = javaClassLoader.loadClass(className);
        return format("Loaded %s", aClass.toString());
    } catch (Exception e) {
        return ExceptionUtils.getStackTrace(e);
    }
}

From source file:com.haulmont.cuba.core.sys.ClassLoaderManager.java

@Override
public String loadClass(String className) {
    try {//  w w  w  . ja  va  2  s  . c om
        Class<?> aClass = scripting.loadClassNN(className);
        return format("Loaded %s", aClass.toString());
    } catch (Exception e) {
        return ExceptionUtils.getStackTrace(e);
    }
}

From source file:com.haulmont.cuba.core.jmx.ClusterManager.java

@Override
public String start() {
    try {/*from  w  w  w  .j  a  v a  2  s  . c om*/
        clusterManager.start();
        return "Done";
    } catch (Throwable e) {
        log.error("Unable to start the cluster", e);
        return ExceptionUtils.getStackTrace(e);
    }
}