Example usage for java.io IOException printStackTrace

List of usage examples for java.io IOException printStackTrace

Introduction

In this page you can find the example usage for java.io IOException printStackTrace.

Prototype

public void printStackTrace(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    File aFile = new File("C:/myFile.text");
    FileInputStream inputFile1 = null;
    FileDescriptor fd = null;/*from   w  w  w  .  ja v  a2  s  . c  om*/
    try {
        inputFile1 = new FileInputStream(aFile);
        fd = inputFile1.getFD();
    } catch (IOException e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
    FileInputStream inputFile2 = new FileInputStream(fd);
}

From source file:Main.java

public static void main(String[] args) {
    int[] x = new int[] { 1, 2, 3 };
    int[] y = new int[] { 4, 5, 6 };
    Polygon polygon = new Polygon(x, y, x.length);
    try {//from   w  ww .  j  av  a2  s  .com
        ObjectOutputStream objectOut = new ObjectOutputStream(
                new BufferedOutputStream(new FileOutputStream("Polygons.bin")));
        objectOut.writeObject(polygon);
        objectOut.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
    try {
        ObjectInputStream objectIn = new ObjectInputStream(
                new BufferedInputStream(new FileInputStream("Polygons.bin")));
        Polygon theLine = (Polygon) objectIn.readObject();
        System.out.println(theLine);
        objectIn.close();
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

From source file:Data.java

public static void main(String[] args) {
    Data data = new Data(1);
    try {/*from  ww w.  j  av a 2  s. c  o m*/
        ObjectOutputStream objectOut = new ObjectOutputStream(
                new BufferedOutputStream(new FileOutputStream("C:/test.bin")));
        objectOut.writeObject(data);
        System.out.println("1st Object written has value: " + data.getValue());
        data.setValue(2);
        objectOut.writeObject(data);
        System.out.println("2nd Object written has value: " + data.getValue());
        data.setValue(3);
        objectOut.writeObject(data);
        System.out.println("3rd Object written has value: " + data.getValue());
        objectOut.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
    try {
        ObjectInputStream objectIn = new ObjectInputStream(
                new BufferedInputStream(new FileInputStream("C:/test.bin")));
        Data data1 = (Data) objectIn.readObject();
        Data data2 = (Data) objectIn.readObject();
        Data data3 = (Data) objectIn.readObject();
        System.out.println(data1.equals(data2));
        System.out.println(data2.equals(data3));
        System.out.println(data1.getValue());
        System.out.println(data2.getValue());
        System.out.println(data3.getValue());
        objectIn.close();
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

From source file:org.fusesource.cloudmix.tests.consumer.Main.java

public static void main(String[] args) {
    if (args.length > 0 && args[0].equals("-debug")) {
        Map<Object, Object> properties = new TreeMap<Object, Object>();
        properties.putAll(System.getProperties());
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            System.out.println(" " + entry.getKey() + " = " + entry.getValue());
        }//  w ww  . j a  v  a  2 s .c  o  m
    }

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/context.xml");
    applicationContext.start();

    System.out.println("Enter quit to stop");

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.trim().equalsIgnoreCase("quit")) {
                break;
            }
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        e.printStackTrace(System.err);
    }

    applicationContext.close();
}

From source file:org.fusesource.cloudmix.tests.broker.Main.java

public static void main(String[] args) {
    if (verbose || (args.length > 0 && args[0].equals("-debug"))) {
        Map<Object, Object> properties = new TreeMap<Object, Object>();
        properties.putAll(System.getProperties());
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            System.out.println(" " + entry.getKey() + " = " + entry.getValue());
        }//from  w w  w .  ja v  a2s.  c  om
    }

    ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
            "META-INF/spring/activemq.xml");
    applicationContext.start();

    System.out.println("Enter quit to stop");

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String line = reader.readLine();
            if (line == null || line.trim().equalsIgnoreCase("quit")) {
                break;
            }
        }
    } catch (IOException e) {
        System.err.println("Caught: " + e);
        e.printStackTrace(System.err);
    }

    applicationContext.close();
}

