openFile.setMode(modes.getOpenFileFlags() | OpenFile.SYNC);
openFile.setProcess(process);
try {
if (openFile.isReadable()) {
Channel inChannel;
if (process.getInput() != null) {
// NIO-based
inChannel = process.getInput();
} else {
// Stream-based
inChannel = Channels.newChannel(process.getInputStream());
}
ChannelDescriptor main = new ChannelDescriptor(
inChannel,
getNewFileno(),
new FileDescriptor());
main.setCanBeSeekable(false);
openFile.setMainStream(new ChannelStream(getRuntime(), main));
registerDescriptor(main);
}
if (openFile.isWritable()) {
Channel outChannel;
if (process.getOutput() != null) {
// NIO-based
outChannel = process.getOutput();
} else {
outChannel = Channels.newChannel(process.getOutputStream());