java - How can I retrieve the output of an outputstream -
i'm aware outputstreams meant writing data. want retrieve own output , know out has protected access in filteroutputstream. there loop or shortcut can .out field of output stream ?
socket socket = new socket("localhost,4000); dataoutputstream data = new dataoutputstream(socket.getoutputstream()); data.writeutf("hi"); system.out.println(data.out); // want achieve.
to out
field, derive subclass of dataoutputstream , make output stream publicly retrievable:
class yourdataoutputstream extends dataoutputstream { public outputstream getout() { return out; } }
however, if want capture data sent out on socket, not want, since return output stream object returned socket. could, however, write subclass of filteroutputstream overrides write() methods print out data coming through, or store in array or file, before writing data underlying output stream. override methods like:
public void write(int databyte) { system.out.println(databyte); out.write(databyte); }
you construct instance of class on socket's output stream, , construct dataoutputstream on instance of class.
Comments
Post a Comment