Example usage for java.io FileDescriptor out

List of usage examples for java.io FileDescriptor out

Introduction

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

Prototype

FileDescriptor out

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

Click Source Link

Document

A handle to the standard output stream.

Usage

From source file:Main.java

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

From source file:Main.java

public static void main(String[] args) throws IOException {

    byte b = 66;//from  w  w  w  .  j a va2  s  . c  o m
    int i = 0;
    FileOutputStream fos = new FileOutputStream(FileDescriptor.out);

    fos.write(b);

    fos.flush();

    FileInputStream fis = new FileInputStream("C://test.txt");

    // read till the end of the file
    while ((i = fis.read()) != -1) {
        // convert integer to character
        char c = (char) i;

        System.out.print(c);
    }
    fos.close();
    fis.close();
}

From source file:de.uzk.hki.da.sb.SIPBuilder.java

public static void main(String[] args) {

    logger.setLevel(Level.ERROR);

    try {//from   www . j a va  2  s.c o m
        if (SystemUtils.IS_OS_WINDOWS)
            System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "CP850"));
        else
            System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        return;
    }

    String mainFolderPath = SIPBuilder.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    String confFolderPath, dataFolderPath;
    try {
        mainFolderPath = URLDecoder.decode(mainFolderPath, "UTF-8");
        confFolderPath = new File(mainFolderPath).getParent() + File.separator + "conf";
        dataFolderPath = new File(mainFolderPath).getParent() + File.separator + "data";
    } catch (UnsupportedEncodingException e) {
        confFolderPath = "conf";
        dataFolderPath = "data";
    }

    if (args.length == 0)
        startGUIMode(confFolderPath, dataFolderPath);
    else
        startCLIMode(confFolderPath, dataFolderPath, args);
}

From source file:de.uzk.hki.da.main.SIPBuilder.java

public static void main(String[] args) {

    TTCCLayout layout = new TTCCLayout();
    layout.setDateFormat("yyyy'-'MM'-'dd' 'HH':'mm':'ss");
    layout.setThreadPrinting(false);/*from  w  ww.  j  a v  a 2s .  c  om*/
    ConsoleAppender consoleAppender = new ConsoleAppender(layout);
    logger.addAppender(consoleAppender);
    logger.setLevel(Level.DEBUG);

    properties = new Properties();
    try {
        properties.load(new InputStreamReader(
                (ClassLoader.getSystemResourceAsStream("configuration/config.properties"))));
    } catch (FileNotFoundException e1) {
        System.exit(Feedback.GUI_ERROR.toInt());
    } catch (IOException e2) {
        System.exit(Feedback.GUI_ERROR.toInt());
    }

    try {
        if (SystemUtils.IS_OS_WINDOWS)
            System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "CP850"));
        else
            System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        return;
    }

    String mainFolderPath = SIPBuilder.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    String confFolderPath, dataFolderPath;
    try {
        mainFolderPath = URLDecoder.decode(mainFolderPath, "UTF-8");
        confFolderPath = new File(mainFolderPath).getParent() + File.separator + "conf";
        dataFolderPath = new File(mainFolderPath).getParent() + File.separator + "data";
    } catch (UnsupportedEncodingException e) {
        confFolderPath = "conf";
        dataFolderPath = "data";
    }
    System.out.println("ConfFolderPath:" + confFolderPath);
    if (args.length == 0)
        startGUIMode(confFolderPath, dataFolderPath);
    else
        startCLIMode(confFolderPath, dataFolderPath, args);
}

From source file:dk.dma.ais.store.FileExport.java

