Example usage for java.io IOException getMessage

List of usage examples for java.io IOException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.lternet.pasta.common.HTMLUtility.java

public static void main(String[] args) {

    File badIn = new File("/Users/servilla/tmp/bad.txt");
    File goodOut = new File("/Users/servilla/tmp/good.txt");

    String bad = null;//  w  ww  .java  2  s  .  co  m

    try {
        bad = FileUtils.readFileToString(badIn, "UTF-8");
    } catch (IOException e) {
        System.err.println("HTMLUtility: " + e.getMessage());
        e.printStackTrace();
    }

    String good = stripNonValidHTMLCharacters(bad);

    try {
        FileUtils.writeStringToFile(goodOut, good, "UTF-8");
    } catch (IOException e) {
        System.err.println("HTMLUtility: " + e.getMessage());
        e.printStackTrace();
    }

}

From source file:logClient.LogClient.java

public static void main(String[] args) {

    PropertyConfigurator.configure(Constants.LOG4J_PROPERTY_PATH);

    System.setProperty("javax.net.ssl.trustStore", Constants.TRUST_STORE_PATH);
    System.setProperty("javax.net.ssl.trustStorePassword", Constants.TRUST_STORE_PASSWORD);

    LogClient logClient = new LogClient();
    logClient.processConf();/*from  ww w . j  a v  a  2 s.  c o  m*/
    logClient.setupBam();
    logClient.getPathList();

    try {
        FileTracker watchService = new FileTracker(FileTracker.regPaths);
        watchService.processEvents();
    } catch (IOException e) {
        log.fatal("Error initializing file watch client -" + e.getMessage(), e);
        log.fatal("Log client is Exiting..");
        System.exit(-1);
    }
}

From source file:at.tuwien.minimee.emulation.EmulationService.java

/**
 * A small test method/*from   w  w  w .  j a v a2  s  . c  om*/
 * @param args not used
 */
public static void main(String[] args) {
    String url = "http://planets.ruf.uni-freiburg.de/~randy/plato_interface/plato_uploader.php";
    EmulationService emu = new EmulationService();
    File sample = new File("D:/projects/ifs/workspace/plato/data/samples/polarbear1.jpg");

    try {
        byte[] data = getBytesFromFile(sample);

        String sessionid = emu.startSession("polarbear1.jpg", data, url);
        System.out.println(sessionid);
    } catch (IOException e) {
        PlatoLogger.getLogger(EmulationService.class).error(e.getMessage(), e);
    } catch (PlatoServiceException e) {
        PlatoLogger.getLogger(EmulationService.class).error(e.getMessage(), e);
    }

}

From source file:com.cohesionforce.AvroToParquet.java

public static void main(String[] args) {

    String inputFile = null;//from   w w w.ja  v a2 s .c o m
    String outputFile = null;

    HelpFormatter formatter = new HelpFormatter();
    // create Options object
    Options options = new Options();

    // add t option
    options.addOption("i", true, "input avro file");
    options.addOption("o", true, "ouptut Parquet file");
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
        inputFile = cmd.getOptionValue("i");
        if (inputFile == null) {
            formatter.printHelp("AvroToParquet", options);
            return;
        }
        outputFile = cmd.getOptionValue("o");
    } catch (ParseException exc) {
        System.err.println("Problem with command line parameters: " + exc.getMessage());
        return;
    }

    File avroFile = new File(inputFile);

    if (!avroFile.exists()) {
        System.err.println("Could not open file: " + inputFile);
        return;
    }
    try {

        DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>();
        DataFileReader<GenericRecord> dataFileReader;
        dataFileReader = new DataFileReader<GenericRecord>(avroFile, datumReader);
        Schema avroSchema = dataFileReader.getSchema();

        // choose compression scheme
        CompressionCodecName compressionCodecName = CompressionCodecName.SNAPPY;

        // set Parquet file block size and page size values
        int blockSize = 256 * 1024 * 1024;
        int pageSize = 64 * 1024;

        String base = FilenameUtils.removeExtension(avroFile.getAbsolutePath()) + ".parquet";
        if (outputFile != null) {
            File file = new File(outputFile);
            base = file.getAbsolutePath();
        }

        Path outputPath = new Path("file:///" + base);

        // the ParquetWriter object that will consume Avro GenericRecords
        ParquetWriter<GenericRecord> parquetWriter;
        parquetWriter = new AvroParquetWriter<GenericRecord>(outputPath, avroSchema, compressionCodecName,
                blockSize, pageSize);
        for (GenericRecord record : dataFileReader) {
            parquetWriter.write(record);
        }
        dataFileReader.close();
        parquetWriter.close();
    } catch (IOException e) {
        System.err.println("Caught exception: " + e.getMessage());
    }
}

From source file:com.myjeeva.poi.ExcelWorkSheetRowCallbackHandlerTest.java

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

    String SAMPLE_PERSON_DATA_FILE_PATH = "src/test/resources/Sample-Person-Data.xlsx";

    File file = new File(SAMPLE_PERSON_DATA_FILE_PATH);
    InputStream inputStream = new FileInputStream(file);

    // The package open is instantaneous, as it should be.
    OPCPackage pkg = null;//from   www.  j a v a2s  .  co m
    try {
        ExcelWorkSheetRowCallbackHandler sheetRowCallbackHandler = new ExcelWorkSheetRowCallbackHandler(
                new ExcelRowContentCallback() {

                    @Override
                    public void processRow(int rowNum, Map<String, String> map) {

                        // Do any custom row processing here, such as save
                        // to database
                        // Convert map values, as necessary, to dates or
                        // parse as currency, etc
                        System.out.println("rowNum=" + rowNum + ", map=" + map);

                    }

                });

        pkg = OPCPackage.open(inputStream);

        ExcelSheetCallback sheetCallback = new ExcelSheetCallback() {
            private int sheetNumber = 0;

            @Override
            public void startSheet(int sheetNum, String sheetName) {
                this.sheetNumber = sheetNum;
                System.out.println("Started processing sheet number=" + sheetNumber + " and Sheet Name is '"
                        + sheetName + "'");
            }

            @Override
            public void endSheet() {
                System.out.println("Processing completed for sheet number=" + sheetNumber);
            }
        };

        System.out.println("Constructor: pkg, sheetRowCallbackHandler, sheetCallback");
        ExcelReader example1 = new ExcelReader(pkg, sheetRowCallbackHandler, sheetCallback);
        example1.process();

        System.out.println("\nConstructor: filePath, sheetRowCallbackHandler, sheetCallback");
        ExcelReader example2 = new ExcelReader(SAMPLE_PERSON_DATA_FILE_PATH, sheetRowCallbackHandler,
                sheetCallback);
        example2.process();

        System.out.println("\nConstructor: file, sheetRowCallbackHandler, sheetCallback");
        ExcelReader example3 = new ExcelReader(file, sheetRowCallbackHandler, null);
        example3.process();

    } catch (RuntimeException are) {
        LOG.error(are.getMessage(), are.getCause());
    } catch (InvalidFormatException ife) {
        LOG.error(ife.getMessage(), ife.getCause());
    } catch (IOException ioe) {
        LOG.error(ioe.getMessage(), ioe.getCause());
    } finally {
        IOUtils.closeQuietly(inputStream);
        try {
            if (null != pkg) {
                pkg.close();
            }
        } catch (IOException e) {
            // just ignore IO exception
        }
    }
}

From source file:com.sm.store.server.grizzly.GZClusterServer.java

