Example usage for java.io IOException getLocalizedMessage

List of usage examples for java.io IOException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:jgnash.convert.exportantur.csv.CsvExport.java

public static void exportAccount(final Account account, final LocalDate startDate, final LocalDate endDate,
        final File file) {
    Objects.requireNonNull(account);
    Objects.requireNonNull(startDate);
    Objects.requireNonNull(endDate);
    Objects.requireNonNull(file);

    // force a correct file extension
    final String fileName = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".csv";

    final CSVFormat csvFormat = CSVFormat.EXCEL.withQuoteMode(QuoteMode.ALL);

    try (final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
            Files.newOutputStream(Paths.get(fileName)), StandardCharsets.UTF_8);
            final CSVPrinter writer = new CSVPrinter(new BufferedWriter(outputStreamWriter), csvFormat)) {

        outputStreamWriter.write('\ufeff'); // write UTF-8 byte order mark to the file for easier imports

        writer.printRecord("Account", "Number", "Debit", "Credit", "Balance", "Date", "Timestamp", "Memo",
                "Payee", "Reconciled");

        // write the transactions
        final List<Transaction> transactions = account.getTransactions(startDate, endDate);

        final DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().appendValue(YEAR, 4)
                .appendValue(MONTH_OF_YEAR, 2).appendValue(DAY_OF_MONTH, 2).toFormatter();

        final DateTimeFormatter timestampFormatter = new DateTimeFormatterBuilder().appendValue(YEAR, 4)
                .appendLiteral('-').appendValue(MONTH_OF_YEAR, 2).appendLiteral('-')
                .appendValue(DAY_OF_MONTH, 2).appendLiteral(' ').appendValue(HOUR_OF_DAY, 2).appendLiteral(':')
                .appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':').appendValue(SECOND_OF_MINUTE, 2)
                .toFormatter();//from w  w w. java 2  s .  c  om

        for (final Transaction transaction : transactions) {
            final String date = dateTimeFormatter.format(transaction.getLocalDate());

            final String timeStamp = timestampFormatter.format(transaction.getTimestamp());

            final String credit = transaction.getAmount(account).compareTo(BigDecimal.ZERO) < 0 ? ""
                    : transaction.getAmount(account).abs().toPlainString();

            final String debit = transaction.getAmount(account).compareTo(BigDecimal.ZERO) > 0 ? ""
                    : transaction.getAmount(account).abs().toPlainString();

            final String balance = account.getBalanceAt(transaction).toPlainString();

            final String reconciled = transaction.getReconciled(account) == ReconciledState.NOT_RECONCILED
                    ? Boolean.FALSE.toString()
                    : Boolean.TRUE.toString();

            writer.printRecord(account.getName(), transaction.getNumber(), debit, credit, balance, date,
                    timeStamp, transaction.getMemo(), transaction.getPayee(), reconciled);
        }
    } catch (final IOException e) {
        Logger.getLogger(CsvExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}

From source file:com.tckb.geo.stubgen.Generator.java

/**
 * Generates the java stubs for the POJOs used for REST web service
 *//* www  . j  a v  a  2s  .c  o m*/
public static void generateStubs() {
    if (new File(outDir).mkdir()) {
        try {
            getRawJsonFromRemote();
            Logger.getAnonymousLogger().info("Generating stubs...");

            JCodeModel model = new JCodeModel();
            SchemaMapper mapper = new SchemaMapper(new RuleFactory(new DefaultGenerationConfig() {
                @Override
                public SourceType getSourceType() {
                    return SourceType.JSON;
                }

                @Override
                public boolean isUseCommonsLang3() {
                    return false;
                }

                @Override
                public boolean isIncludeHashcodeAndEquals() {
                    return false;
                }

                @Override
                public boolean isIncludeToString() {
                    return false;
                }

                @Override
                public boolean isIncludeJsr303Annotations() {
                    return false;
                }

            }, new NoopAnnotator(), new SchemaStore()), new SchemaGenerator());

            mapper.generate(model, "Device", "com.tckb.geo.stubs", new URL("file://" + deviceJson));
            model.build(new File(outDir));
            mapper.generate(model, "Cluster", "com.tckb.geo.stubs", new URL("file://" + clusterJson));
            model.build(new File(outDir));

        } catch (IOException ex) {

            Logger.getAnonymousLogger().log(Level.SEVERE, "Failed ! {0}", ex.getLocalizedMessage());
        }
        Logger.getAnonymousLogger().info("Finished");

    } else {
        Logger.getAnonymousLogger().severe("Cannot create output directory!");

    }

}

From source file:com.ibm.soatf.tool.FileSystem.java

public static void initializeFileSystemStructure(String path) {
    try {/*  w w w . j ava2  s . co m*/

        // Create root test directory
        forceMkdir(new File(path + ROOT_DIR));
        // Create database test directory
        forceMkdir(new File(path + DATABASE_DIR));
        forceMkdir(new File(path + DATABASE_SCRIPT_DIR));
        // Create jms test directory
        forceMkdir(new File(path + JMS_DIR));
        forceMkdir(new File(path + JMS_SCHEMA_DIR));
        forceMkdir(new File(path + JMS_MESSAGE_DIR));
        // Create report test directory
        forceMkdir(new File(path + REPORT_DIR));
        forceMkdir(new File(path + REPORT_HTML_DIR));
        forceMkdir(new File(path + REPORT_JUNIT_DIR));
        forceMkdir(new File(path + REPORT_PDF_DIR));
        forceMkdir(new File(path + REPORT_XML_DIR));

    } catch (IOException ex) {
        logger.error("Error when trying to initialize file system structure for testing framework: "
                + ex.getLocalizedMessage());
    }
}

From source file:com.splicemachine.derby.impl.sql.actions.index.CsvUtil.java

public static List<String> fileToLines(String filePath, String commentPattern) {
    List<String> lines = new LinkedList<String>();
    BufferedReader in = null;/*from ww  w . j a v  a2 s.  com*/
    try {
        in = new BufferedReader(new FileReader(filePath));

        String line = in.readLine();
        while (line != null) {
            if (commentPattern != null) {
                if (!lineIsComment(line, commentPattern)) {
                    lines.add(line);
                }
            } else {
                lines.add(line);
            }
            line = in.readLine();
        }
    } catch (IOException e) {
        Assert.fail("Unable to read: " + filePath + ": " + e.getLocalizedMessage());
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
    return lines;
}

From source file:com.dastardlylabs.ti.ocrdroid.OcrdroidModule.java

private static void unpackTessData() {

    String assetName = "tess.zip", assetPath, outputDir = getTessDataDirectory().getAbsolutePath();
    File assetTmpFile;/*w  w  w .  j  av a2  s  . c o  m*/

    Log.i(LCAT, "Extracting " + assetName);
    assetTmpFile = storageHelper.copyAssetToTmp(assetName);
    assetPath = assetTmpFile.getAbsolutePath();

    try {
        Log.d(LCAT, "assetFile Path: " + assetPath);
        com.dastardlylabs.android.util.ZipHelper.extract(assetPath, outputDir);
    } catch (IOException e) {
        Log.e(LCAT, "Asset unpacking failed: " + e.getLocalizedMessage());
    } finally {
        if (assetTmpFile != null && assetTmpFile.exists())
            assetTmpFile.delete();
    }

}

From source file:com.aspose.email.examples.outlook.pst.SplitAndMergePSTFile.java

public static void deleteAndRecopySampleFiles(String destFolder, String srcFolder) {

    try {//  w w w  .ja v a  2 s  . com
        deleteAllFilesInDirectory(new File(destFolder));
        File source = new File(srcFolder);
        File dest = new File(destFolder);
        FileUtils.copyDirectory(source, dest);
    } catch (IOException e) {
        System.out.println(e.getLocalizedMessage());
    }
}

From source file:controlador.Red.java

/**
 * Conexion y login mediante FTP al server pasado como parametro con los datos requeridos.
 * @param ip URL del Server./*  w w  w .ja  v  a  2 s.co  m*/
 * @param puerto Puerto por el cual entra la conexion.
 * @param user Usuario que se conecta.
 * @param pwd Password del Usuario a conectar.
 * @return Estado de la operacion.
 */
public static boolean login(String ip, int puerto, String user, String pwd) {
    try {
        conexion = "ftp://" + user + ": @" + ip + ":6598" + "/"; //fixme: los puertos deberian ser dinamicos, no estar hardcodeados. Arreglarlo.
        ftp.connect(ip, puerto);
        return ftp.login(user, pwd);
    } catch (IOException ex) {
        System.out.println("Problema en la conexion o login: " + ex.getLocalizedMessage());
    }

    return false;
}

From source file:de.marius_oe.cfs.cryption.Crypter.java

/**
 * Encrypts the given input stream and stores the encrypted data in the
 * destinationFile.//  ww w  . ja v a  2  s . com
 *
 * @param inStream
 *            plain text stream
 * @param destinationStream
 *            stream for the encrypted data
 * @param compressStream
 *            whether the data should be compressed before encryption
 */
public static void encrypt(InputStream inStream, OutputStream destinationStream, boolean compressStream) {
    logger.debug("encrypting inputstream - compressed: {}", compressStream);

    InputStream tempInputStream;

    if (compressStream) {
        logger.debug("Compress InputStream.");
        tempInputStream = StreamUtils.zipStream(inStream);
    } else {
        tempInputStream = inStream;
    }

    Cipher cipher = getCipher(Cipher.ENCRYPT_MODE, null);

    logger.debug("Encrypt InputStream.");
    tempInputStream = new CipherInputStream(tempInputStream, cipher);

    try {
        // write iv to the beginning of the stream
        destinationStream.write((byte) cipher.getIV().length);
        destinationStream.write(cipher.getIV());

        int bytesCopied = IOUtils.copy(tempInputStream, destinationStream);

        logger.debug("encryption done. copied {} encrypted bytes to the outputstream", bytesCopied);

        tempInputStream.close();
        destinationStream.close();
    } catch (IOException e) {
        logger.error("Encryption failed - Reason: {}", e.getLocalizedMessage());
        throw new RuntimeException(e);
    }
}

From source file:com.innoq.ldap.connector.Utils.java

public static boolean compareFiles(final File file1, final File file2) {
    try {/*from   w w  w .java  2s .  c o  m*/
        return FileUtils.contentEquals(file1, file2);
    } catch (IOException ex) {
        LOG.log(Level.WARNING, ex.getLocalizedMessage(), ex);
        return false;
    }
}

From source file:controlador.Red.java

/**
 * Obtencion de un JTree mapeado pasandole una URL de un server FTP.
 * @param url URL formateada de la siguiente manera: protocolo://user:pwd@ip:puerto".
 * @return JTree formateado para hacer un set directamente.
 *///from  www  .  j  a v a2s. co m
public static JTree setArbolFTP(URL url) {
    try {
        URLConnection conn = url.openConnection();
        InputStream is = conn.getInputStream();

        JTree tree = new Mapeador().mapearServer(is);

        is.close();
        return tree;
    } catch (IOException ex) {
        System.out.println("Problema al hacer set del ArbolFTP: " + ex.getLocalizedMessage());
    }

    return null;
}