I’m looking at a class which takes an OutputStream object via its constructor and the uses it to create a PrintStream object as follows:
this.pout = new PrintStream(out);
Then this class uses the pout object in the following manner in a number of places in the class implementation:
String string;
...
pout.print(string);
pout.flush();
Am I correct in saying that the use of PrintStream here is pointless and that this would have done the same job:
this.out = out
...
out.print(string);
out.flush();
where out is of type OutputStream.
Also, I am using this class to write out a command on an a ssh2 connection. I then use a class implementing InputStream to read back the response. Is there any behind the scenes syncing between OutputStream and InputStream or should I always call flush before polling for a reply?
The second snippet is invalid.
OutputStreamdoes not have aprint()method.This depends on the mechanics of the actual stream classes that you’re using. If in doubt, use
flush().