/** {@inheritDoc} */
@Override//from   w  w  w  . jav a2 s  . c  o  m
protected void run(Injector injector) throws Exception {
    AisStoreQueryBuilder b;
    if (!mmsis.isEmpty()) {
        b = AisStoreQueryBuilder.forMmsi(ArrayUtils.toPrimitive(mmsis.toArray(new Integer[0])));
        b.setFetchSize(fetchSize);
    } else if (area != null) {
        BoundingBox bbox = findBoundingBox(area);
        b = AisStoreQueryBuilder.forArea(bbox);
        b.setFetchSize(fetchSize);
    } else {
        b = AisStoreQueryBuilder.forTime();
        b.setFetchSize(fetchSize);
    }

    b.setInterval(DateTimeUtil.toInterval(interval));

    if (dryrun) {
        System.out.println(b);
        return;
    }

    CassandraConnection conn = CassandraConnection.create(keyspace, seeds);
    conn.startAsync();

    AisStoreQueryResult result = conn.execute(b);
    Iterable<AisPacket> iterableResult = result;

    if (filter != null) {
        iterableResult = Iterables.filter(iterableResult, AisPacketFilters.parseExpressionFilter(filter));
    }

    OutputStreamSink<AisPacket> sink = AisPacketOutputSinks.getOutputSink(outputFormat, columns, separator);

    FileOutputStream fos;
    if (filePath != null) {
        fos = new FileOutputStream(new File(filePath));
    } else {
        fos = new FileOutputStream(FileDescriptor.out);
    }

    sink.closeWhenFooterWritten();
    sink.writeAll(iterableResult, fos);
    conn.stopAsync();
}

From source file:com.linkedin.restli.tools.idlgen.TestRestLiResourceModelExporter.java

private void compareFiles(String actualFileName, String expectedFileName) throws Exception {
    String actualContent = readFile(actualFileName);
    String expectedContent = readFile(expectedFileName);
    if (!actualContent.trim().equals(expectedContent.trim())) {
        // Ugh... gradle
        PrintStream actualStdout = new PrintStream(new FileOutputStream(FileDescriptor.out));
        actualStdout.println(//from  www.jav  a 2s  .c o m
                "ERROR " + actualFileName + " does not match " + expectedFileName + " . Printing diff...");
        try {
            // TODO environment dependent, not cross platform
            ProcessBuilder pb = new ProcessBuilder("diff", expectedFileName, actualFileName);
            pb.redirectErrorStream();
            Process p = pb.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;

            while ((line = reader.readLine()) != null) {
                actualStdout.println(line);
                //          System.out.println(line);
            }
        } catch (Exception e) {
            // TODO Setup log4j, find appropriate test harness used in R2D2
            actualStdout.println("Error printing diff: " + e.getMessage());
        }
        fail(actualFileName + " does not match " + expectedFileName);
    }
}

From source file:com.github.vatbub.awsvpnlauncher.Main.java

/**
 * Connects to the specified instance using ssh. Output will be sent to System.out, input will be taken from System.in
 *
 * @param instanceID The id of the instance to connect to
 *//* ww  w.  jav a  2  s  . c om*/
private static void ssh(String instanceID) {
    try {
        File privateKey = new File(prefs.getPreference(Property.privateKeyFile));
        DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
        List<String> instanceId = new ArrayList<>(1);
        instanceId.add(instanceID);
        describeInstancesRequest.setInstanceIds(instanceId);
        DescribeInstancesResult describeInstancesResult = client.describeInstances(describeInstancesRequest);
        Instance instance = describeInstancesResult.getReservations().get(0).getInstances().get(0);

        String sshIp = instance.getPublicDnsName();

        // SSH config
        FOKLogger.info(Main.class.getName(), "Configuring SSH...");
        Properties sshConfig = new Properties();
        sshConfig.put("StrictHostKeyChecking", "no");
        JSch jsch = new JSch();
        jsch.addIdentity(privateKey.getAbsolutePath());

        FOKLogger.info(Main.class.getName(), "Connecting using ssh to " + sshUsername + "@" + sshIp);
        session = jsch.getSession(sshUsername, sshIp, 22);

        session.setConfig(sshConfig);
        try {
            session.connect();
        } catch (Exception e) {
            FOKLogger.log(Main.class.getName(), Level.SEVERE,
                    "Could not connect to the instance due to an exception", e);
        }

        // Connected
        FOKLogger.info(Main.class.getName(),
                "Connection established, connected to " + sshUsername + "@" + sshIp);

        Channel channel = session.openChannel("shell");

        if (posix.isatty(FileDescriptor.out)) {
            FOKLogger.info(Main.class.getName(), "Connected to a tty, disabling colors...");
            // Disable colors
            ((ChannelShell) channel).setPtyType("vt102");
        }

        channel.setInputStream(copyAndFilterInputStream());
        channel.setOutputStream(new MyPrintStream());
        channel.connect();

        NullOutputStream nullOutputStream = new NullOutputStream();
        Thread watchForSSHDisconnectThread = new Thread(() -> {
            while (channel.isConnected()) {
                nullOutputStream.write(0);
            }
            // disconnected
            System.exit(0);
        });
        watchForSSHDisconnectThread.setName("watchForSSHDisconnectThread");
        watchForSSHDisconnectThread.start();

    } catch (JSchException | IOException e) {
        FOKLogger.log(Main.class.getName(), Level.SEVERE, "An error occurred", e);
    }
}