From source file:com.sap.core.odata.fit.mapping.MappingTest.java

public static void main(final String[] args) {
    final TestServer server = new TestServer();
    try {//from  ww w  .  j a v a  2s . c  o m
        server.startServer(MapFactory.class);
        System.out.println("Press any key to exit");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    } catch (final IOException e) {
        e.printStackTrace(System.err);
    } finally {
        server.stopServer();
    }
}

From source file:org.apache.olingo.odata2.fit.mapping.MappingTest.java

public static void main(final String[] args) {
    final TestServer server = new TestServer(ServletType.JAXRS_SERVLET);
    try {/*from   w w w  . j a va 2 s.co m*/
        server.startServer(MapFactory.class);
        System.out.println("Press any key to exit");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    } catch (final IOException e) {
        e.printStackTrace(System.err);
    } finally {
        server.stopServer();
    }
}

From source file:Dcm2Txt.java

public static void main(String[] args) {
    CommandLine cl = parse(args);/*from  w ww.ja v  a2 s.co m*/
    Dcm2Txt dcm2txt = new Dcm2Txt();
    dcm2txt.setWithNames(!cl.hasOption("c"));
    if (cl.hasOption("w"))
        dcm2txt.setMaxWidth(parseInt(cl.getOptionValue("w"), "w", MIN_MAX_WIDTH, MAX_MAX_WIDTH));
    if (cl.hasOption("l"))
        dcm2txt.setMaxValLen(parseInt(cl.getOptionValue("l"), "l", MIN_MAX_VAL_LEN, MAX_MAX_VAL_LEN));
    File ifile = new File((String) cl.getArgList().get(0));
    try {
        dcm2txt.dump(ifile);
    } catch (IOException e) {
        System.err.println("dcm2txt: Failed to dump " + ifile + ": " + e.getMessage());
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:fr.cs.examples.bodies.DEFile.java

/** Program entry point.
 * @param args program arguments (unused here)
 *///from ww  w.  j ava  2s  .  c o  m
public static void main(String[] args) {
    try {
        Autoconfiguration.configureOrekit();
        String inName = null;
        String outName = null;
        List<String> constants = new ArrayList<String>();
        boolean allConstants = false;
        AbsoluteDate start = AbsoluteDate.PAST_INFINITY;
        AbsoluteDate end = AbsoluteDate.FUTURE_INFINITY;
        for (int i = 0; i < args.length; ++i) {
            if ("-in".equals(args[i])) {
                inName = args[++i];
            } else if ("-help".equals(args[i])) {
                displayUsage(System.out);
            } else if ("-constant".equals(args[i])) {
                constants.add(args[++i]);
            } else if ("-all-constants".equals(args[i])) {
                allConstants = true;
            } else if ("-start".equals(args[i])) {
                start = new AbsoluteDate(args[++i], TimeScalesFactory.getUTC());
            } else if ("-end".equals(args[i])) {
                end = new AbsoluteDate(args[++i], TimeScalesFactory.getUTC());
            } else if ("-out".equals(args[i])) {
                outName = args[++i];
            } else {
                System.err.println("unknown command line option \"" + args[i] + "\"");
                displayUsage(System.err);
                System.exit(1);
            }
        }

        if (inName == null) {
            displayUsage(System.err);
            System.exit(1);
        }
        DEFile de = new DEFile(inName, outName);

        de.processHeader();
        System.out.println("header label 1     " + de.label1);
        System.out.println("header label 2     " + de.label2);
        System.out.println("header label 3     " + de.label3);
        System.out.println("header start epoch " + de.headerStartEpoch.toString(de.timeScale) + " ("
                + de.timeScale.getName() + ")");
        System.out.println("header end epoch   " + de.headerFinalEpoch.toString(de.timeScale) + " ("
                + de.timeScale.getName() + ")");

        for (String constant : constants) {
            Double value = de.headerConstants.get(constant);
            System.out.println(constant + "     " + ((value == null) ? "not present" : value));
        }

        if (allConstants) {
            for (Map.Entry<String, Double> entry : de.headerConstants.entrySet()) {
                System.out.println(entry.getKey() + "     " + entry.getValue());
            }
        }

        int processed = de.processData(start, end);
        System.out.println("data records: " + processed);

        if (outName != null) {
            de.write();
            System.out.println(outName + " file created with " + de.selected.size() + " selected data records");
        }

    } catch (IOException ioe) {
        ioe.printStackTrace(System.err);
    } catch (OrekitException oe) {
        oe.printStackTrace(System.err);
    }
}

From source file:glacierpipe.GlacierPipeMain.java

public static void main(String[] args) throws IOException, ParseException {
    CommandLineParser parser = new GnuParser();

    CommandLine cmd = parser.parse(OPTIONS, args);

    if (cmd.hasOption("help")) {
        try (PrintWriter writer = new PrintWriter(System.err)) {
            printHelp(writer);/*  www  .  j  a v a2 s .  c  o m*/
        }

        System.exit(0);
    } else if (cmd.hasOption("upload")) {

        // Turn the CommandLine into Properties
        Properties cliProperties = new Properties();
        for (Iterator<?> i = cmd.iterator(); i.hasNext();) {
            Option o = (Option) i.next();

            String opt = o.getLongOpt();
            opt = opt != null ? opt : o.getOpt();

            String value = o.getValue();
            value = value != null ? value : "";

            cliProperties.setProperty(opt, value);
        }

        // Build up a configuration
        ConfigBuilder configBuilder = new ConfigBuilder();

        // Archive name
        List<?> archiveList = cmd.getArgList();
        if (archiveList.size() > 1) {
            throw new ParseException("Too many arguments");
        } else if (archiveList.isEmpty()) {
            throw new ParseException("No archive name provided");
        }

        configBuilder.setArchive(archiveList.get(0).toString());

        // All other arguments on the command line
        configBuilder.setFromProperties(cliProperties);

        // Load any config from the properties file
        Properties fileProperties = new Properties();
        try (InputStream in = new FileInputStream(configBuilder.propertiesFile)) {
            fileProperties.load(in);
        } catch (IOException e) {
            System.err.printf("Warning: unable to read properties file %s; %s%n", configBuilder.propertiesFile,
                    e);
        }

        configBuilder.setFromProperties(fileProperties);

        // ...
        Config config = new Config(configBuilder);

        IOBuffer buffer = new MemoryIOBuffer(config.partSize);

        AmazonGlacierClient client = new AmazonGlacierClient(
                new BasicAWSCredentials(config.accessKey, config.secretKey));
        client.setEndpoint(config.endpoint);

        // Actual upload
        try (InputStream in = new BufferedInputStream(System.in, 4096);
                PrintWriter writer = new PrintWriter(System.err);
                ObservableProperties configMonitor = config.reloadProperties
                        ? new ObservableProperties(config.propertiesFile)
                        : null;
                ProxyingThrottlingStrategy throttlingStrategy = new ProxyingThrottlingStrategy(config);) {
            TerminalGlacierPipeObserver observer = new TerminalGlacierPipeObserver(writer);

            if (configMonitor != null) {
                configMonitor.registerObserver(throttlingStrategy);
            }

            GlacierPipe pipe = new GlacierPipe(buffer, observer, config.maxRetries, throttlingStrategy);
            pipe.pipe(client, config.vault, config.archive, in);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }

        System.exit(0);
    } else {
        try (PrintWriter writer = new PrintWriter(System.err)) {
            writer.println("No action specified.");
            printHelp(writer);
        }

        System.exit(-1);
    }
}