Home > Archive > Java Help > November 2005 > Restoring redirected System.out
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Restoring redirected System.out
|
|
| Rob McDonald 2005-11-17, 7:03 pm |
| After you've done a "System.setOut(PrintStream out);" is there a way to
restore the initial state without explicitly storing it?
Rob
| |
|
| Rob McDonald, while chewing on bamboo shoots, wrote:
> After you've done a "System.setOut(PrintStream out);" is there a way to
> restore the initial state without explicitly storing it?
As far as I know, no there is not. I've always just kept a handle on the
old one when I set it.
--
Of making better designs there is no end,
and much refactoring wearies the body.
| |
| Boudewijn Dijkstra 2005-11-17, 7:03 pm |
| "Rob McDonald" <robm@nospam.asdl.gatech.edu> schreef in bericht
news:dliibk$bfv$1@news-int.gatech.edu...
> After you've done a "System.setOut(PrintStream out);" is there a way to
> restore the initial state without explicitly storing it?
Yes, there is. Class java.lang.FileDescriptor keeps record of the base
streams. The streams for System are usually buffered and otherwise wrapped
versions of these base streams.
| |
| Roedy Green 2005-11-17, 7:03 pm |
| On Thu, 17 Nov 2005 13:32:20 -0500, "Rob McDonald"
<robm@nospam.asdl.gatech.edu> wrote, quoted or indirectly quoted
someone who said :
>After you've done a "System.setOut(PrintStream out);" is there a way to
>restore the initial state without explicitly storing it?
System.out is a variable.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
| |
| Boudewijn Dijkstra 2005-11-20, 7:01 pm |
| "Benji" <bdg@cc.gatech.edu> schreef in bericht
news:dlli3b$kdf$1@news-int.gatech.edu...
> Boudewijn Dijkstra, while chewing on bamboo shoots, wrote:
>
>
> is it safe to create more than one file input/output stream on the same
> file descriptor?
Absolutely, as long as you can ensure that only one of them is used at any
given time.
| |
|
| Boudewijn Dijkstra, while chewing on bamboo shoots, wrote:
[color=darkred]
> Absolutely, as long as you can ensure that only one of them is used at any
> given time.
ok, well that's my point. there's no reason in using that class, since
you have to keep around some state making sure that only one of them is
being used (and I'm not sure it would be possible to make it completly
safe). You might as well just keep references to the old out vars.
--
Of making better designs there is no end,
and much refactoring wearies the body.
| |
| Boudewijn Dijkstra 2005-11-23, 9:57 pm |
| "Benji" <bdg@cc.gatech.edu> schreef in bericht
news:dlqc33$j5j$1@news-int.gatech.edu...
> Boudewijn Dijkstra, while chewing on bamboo shoots, wrote:
>
>
> ok, well that's my point. there's no reason in using that class, since
> you have to keep around some state making sure that only one of them is
> being used (and I'm not sure it would be possible to make it completly
> safe). You might as well just keep references to the old out vars.
If your design is simple/straightforward enough that it can be ensured that no
thread has cached the System or FileDescriptor streams at the moment that you
change it, then my requirement is not a problem.
| |
|
| Boudewijn Dijkstra, while chewing on bamboo shoots, wrote:
> If your design is simple/straightforward enough that it can be ensured that no
> thread has cached the System or FileDescriptor streams at the moment that you
> change it, then my requirement is not a problem.
System.out.[context switch, other stuff happens]println("yadda yadda yadda");
that's not really possible to avoid.
--
Of making better designs there is no end,
and much refactoring wearies the body.
| |
| Chris Smith 2005-11-24, 9:56 pm |
| Benji <bdg@cc.gatech.edu> wrote:
> Boudewijn Dijkstra, while chewing on bamboo shoots, wrote:
>
> System.out.[context switch, other stuff happens]println("yadda yadda yadda");
>
> that's not really possible to avoid.
Of course it is possible to avoid (in all interesting ways), if you know
what all other threads in the system will be doing. Console output is a
global side-effect, so its use would be documented in any well-designed
module or API. In a fairly basic example, you may know that there are
no other threads that will be writing to or modifying System.out.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
|
|
|
|
|