Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4274770
Votes 0
Synopsis FileDescriptor.dup() to restore io, out, and err streams
Category java:classes_io
Reported Against kestrel
Release Fixed
State 11-Closed, duplicate of 4209999, request for enhancement
Priority: 4-Low
Related Bugs 4209999 , 4271614
Submit Date 23-SEP-1999
Description
Currently its impossible to restore the standard io streams if they have been closed. One needs the flexibility to temporarily close the standard io and make System.in (out and err) use different streams and then restore the standard io streams. 

This can be achieved by duplicating FileDescriptors, i.e have the ability to create an additional entry in the File descriptor table pointing to the same file. Thus even if one of the file descriptors is freed one can still use the duplicate fd to reestablish a file stream. 

The FileDescriptors System.in(out and err) are set to -1, if the FileStream using them is closed, rendering them useless. There is no other portable way of dealing with stdio other than using file descriptors.

Assuming FileDescriptor.dup() exists, the code could look like,

....
FileDescriptor backupStdin = FileDescriptor.in.dup();
System.in.close();

// Set a different stream (file) to be used as stdin
System.setIn(....)

... Do Stuff using System.in ....

// Restore Stdin using backed up fd.
System.setIn(new BufferedInputStream(new FileInputStream(backupStdin));

... Now use regular Stdin, with System.in



  xxxxx@xxxxx   1999-09-22
Work Around
N/A
Evaluation
Possible duplicate of 4209999.
Posted Date : 2005-08-25 20:48:00.0

Yes, this is essentially the same issue as 4209999.
Posted Date : 2007-11-15 16:01:24.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang