Java Newbie question :
I need to capture the text being written to a printStream by a 3rd party component.
The PrintStream is defaulted to System.err, but can be changed to another PrintStream.
Looking through the docs, I couldn't find an easy way to direct the contents of a PrintStream to a string writer / buffer.
Can someone please assist?
I use the following class to log System.out and System.err to a set of rotating files (where xxx-001.log is the most recent). It contains a few call to utility methods, which you will need to implement before it will compile - they should be self-explanatory.
You can create a PrintStream around any other OutputStream.
The simplest way to create one that goes to a buffer in memory would be:
Then you could read and reset the contents of the byte array at whatever points you like.
Another possibility would be to use pipes.
Then you could read from the third_party_output stream to get the text written by the library.
Are you looking for something like this?
If you can pass
myPrintStream
to the 3rd party application, you can redirect it anywhere you want.