Sure you can 'see' the 'contents' of a DataOutputStream - I imagine it wouldn't be what you expected though! I imagine what you want to be able to do is examine the data getting passed through the stream, quite impossible with the regular class - indeed the very definition of a stream is that it doesn't contain all the data being managed by it, at any one time.
If you really need to be able to audit the data that you've supplied to any output stream then you could do something like this:
import java.io.DataOutputStream;
public class WatcherOutputStream extends DataOutputStream {
private byte[] data = null;
public WatcherOutputStream(OutputStream delegateStream) {
super(delegateStream);
}
public void write(byte[] b) {
// Store the bytes internally
// Pass off to delegate
super.write(b);
}
}
The data saving code and remaining write methods are left to you as an exercise. Of course, this is a horrible way to track the data you are writing out to the stream - it's an extra layer of overhead in both memory and speed. Another options would be to use AOP to examine the data as you write it. This method has the advantages of being less intrusive to your code, and easily maintainable in that you can easily add and remove point cuts without modifying your main program. I suspect that AOP may be more complicated a solution than you are looking for right now, but I am including this link to more reading, just in case it will be helpful.