StreamUtil { @SuppressWarnings(value = "DM_DEFAULT_ENCODING") public static String exceptionCallStack(final Throwable throwable) { final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final PrintWriter printWriter = new PrintWriter(byteArrayOutputStream); throwable.printStackTrace(printWriter); printWriter.close(); return new String(byteArrayOutputStream.toByteArray(), StreamUtil.DEFAULT_CHARSET); } private  StreamUtil(); static String streamToString(final InputStream stream); static String streamToString(final InputStream stream, final boolean close); static String streamToString(final InputStream stream, final Charset charset); static String streamToString(final InputStream stream, final Charset charset, final boolean close); static ByteArrayOutputStream streamToBuffer(final InputStream stream); static ByteArrayOutputStream streamToBuffer(final InputStream stream, final boolean close); static void stringToFile(final String string, final File file); static void stringToFile(final String string, final File file, final Charset charset); static void stringToStream(final String string, final OutputStream outputStream); static void stringToStream(final String string, final OutputStream outputStream, final Charset charset); static String fileToString(final File file); static String fileToString(final File file, final Charset charset); static InputStream fileToStream(final File file); static void streamToFile(final InputStream inputStream, final String outputFileName); static void streamToFile(final InputStream inputStream, final File file); static void copyFile(final File fromFile, final File toFile); static void streamToStream(final InputStream inputStream, final OutputStream outputStream); static long streamToStream(final InputStream inputStream, final OutputStream outputStream,
            final boolean close); static InputStream stringToStream(final String string); static InputStream stringToStream(final String string, final Charset charset); static int eagerRead(final InputStream stream, final byte[] buffer); static long skip(final InputStream inputStream, final long totalBytesToSkip); static void fillBuffer(final InputStream stream, final byte[] buffer); static void fillBuffer(final InputStream stream, final byte[] buffer, final int offset, final int len); static OutputStream ignoreClose(final OutputStream outputStream); @SuppressWarnings(value = "DM_DEFAULT_ENCODING") static String exceptionCallStack(final Throwable throwable); static void close(final OutputStream outputStream); static void close(final InputStream inputStream); static ByteSlice getByteSlice(final String string); static final int BUFFER_SIZE; static final String DEFAULT_CHARSET_NAME; static final Charset DEFAULT_CHARSET; static final Locale DEFAULT_LOCALE; }
@Test public void testException() { try { throw new RuntimeException(); } catch (RuntimeException ex) { String callStack = StreamUtil.exceptionCallStack(ex); Assert.assertTrue(callStack, callStack.contains("testException")); } }