Added doc. Clean up code
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
fe4851053a
commit
fa46939c54
@ -56,6 +56,8 @@ import net.bigeon.gclc.manager.ConsoleOutput;
|
||||
* @author Emmanuel Bigeon */
|
||||
public class ExecSystemCommand extends Command {
|
||||
|
||||
/** Error message for the manager closed. */
|
||||
private static final String MANAGER_WAS_CLOSED = "manager was closed";
|
||||
/** The command default name */
|
||||
private static final String COMMAND_DEFAULT_NAME = "exec"; //$NON-NLS-1$
|
||||
/** The end of line separator */
|
||||
@ -64,12 +66,14 @@ public class ExecSystemCommand extends Command {
|
||||
private static final Logger LOGGER = Logger
|
||||
.getLogger(ExecSystemCommand.class.getName());
|
||||
|
||||
/***/
|
||||
/** Create the command with the name 'exec'. */
|
||||
public ExecSystemCommand() {
|
||||
super(COMMAND_DEFAULT_NAME);
|
||||
}
|
||||
|
||||
/** @param name the name of the command (the input from the manager that should
|
||||
/** Create the command with a custom name.
|
||||
*
|
||||
* @param name the name of the command (the input from the manager that should
|
||||
* trigger this command) */
|
||||
public ExecSystemCommand(final String name) {
|
||||
super(name);
|
||||
@ -92,7 +96,6 @@ public class ExecSystemCommand extends Command {
|
||||
final InputStream is = proc.getInputStream();
|
||||
final Thread th = new Thread(new Runnable() {
|
||||
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -110,18 +113,12 @@ public class ExecSystemCommand extends Command {
|
||||
final OutputStream os = proc.getOutputStream();
|
||||
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os))) {
|
||||
while (th.isAlive()) {
|
||||
String user;
|
||||
try {
|
||||
user = in.prompt();
|
||||
} catch (final IOException e) {
|
||||
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
|
||||
"manager was closed", e); //$NON-NLS-1$
|
||||
}
|
||||
String user = in.prompt();
|
||||
writer.write(user + EOL);
|
||||
}
|
||||
} catch (final IOException e1) {
|
||||
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
|
||||
"manager was closed", e1); //$NON-NLS-1$
|
||||
MANAGER_WAS_CLOSED, e1); // $NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,18 +130,28 @@ public class ExecSystemCommand extends Command {
|
||||
int c;
|
||||
try {
|
||||
while ((c = is.read()) != -1) {
|
||||
try {
|
||||
out.print(Character.valueOf((char) c).toString());
|
||||
} catch (final IOException e) {
|
||||
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
|
||||
"manager was closed", e); //$NON-NLS-1$
|
||||
}
|
||||
printCharacter(out, (char) c);
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
LOGGER.log(Level.INFO, "input stream reading failed", e); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/** Print a character on the console.
|
||||
*
|
||||
* @param out the console
|
||||
* @param c the character
|
||||
* @throws CommandRunException if the console failed to print the character. */
|
||||
private void printCharacter(final ConsoleOutput out, char c)
|
||||
throws CommandRunException {
|
||||
try {
|
||||
out.print(Character.toString(c));
|
||||
} catch (final IOException e) {
|
||||
throw new CommandRunException(CommandRunExceptionType.INTERACTION,
|
||||
MANAGER_WAS_CLOSED, e); // $NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||
@Override
|
||||
|
@ -0,0 +1,8 @@
|
||||
/** This package contains classes for command execution on the system.
|
||||
* <p>
|
||||
* The class {@link net.bigeon.gclc.system.ExecSystemCommand} is, in the current
|
||||
* version (0.0.1), a source of vulnerability and should probably be used only
|
||||
* in private projects where the user is aware of the dangers.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
package net.bigeon.gclc.system;
|
Loading…
Reference in New Issue
Block a user