Created
May 27, 2011 02:56
-
-
Save colin-haber/994558 to your computer and use it in GitHub Desktop.
JavaCon Error Stream handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thread t = null; | |
try { | |
final PipedOutputStream errOut = new PipedOutputStream(); | |
System.setErr(new PrintStream(errOut)); | |
final BufferedReader errIn = new BufferedReader(new InputStreamReader(new PipedInputStream(errOut))); | |
t = new Thread( | |
new Runnable() { | |
public void run() { | |
try { | |
this.wait(); | |
while (true) { | |
String error = errIn.readLine(); | |
print(error); | |
} | |
} catch (IOException e){ | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
, "ERROR"); | |
t.start(); | |
} catch (Exception e) { | |
} | |
//GUI creation | |
t.notify(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this work for anyone else? I'm having problems actually creating errors. They only show up on the JavaCon every once in a while. And I guarantee, I have enough cores.