Example usage for java.io FileDescriptor in

List of usage examples for java.io FileDescriptor in

Introduction

In this page you can find the example usage for java.io FileDescriptor in.

Prototype

FileDescriptor in

To view the source code for java.io FileDescriptor in.

Click Source Link

Document

A handle to the standard input stream.

Usage

From source file:Main.java

public static void main(String args[]) {
    FileDescriptor fd = FileDescriptor.in;
    System.out.println(fd.hashCode());
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    FileInputStream fis = new FileInputStream(FileDescriptor.in);

    // skip bytes from file input stream
    fis.skip(4);/*from   w w  w. j ava2  s.c  om*/

    // read bytes from this stream
    int i = fis.read();

    // converts integer to character
    char c = (char) i;
    System.out.print("Character read: " + c);
}

From source file:mitm.common.tools.CreateCA.java

public static void main(String[] args) throws Exception {
    PropertyConfigurator.configure("conf/log4j.properties");

    if (args.length != 1) {
        System.err.println("p12 file expected.");

        return;//from w  w  w  .j a  v  a 2s . c  om
    }

    System.out.println("Please enter your password: ");

    ConsoleReader consoleReader = new ConsoleReader(new FileInputStream(FileDescriptor.in),
            new PrintWriter(System.err));

    String password = consoleReader.readLine(new Character('*'));

    CreateCA createCA = new CreateCA();

    File p12File = new File(args[0]);

    createCA.generateCA(password, p12File);

    System.out.println("CA generated and written to " + p12File.getAbsolutePath());
}

From source file:com.flowpowered.commons.console.JLineConsole.java

public JLineConsole(CommandCallback callback, Completer completer, Logger logger, int inThreadSleepTime,
        OutputStream out, InputStream in) {
    this.callback = callback;
    if (logger == null) {
        this.logger = LoggerFactory.getLogger("JLineConsole");
    } else {/*from   w  ww .  j  a  va2  s .  c  om*/
        this.logger = logger;
    }
    if (out == null) {
        out = System.out;
    }
    if (in == null) {
        in = new FileInputStream(FileDescriptor.in);
    }

    if (inThreadSleepTime != INPUT_THREAD_BLOCK) {
        in = new InterruptableInputStream(in, inThreadSleepTime);
    }

    try {
        reader = new ConsoleReader(in, out);
    } catch (IOException e) {
        throw new ExceptionInInitializerError(e);
    }

    setupConsole(reader);

    @SuppressWarnings("unchecked")
    final Collection<Completer> oldCompleters = reader.getCompleters();
    for (Completer c : new ArrayList<>(oldCompleters)) {
        reader.removeCompleter(c);
    }
    reader.addCompleter(completer);

    commandThread = new ConsoleCommandThread();
    commandThread.start();
}

From source file:com.spotify.heroic.HeroicShell.java

static void runInteractiveShell(final CoreInterface core) throws Exception {
    final List<CommandDefinition> commands = new ArrayList<>(core.commands());

    commands.add(new CommandDefinition("clear", ImmutableList.of(), "Clear the current shell"));
    commands.add(new CommandDefinition("timeout", ImmutableList.of(), "Get or set the current task timeout"));
    commands.add(new CommandDefinition("exit", ImmutableList.of(), "Exit the shell"));

    try (final FileInputStream input = new FileInputStream(FileDescriptor.in)) {
        final HeroicInteractiveShell interactive = HeroicInteractiveShell.buildInstance(commands, input);

        try {//w ww . j a  v  a  2  s. c o m
            interactive.run(core);
        } finally {
            interactive.shutdown();
        }
    }
}

From source file:mitm.common.tools.SMIME.java

/**
 * @param args/*from ww w.j a  v  a  2  s  .  c o m*/
 * @throws CryptoMessageSyntaxException
 */
