System.arraycopy(holders, 0, tmp, 0, fd + 1);
holders = tmp;
}
CommandIOHolder stream;
CommandInput in;
CommandOutput out;
switch (redir.getRedirectionType()) {
case REDIR_DLESS:
case REDIR_DLESSDASH:
String here = redir.getHereDocument();
if (redir.isHereDocumentExpandable()) {
here = dollarBacktickExpand(here).toString();
}
in = new CommandInput(new StringReader(here));
stream = new CommandIOHolder(in, true);
break;
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;