From source file:org.dcm4che.tool.mkkos.MkKOS.java

public void writeKOS() throws IOException {
    DicomOutputStream dos = new DicomOutputStream(
            new BufferedOutputStream(
                    fname != null ? new FileOutputStream(fname) : new FileOutputStream(FileDescriptor.out)),
            nofmi ? UID.ImplicitVRLittleEndian : UID.ExplicitVRLittleEndian);
    dos.setEncodingOptions(encOpts);/*from ww w .  j a  v a2 s .c om*/
    try {
        dos.writeDataset(nofmi ? null : kos.createFileMetaInformation(tsuid), kos);
    } finally {
        dos.close();
    }
}

From source file:org.dcm4che.tool.xml2dcm.Xml2Dcm.java

public static void main(String[] args) {
    try {/*from   www . j a v a 2  s.com*/
        CommandLine cl = parseComandLine(args);
        Xml2Dcm main = new Xml2Dcm();
        configureBulkdata(main, cl);
        if (cl.hasOption("t")) {
            main.setTransferSyntax(cl.getOptionValue("t"));
        }
        main.setWithFileMetaInformation(cl.hasOption("f"));
        main.setNoFileMetaInformation(cl.hasOption("F"));
        main.setEncodingOptions(CLIUtils.encodingOptionsOf(cl));
        try {
            if (cl.hasOption("i")) {
                String fname = cl.getOptionValue("i");
                if (fname.equals("-")) {
                    main.parse(new DicomInputStream(System.in));
                } else {
                    DicomInputStream dis = new DicomInputStream(new File(fname));
                    try {
                        main.parse(dis);
                    } finally {
                        dis.close();
                    }
                }
            }

            if (cl.hasOption("x"))
                main.mergeXML(cl.getOptionValue("x"));

            OutputStream out = cl.hasOption("o") ? new FileOutputStream(cl.getOptionValue("o"))
                    : new FileOutputStream(FileDescriptor.out);
            try {
                main.writeTo(out);
            } finally {
                out.close();
            }
        } finally {
            if (!cl.hasOption("keep-blk-files"))
                main.delBulkDataFiles();
        }
    } catch (ParseException e) {
        System.err.println("xml2dcm: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("xml2dcm: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.json2dcm.Json2Dcm.java

public static void main(String[] args) {
    try {// ww  w  . j  a v a2 s . c o  m
        CommandLine cl = parseComandLine(args);
        Json2Dcm main = new Json2Dcm();
        configureBulkdata(main, cl);
        if (cl.hasOption("t")) {
            main.setTransferSyntax(cl.getOptionValue("t"));
        }
        main.setWithFileMetaInformation(cl.hasOption("f"));
        main.setNoFileMetaInformation(cl.hasOption("F"));
        main.setEncodingOptions(CLIUtils.encodingOptionsOf(cl));
        try {
            if (cl.hasOption("i")) {
                String fname = cl.getOptionValue("i");
                if (fname.equals("-")) {
                    main.parse(new DicomInputStream(System.in));
                } else {
                    DicomInputStream dis = new DicomInputStream(new File(fname));
                    try {
                        main.parse(dis);
                    } finally {
                        dis.close();
                    }
                }
            }

            if (cl.hasOption("j"))
                main.mergeJSON(cl.getOptionValue("j"));

            OutputStream out = cl.hasOption("o") ? new FileOutputStream(cl.getOptionValue("o"))
                    : new FileOutputStream(FileDescriptor.out);
            try {
                main.writeTo(out);
            } finally {
                out.close();
            }
        } finally {
            if (!cl.hasOption("keep-blk-files"))
                main.delBulkDataFiles();
        }
    } catch (ParseException e) {
        System.err.println("json2dcm: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("json2dcm: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}