Example usage for java.io StringWriter StringWriter

List of usage examples for java.io StringWriter StringWriter

Introduction

In this page you can find the example usage for java.io StringWriter StringWriter.

Prototype

public StringWriter() 

Source Link

Document

Create a new string writer using the default initial string-buffer size.

Usage

From source file:Main.java

public static String getText(Node node) throws IOException {
    StringWriter writer = new StringWriter();
    if (!serializeXmlNode(node, writer, false)) {
        return null;
    }// www.  j ava2  s  .c om
    return writer.toString();
}

From source file:Main.java

public static void openFeedback(Activity activity) {
    try {//from www  .jav a2s  .co  m
        throw new Exception();
    } catch (Exception e) {
        ApplicationErrorReport report = new ApplicationErrorReport();
        report.packageName = report.processName = activity.getApplication().getPackageName();
        report.time = System.currentTimeMillis();
        report.type = ApplicationErrorReport.TYPE_CRASH;
        report.systemApp = false;
        ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo();
        crash.exceptionClassName = e.getClass().getSimpleName();
        crash.exceptionMessage = e.getMessage();
        StringWriter writer = new StringWriter();
        PrintWriter printer = new PrintWriter(writer);
        e.printStackTrace(printer);
        crash.stackTrace = writer.toString();
        StackTraceElement stack = e.getStackTrace()[0];
        crash.throwClassName = stack.getClassName();
        crash.throwFileName = stack.getFileName();
        crash.throwLineNumber = stack.getLineNumber();
        crash.throwMethodName = stack.getMethodName();
        report.crashInfo = crash;
        Intent intent = new Intent(Intent.ACTION_APP_ERROR);
        intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
        activity.startActivity(intent);
    }
}

From source file:com.opendoorlogistics.core.utils.XMLUtils.java

public static String toString(Node node) {
    try {/*from  w  w w  .  ja v  a 2  s .  co  m*/
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(node);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        transformer.transform(source, result);
        return writer.toString();
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}

From source file:org.kordamp.javatrove.example01.TestHelper.java

public static String repositoriesAsJSON(Collection<Repository> repositories, ObjectMapper objectMapper) {
    StringWriter writer = new StringWriter();
    try {//from   w  ww .j av a2 s  . c o  m
        objectMapper.writeValue(writer, repositories);
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return writer.toString();
}