public static void main(String[] args) {
    try {
        PropertyConfigurator.configure("conf/tools.log4j.properties");

        InitializeBouncycastle.initialize();

        securityFactory = SecurityFactoryFactory.getSecurityFactory();

        CommandLineParser parser = new BasicParser();

        Options options = createCommandLineOptions();

        HelpFormatter formatter = new HelpFormatter();

        CommandLine commandLine;

        try {
            commandLine = parser.parse(options, args);
        } catch (ParseException e) {
            formatter.printHelp("SMIME", options, true);

            throw e;
        }

        String inFile = commandLine.getOptionValue("in");
        String keyFile = commandLine.getOptionValue("p12");
        String password = commandLine.getOptionValue("password");
        boolean binary = commandLine.hasOption("binary");
        String p7mOut = commandLine.getOptionValue("p7mOut");
        String cerOut = commandLine.getOptionValue("cerOut");
        String alias = commandLine.getOptionValue("alias");
        String digest = commandLine.getOptionValue("digest");
        String outFile = commandLine.getOptionValue("out");

        if (commandLine.hasOption("help") || args == null || args.length == 0) {
            formatter.printHelp("SMIME", options, true);

            return;
        }

        if (commandLine.hasOption("pwd")) {
            System.err.println("Please enter your password: ");

            /*
             * We will redirect the output to err so we do not get any * chars on the output.
             */
            ConsoleReader consoleReader = new ConsoleReader(new FileInputStream(FileDescriptor.in),
                    new PrintWriter(System.err));

            password = consoleReader.readLine(new Character('*'));
        }

        KeyStore keyStore = null;

        if (keyFile != null) {
            keyStore = loadKeyStore(keyFile, password);
        }

        if (commandLine.hasOption("printAliases")) {
            if (keyStore == null) {
                throw new MissingArgumentException("p12 file is missing.");
            }

            printKeystoreAliases(keyStore);
        }

        MimeMessage message;

        if (commandLine.hasOption("r")) {
            if (commandLine.hasOption("p7m")) {
                message = loadp7m(inFile, binary);

                if (commandLine.hasOption("p7mOut")) {
                    MailUtils.writeMessage(message, new File(p7mOut));
                }
            } else {
                message = loadMessage(inFile);
            }

            KeyStoreKeyProvider basicKeyStore = null;

            if (keyStore != null) {
                basicKeyStore = new KeyStoreKeyProvider(keyStore, "test");

                basicKeyStore.setUseOL2010Workaround(true);
            }

            if (message == null) {
                throw new MissingArgumentException("in file is not specified");
            }

            inspectMessage(message, basicKeyStore, cerOut);
        } else if (commandLine.hasOption("sign")) {
            message = loadMessage(inFile);

            if (message == null) {
                throw new MissingArgumentException("in file is not specified");
            }

            if (StringUtils.isEmpty(outFile)) {
                throw new MissingArgumentException("out file is not specified");
            }

            sign(message, keyStore, alias, password, digest, outFile);
        }
    } catch (MissingArgumentException e) {
        System.err.println("Not all required parameters are specified. " + e);
    } catch (ParseException e) {
        System.err.println("Command line parsing error. " + e);
    } catch (Exception e) {
        logger.error("Some error ocurred", e);
    }
}

From source file:org.apache.accumulo.test.ShellServerTest.java

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    folder.create();/*from  w ww  .jav a  2s  . c om*/
    MiniAccumuloConfig cfg = new MiniAccumuloConfig(folder.newFolder("miniAccumulo"), secret);
    cluster = new MiniAccumuloCluster(cfg);
    cluster.start();

    System.setProperty("HOME", folder.getRoot().getAbsolutePath());

    // start the shell
    output = new TestOutputStream();
    shell = new Shell(
            new ConsoleReader(new FileInputStream(FileDescriptor.in), new OutputStreamWriter(output)));
    shell.setLogErrorsToConsole();
    shell.config("-u", "root", "-p", secret, "-z", cluster.getInstanceName(), cluster.getZooKeepers());
    exec("quit", true);
    shell.start();
    shell.setExit(false);

    // use reflection to call this method so it does not need to be made public
    Method method = cluster.getClass().getDeclaredMethod("exec", Class.class, String[].class);
    method.setAccessible(true);
    traceProcess = (Process) method.invoke(cluster, TraceServer.class, new String[0]);

    // give the tracer some time to start
    UtilWaitThread.sleep(1000);
}

From source file:org.dcm4che.tool.hl7snd.HL7Snd.java

private byte[] readFile(String pathname) throws IOException {
    FileInputStream in = null;//  w w w  . j ava2 s.  c o  m
    try {
        if (pathname.equals("-")) {
            in = new FileInputStream(FileDescriptor.in);
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            StreamUtils.copy(in, buf);
            return buf.toByteArray();
        } else {
            File f = new File(pathname);
            in = new FileInputStream(f);
            byte[] b = new byte[(int) f.length()];
            StreamUtils.readFully(in, b, 0, b.length);
            return b;
        }
    } finally {
        SafeClose.close(in);
    }
}

