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();
}
}
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();
}
Aggregations