public static void main(String[] args) {
    String[] opts = new String[] { "-host", "-configPath", "-dataPath", "-port", "replicaPort", "-start",
            "-freq" };
    String[] defaults = new String[] { "", "", "", "0", "0", "true", "10" };
    String[] paras = getOpts(args, opts, defaults);

    String configPath = paras[1];
    if (configPath.length() == 0) {
        logger.error("missing config path");
        throw new RuntimeException("missing -configPath");
    }//w w  w .j av a  2 s .  c om
    System.setProperty("configPath", configPath);
    NodeConfig nodeConfig = getNodeConfig(configPath + "/node.properties");
    //int clusterNo = Integer.valueOf( paras[0]);
    String dataPath = paras[2];
    if (dataPath.length() == 0) {
        dataPath = "./data";
    }
    int port = Integer.valueOf(paras[3]);
    int replicaPort = Integer.valueOf(paras[4]);
    //get from command line, if not form nodeConfig
    if (port == 0)
        port = nodeConfig.getPort();
    if (port == 0) {
        throw new RuntimeException("port is 0");
    } else {
        if (replicaPort == 0)
            replicaPort = port + 1;
    }
    boolean start = Boolean.valueOf(paras[5]);
    String host = paras[0];
    //get from command line, if not form nodeConfig or from getHost
    if (host.length() == 0)
        host = nodeConfig.getHost();
    if (host.length() == 0)
        host = getLocalHost();
    int freq = Integer.valueOf(paras[6]);
    logger.info("read clusterNode and storeConfig from " + configPath);
    BuildClusterNodes bcn = new BuildClusterNodes(configPath + "/clusters.xml");
    //BuildStoreConfig bsc = new BuildStoreConfig(configPath+"/stores.xml");
    BuildRemoteConfig brc = new BuildRemoteConfig(configPath + "/stores.xml");
    List<ClusterNodes> clusterNodesList = bcn.build();
    short clusterNo = findClusterNo(host + ":" + port, clusterNodesList);
    logger.info("create cluster server config for cluster " + clusterNo + " host " + host + " port " + port
            + " replica port " + replicaPort);
    ClusterServerConfig serverConfig = new ClusterServerConfig(clusterNodesList, brc.build().getConfigList(),
            clusterNo, dataPath, configPath, port, replicaPort, host);
    serverConfig.setFreq(freq);
    logger.info("create cluster server");
    GZClusterStoreServer cs = new GZClusterStoreServer(serverConfig, new HessianSerializer());
    // start replica server
    cs.startReplicaServer();
    logger.info("hookup jvm shutdown process");
    cs.hookShutdown();
    if (start) {
        logger.info("server is starting " + cs.getServerConfig().toString());
        cs.start();
    } else
        logger.warn("server is staged and wait to be started");

    List list = new ArrayList();
    //add jmx metric
    List<String> stores = cs.getAllStoreNames();
    for (String store : stores) {
        list.add(cs.getStore(store));
    }
    list.add(cs);
    stores.add("ClusterServer");
    JmxService jms = new JmxService(list, stores);

    try {
        logger.info("Read from console and wait ....");
        int c = System.in.read();
    } catch (IOException e) {
        logger.warn("Error reading " + e.getMessage());
    }
    logger.warn("Exiting from System.in.read()");
}

From source file:main.ReportGenerator.java

/**
 * Entry point for the program.//from w  ww  . java 2s. co m
 * Takes the variables as JSON on the standard input.
 * @param args Arguments from the command line.
 */
public static void main(String[] args) {
    CommandLine cmd = createOptions(args);

    GeneratorError result = GeneratorError.NO_ERROR;
    try {
        //Build the output name, by default ./output
        String directory = cmd.getOptionValue("output", "./");
        if (!directory.endsWith(File.separator))
            directory += File.separator;
        String filename = cmd.getOptionValue("name", "output");
        String output = directory + filename;

        //Get the JSON from file if given, or get it from the standard input.
        String jsonText = null;
        if (!cmd.hasOption("input")) {
            // Initializes the input with the standard input
            jsonText = IOUtils.toString(System.in, "UTF-8");
        } else // read the file
        {
            FileInputStream inputStream = new FileInputStream(cmd.getOptionValue("input"));
            try {
                jsonText = IOUtils.toString(inputStream);
            } finally {
                inputStream.close();
            }
        }

        //Build the report object
        Report report = new Report(jsonText, cmd.getOptionValue("template"), output);

        //Generate the document
        if (cmd.hasOption("all")) {
            new AllGenerator(report).generate();
        } else {
            if (cmd.hasOption("html"))
                new HTMLGenerator(report).generate();
            if (cmd.hasOption("pdf"))
                new PDFGenerator(report).generate();
            if (cmd.hasOption("doc"))
                new DocGenerator(report).generate();
        }

    } catch (IOException e) {
        System.err.println("Error: " + e.getMessage());
        System.exit(GeneratorError.IO_ERROR.getCode());
    } catch (GeneratorException e) {
        System.err.println("Error: " + e.getMessage());
        System.exit(e.getError().getCode());
    }
    System.exit(result.getCode());
}

From source file:ColumnIrregular.java

/**
 * Demonstrates the use of ColumnText.//from  w ww.j a  v a 2 s  .com
 * @param args no arguments needed
 */
