Search in sources :

Example 26 with PipedReader

use of java.io.PipedReader in project Auto.js by hyb1996.

the class ScriptEngineService method getScriptTrace.

private static String getScriptTrace(Exception e) {
    try {
        PipedReader reader = new PipedReader(8192);
        PrintWriter writer = new PrintWriter(new PipedWriter(reader));
        e.printStackTrace(writer);
        writer.close();
        BufferedReader bufferedReader = new BufferedReader(reader);
        String line;
        StringBuilder scriptTrace = new StringBuilder(TextUtils.toEmptyIfNull(e.getMessage()));
        while ((line = bufferedReader.readLine()) != null) {
            if (line.trim().startsWith("at script"))
                scriptTrace.append("\n").append(line);
        }
        return scriptTrace.toString();
    } catch (IOException e1) {
        e1.printStackTrace();
        return e.getMessage();
    }
}
Also used : PipedWriter(java.io.PipedWriter) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) PipedReader(java.io.PipedReader) PrintWriter(java.io.PrintWriter)

Example 27 with PipedReader

use of java.io.PipedReader in project Java-Tutorial by gpcodervn.

the class PipeReaderExample method test.

private void test() throws IOException, InterruptedException {
    // Tạo một 'pipedWriter',
    PipedWriter pipedWriter = new PipedWriter();
    // Dữ liệu ghi vào 'pipedWriter'
    // sẽ tự động xuất hiện tại 'pipedReader'.
    pipedReader = new PipedReader(pipedWriter);
    new ThreadRead().start();
    char[] chs = new char[] { 'a', 'a', 'b', 'c', 'e' };
    // Ghi dữ liệu vào 'pipedWriter'.
    for (char ch : chs) {
        pipedWriter.write(ch);
        Thread.sleep(1000);
    }
    pipedWriter.close();
}
Also used : PipedWriter(java.io.PipedWriter) PipedReader(java.io.PipedReader)

Aggregations

PipedReader (java.io.PipedReader)27 PipedWriter (java.io.PipedWriter)22 IOException (java.io.IOException)15 BufferedReader (java.io.BufferedReader)5 StreamResult (javax.xml.transform.stream.StreamResult)3 Support_StringReader (tests.support.Support_StringReader)3 Writer (java.io.Writer)2 Templates (javax.xml.transform.Templates)2 Transformer (javax.xml.transform.Transformer)2 Test (org.junit.Test)2 ResourceConfiguration (com.oracle.svm.configure.config.ResourceConfiguration)1 JsonWriter (com.oracle.svm.configure.json.JsonWriter)1 ResourceConfigurationParser (com.oracle.svm.core.configure.ResourceConfigurationParser)1 ResourcesRegistry (com.oracle.svm.core.configure.ResourcesRegistry)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CharArrayReader (java.io.CharArrayReader)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1