case REDIR_GREAT:
try {
File file = new File(redir.getArg().getText());
if (isNoClobber() && file.exists()) {
throw new ShellException("File already exists");
}
out = new CommandOutput(new FileOutputStream(file));
stream = new CommandIOHolder(out, true);
} catch (IOException ex) {
throw new ShellException("Cannot open output file", ex);
}
break;
case REDIR_CLOBBER:
case REDIR_DGREAT:
try {
FileOutputStream tmp = new FileOutputStream(redir.getArg().getText(),
redir.getRedirectionType() == REDIR_DGREAT);
stream = new CommandIOHolder(new CommandOutput(tmp), true);
} catch (IOException ex) {
throw new ShellException("Cannot open output file", ex);
}
break;
case REDIR_LESS:
try {
File file = new File(redir.getArg().getText());
in = new CommandInput(new FileInputStream(file));
stream = new CommandIOHolder(in, true);
} catch (IOException ex) {
throw new ShellException("Cannot open input file", ex);
}
break;
case REDIR_LESSAND:
try {
int fromFd = Integer.parseInt(redir.getArg().getText());
stream = (fromFd >= holders.length) ? null :
new CommandIOHolder(holders[fromFd]);
} catch (NumberFormatException ex) {
throw new ShellException("Invalid fd after <&");
}
break;
case REDIR_GREATAND:
try {
int fromFd = Integer.parseInt(redir.getArg().getText());
stream = (fromFd >= holders.length) ? null :
new CommandIOHolder(holders[fromFd]);
} catch (NumberFormatException ex) {
throw new ShellException("Invalid fd after >&");
}
break;
case REDIR_LESSGREAT:
throw new UnsupportedOperationException("<>");