public static void main(String[] args) {

    System.out.println("Irregular Columns");

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("columnirregular.pdf"));

        // step 3: we open the document
        document.open();

        // step 4:
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        Font font = new Font(bf, 11, Font.NORMAL);

        // we grab the contentbyte and do some stuff with it
        PdfContentByte cb = writer.getDirectContent();

        PdfTemplate t = cb.createTemplate(600, 800);
        Image caesar = Image.getInstance("caesar_coin.jpg");
        cb.addImage(caesar, 100, 0, 0, 100, 260, 595);
        t.setGrayFill(0.75f);
        t.moveTo(310, 112);
        t.lineTo(280, 60);
        t.lineTo(340, 60);
        t.closePath();
        t.moveTo(310, 790);
        t.lineTo(310, 710);
        t.moveTo(310, 580);
        t.lineTo(310, 122);
        t.stroke();
        cb.addTemplate(t, 0, 0);

        ColumnText ct = new ColumnText(cb);
        ct.addText(new Phrase(
                "GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.  Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt.  Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.\n",
                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        ct.addText(new Phrase(
                "[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]\n",
                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        ct.addText(new Phrase(
                "Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix.  Is M. Messala, [et P.] M.  Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent:  perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri.  Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur:  una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit.  His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur.  Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.\n",
                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        ct.addText(new Phrase(
                "His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare.  Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant.  Ad eas res conficiendas Orgetorix deligitur.  Is sibi legationem ad civitates suscipit.  In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat.  Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset:  non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat.  Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.\n",
                FontFactory.getFont(FontFactory.HELVETICA, 12)));
        ct.addText(new Phrase(
                "Ea res est Helvetiis per indicium enuntiata.  Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur.  Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit.  Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.",
                FontFactory.getFont(FontFactory.HELVETICA, 12)));

        float[] left1 = { 70, 790, 70, 60 };
        float[] right1 = { 300, 790, 300, 700, 240, 700, 240, 590, 300, 590, 300, 106, 270, 60 };
        float[] left2 = { 320, 790, 320, 700, 380, 700, 380, 590, 320, 590, 320, 106, 350, 60 };
        float[] right2 = { 550, 790, 550, 60 };

        int status = 0;
        int column = 0;
        while ((status & ColumnText.NO_MORE_TEXT) == 0) {
            if (column == 0) {
                ct.setColumns(left1, right1);
                column = 1;
            } else {
                ct.setColumns(left2, right2);
                column = 0;
            }
            status = ct.go();
            ct.setYLine(790);
            ct.setAlignment(Element.ALIGN_JUSTIFIED);
            status = ct.go();
            if ((column == 0) && ((status & ColumnText.NO_MORE_COLUMN) != 0)) {
                document.newPage();
                cb.addTemplate(t, 0, 0);
                cb.addImage(caesar, 100, 0, 0, 100, 260, 595);
            }
        }
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
}

From source file:TaskQueueSample.java

public static void main(String[] args) {
    if (args.length != 4) {
        System.out.println("Insuficient arguments");
        printUsage();//from w w w  .  j a va2 s.co  m
        System.exit(1);
    } else if (!parseParams(args)) {
        printUsage();
        System.exit(1);
    }
    try {
        run();
        // success!
        return;
    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(1);
}

From source file:com.google.api.services.samples.calendar.cmdline.CalendarSample.java

public static void main(String[] args) {
    try {/*from w  ww  . j a  v  a2  s  .  c o m*/
        // initialize the transport
        httpTransport = GoogleNetHttpTransport.newTrustedTransport();

        // initialize the data store factory
        dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

        // authorization
        Credential credential = authorize();

        // set up global Calendar instance
        client = new Calendar.Builder(httpTransport, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME).build();

        System.out.println(client.getServicePath());
        System.out.println(client.getBaseUrl());
        System.out.println(client.getRootUrl());
        System.out.println(
                client.calendars().get("14tgse4ldpicq5o4pq2metp460@group.calendar.google.com").values());
        System.out.println("Fields:"
                + client.calendars().get("14tgse4ldpicq5o4pq2metp460@group.calendar.google.com").getFields());

        List<CalendarListEntry> object = (List<CalendarListEntry>) client.calendarList().list().execute()
                .get("items");
        for (CalendarListEntry aCalendar : object) {
            System.out.println(aCalendar.getSummary() + "::" + aCalendar.getId() + "::" + aCalendar.getClass()
                    + "::" + aCalendar);
        }
        System.out.println("Items: \t\t" + object);
        for (Object o : client.calendarList().list().execute().keySet()) {
            System.out.println(":::" + o);
            // com.google.api.client.util.Data l;
        }

        for (Object o : client.calendars().get("14tgse4ldpicq5o4pq2metp460@group.calendar.google.com")
                .entrySet()) {
            System.out.println(o);
        }
        System.out.println(client.settings().list().size());
        System.out.println(client.calendarList().list().size());
        // assertEquals(0, client.calendarList().list().size());
        // assertEquals(0, client.events().list().size());

        for (Object o : client.calendarList().list().keySet()) {
            System.out.println(o);
        }

        System.out.println("Success! Now add code here.");

    } catch (IOException e) {
        System.err.println(e.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
    }
    System.exit(1);
}