From source file:org.onehippo.forge.jcrshell.console.Terminal.java

public static final void run(InputStream input, OutputStream output) {
    String cr = System.getProperty("line.separator");
    Writer writer = new OutputStreamWriter(output);
    BufferedReader br = new BufferedReader(new InputStreamReader(input));
    try {/*from w ww  .ja  v a2s  .  c o  m*/
        consoleReader = new ConsoleReader(new FileInputStream(FileDescriptor.in), new PrintWriter(writer), null,
                new UnsupportedTerminal());
        while (br.ready()) {
            String line = br.readLine();
            if (line != null && !line.startsWith("#") && line.trim().length() > 0) {
                writer.append("Executing: ").append(line).append(cr);
                writer.flush();
                try {
                    if (!handleCommand(line)) {
                        writer.append("Command failed, exiting..").append(cr);
                        handleCommand("Exit" + cr);
                        break;
                    }
                } catch (JcrShellShutdownException e) {
                    break;
                }
            }
        }
        writer.append("Finished.").append(cr).flush();
    } catch (IOException e) {
        PrintWriter pw = new PrintWriter(writer);
        e.printStackTrace(pw);
        pw.flush();
    } finally {
        IOUtils.closeQuietly(input);
        IOUtils.closeQuietly(output);
        JcrWrapper.logout();
    }
}

From source file:org.opencms.main.CmsShell.java

/**
 * Main program entry point when started via the command line.<p>
 *
 * @param args parameters passed to the application via the command line
 *//*from  www . j  a  v  a  2 s  . c  o m*/
public static void main(String[] args) {

    boolean wrongUsage = false;
    String webInfPath = null;
    String script = null;
    String servletMapping = null;
    String defaultWebApp = null;
    String additional = null;

    if (args.length > 4) {
        wrongUsage = true;
    } else {
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.startsWith(SHELL_PARAM_BASE)) {
                webInfPath = arg.substring(SHELL_PARAM_BASE.length());
            } else if (arg.startsWith(SHELL_PARAM_SCRIPT)) {
                script = arg.substring(SHELL_PARAM_SCRIPT.length());
            } else if (arg.startsWith(SHELL_PARAM_SERVLET_MAPPING)) {
                servletMapping = arg.substring(SHELL_PARAM_SERVLET_MAPPING.length());
            } else if (arg.startsWith(SHELL_PARAM_DEFAULT_WEB_APP)) {
                defaultWebApp = arg.substring(SHELL_PARAM_DEFAULT_WEB_APP.length());
            } else if (arg.startsWith(SHELL_PARAM_ADDITIONAL_COMMANDS)) {
                additional = arg.substring(SHELL_PARAM_ADDITIONAL_COMMANDS.length());
            } else {
                System.out.println(Messages.get().getBundle().key(Messages.GUI_SHELL_WRONG_USAGE_0));
                wrongUsage = true;
            }
        }
    }
    if (wrongUsage) {
        System.out
                .println(Messages.get().getBundle().key(Messages.GUI_SHELL_USAGE_1, CmsShell.class.getName()));
    } else {

        I_CmsShellCommands additionalCommands = null;
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(additional)) {
            try {
                Class<?> commandClass = Class.forName(additional);
                additionalCommands = (I_CmsShellCommands) commandClass.newInstance();
            } catch (Exception e) {
                System.out.println(Messages.get().getBundle().key(Messages.GUI_SHELL_ERR_ADDITIONAL_COMMANDS_1,
                        additional));
                e.printStackTrace();
                return;
            }
        }
        FileInputStream stream = null;
        if (script != null) {
            try {
                stream = new FileInputStream(script);
            } catch (IOException exc) {
                System.out.println(Messages.get().getBundle().key(Messages.GUI_SHELL_ERR_SCRIPTFILE_1, script));
            }
        }
        if (stream == null) {
            // no script-file, use standard input stream
            stream = new FileInputStream(FileDescriptor.in);
        }
        CmsShell shell = new CmsShell(webInfPath, servletMapping, defaultWebApp,
                "${user}@${project}:${siteroot}|${uri}>", additionalCommands);
        shell.start(stream);
    }
}