Example usage for java.io FileNotFoundException getMessage

List of usage examples for java.io FileNotFoundException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:airportApp.Query.java

/**
 * This method opens the buffer readers for the three files.
 *//*from  w ww .  j  a v  a  2s.  c o  m*/
private static void readyFiles() {
    try {
        countriesReader = new BufferedReader(new FileReader("resources/countries.csv"));
        airportsReader = new BufferedReader(new FileReader("resources/airports.csv"));
        runwaysReader = new BufferedReader(new FileReader("resources/runways.csv"));
    } catch (FileNotFoundException ex) {
        System.err.println("Error: " + ex.getMessage());
    }
}

From source file:com.phonytive.astive.server.AstiveServer.java

private static ServiceProperties getServiceProperties(String propPath, String serviceName)
        throws SystemException, IOException {
    Properties prop = new Properties();

    try {/*from  ww  w . j a va  2 s.co  m*/
        prop.load(new FileInputStream(propPath));

        return new ServicePropertiesImpl(prop, serviceName);
    } catch (FileNotFoundException ex) {
        throw new SystemException(
                AppLocale.getI18n("unableToReadFile", new Object[] { propPath, ex.getMessage() }));
    }
}

From source file:com.cws.esolutions.security.utils.DAOInitializer.java

/**
 * @param properties - The <code>AuthRepo</code> object containing connection information
 * @param isContainer - A <code>boolean</code> flag indicating if this is in a container
 * @param bean - The {@link com.cws.esolutions.security.SecurityServiceBean} <code>SecurityServiceBean</code> that holds the connection
 *//*from   w w w. ja v  a2s.  co m*/
public synchronized static void closeAuthConnection(final InputStream properties, final boolean isContainer,
        final SecurityServiceBean bean) {
    String methodName = DAOInitializer.CNAME
            + "#closeAuthConnection(final InputStream properties, final boolean isContainer, final SecurityServiceBean bean)";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("InputStream: {}", properties);
        DEBUGGER.debug("isContainer: {}", isContainer);
        DEBUGGER.debug("SecurityServiceBean: {}", bean);
    }

    try {
        Properties connProps = new Properties();
        connProps.load(properties);

        if (DEBUG) {
            DEBUGGER.debug("Properties: {}", connProps);
        }

        AuthRepositoryType repoType = AuthRepositoryType
                .valueOf(connProps.getProperty(DAOInitializer.REPO_TYPE));

        if (DEBUG) {
            DEBUGGER.debug("AuthRepositoryType: {}", repoType);
        }

        switch (repoType) {
        case LDAP:
            LDAPConnectionPool ldapPool = (LDAPConnectionPool) bean.getAuthDataSource();

            if (DEBUG) {
                DEBUGGER.debug("LDAPConnectionPool: {}", ldapPool);
            }

            if ((ldapPool != null) && (!(ldapPool.isClosed()))) {
                ldapPool.close();
            }

            break;
        case SQL:
            // the isContainer only matters here
            if (!(isContainer)) {
                BasicDataSource dataSource = (BasicDataSource) bean.getAuthDataSource();

                if (DEBUG) {
                    DEBUGGER.debug("BasicDataSource: {}", dataSource);
                }

                if ((dataSource != null) && (!(dataSource.isClosed()))) {
                    dataSource.close();
                }
            }

            break;
        case NONE:
            return;
        default:
            return;
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), sqx);
    } catch (FileNotFoundException fnfx) {
        ERROR_RECORDER.error(fnfx.getMessage(), fnfx);
    } catch (IOException iox) {
        ERROR_RECORDER.error(iox.getMessage(), iox);
    }
}

From source file:com.all.client.data.Hashcoder.java

public static String createHashCode(File file) {
    if (file == null) {
        return null;
    }/*from  ww w .j  av  a 2s  .  c  o m*/
    byte[] hashCode = null;
    try {
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fis);

        byte[] buffer = new byte[65536];

        bis.read(buffer);

        bis.close();
        fis.close();

        hashCode = md.digest(buffer);

    } catch (FileNotFoundException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }
    return toHex(hashCode);
}

From source file:com.cablevision.util.sso.UtilSSO.java

/**
 * Creates a PublicKey from the specified public key file and algorithm.
 * Returns null if failure to generate PublicKey.
 * //from ww w. j a  v a  2 s.com
 * @param publicKeyFilepath location of public key file
 * @param algorithm algorithm of specified key file
 * @return PublicKey object representing contents of specified public key
 *         file, null if error in generating key or invalid file specified
 */
public static PublicKey getPublicKey(String publicKeyFilepath, String algorithm) throws SamlException {
    try {
        InputStream pubKey = null;

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        pubKey = cl.getResourceAsStream(publicKeyFilepath);

        byte[] bytes = IOUtils.toByteArray(pubKey);

        pubKey.close();

        System.out.println("Private bytes: " + Arrays.toString(bytes));

        pubKey.close();
        X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(bytes);
        KeyFactory factory = KeyFactory.getInstance(algorithm);
        return factory.generatePublic(pubSpec);
    } catch (FileNotFoundException e) {
        throw new SamlException("ERROR: Public key file not found - " + publicKeyFilepath);
    } catch (IOException e) {
        throw new SamlException("ERROR: Invalid public key file - " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new SamlException("ERROR: Invalid public key algorithm - " + e.getMessage());
    } catch (InvalidKeySpecException e) {
        throw new SamlException("ERROR: Invalid public key spec - " + e.getMessage());
    }
}

From source file:com.cablevision.util.sso.UtilSSO.java

/**
 * Creates a PrivateKey from the specified public key file and algorithm.
 * Returns null if failure to generate PrivateKey.
 * /*from  w w  w.  j  a v a2s.c o  m*/
 * @param PrivateKeyFilepath location of public key file
 * @param algorithm algorithm of specified key file
 * @return PrivateKey object representing contents of specified private key
 *         file, null if error in generating key or invalid file specified
 */
public static PrivateKey getPrivateKey(String privateKeyFilepath, String algorithm) throws SamlException {
    try {
        InputStream privKey = null;

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        privKey = cl.getResourceAsStream(privateKeyFilepath);

        byte[] bytes = IOUtils.toByteArray(privKey);

        privKey.close();

        System.out.println("Private bytes: " + Arrays.toString(bytes));

        PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(bytes);
        KeyFactory factory = KeyFactory.getInstance(algorithm);
        return factory.generatePrivate(privSpec);
    } catch (FileNotFoundException e) {
        throw new SamlException("ERROR: Private key file not found - " + privateKeyFilepath);
    } catch (IOException e) {
        throw new SamlException("ERROR: Invalid private key file - " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new SamlException("ERROR: Invalid private key algorithm - " + e.getMessage());
    } catch (InvalidKeySpecException e) {
        throw new SamlException("ERROR: Invalid private key spec - " + e.getMessage());
    }
}

From source file:cd.education.data.collector.android.utilities.FileUtils.java

private static String actualCopy(File sourceFile, File destFile) {
    FileInputStream fileInputStream = null;
    FileOutputStream fileOutputStream = null;
    FileChannel src = null;/*from  www. ja v a 2s .co m*/
    FileChannel dst = null;
    try {
        fileInputStream = new FileInputStream(sourceFile);
        src = fileInputStream.getChannel();
        fileOutputStream = new FileOutputStream(destFile);
        dst = fileOutputStream.getChannel();
        dst.transferFrom(src, 0, src.size());
        dst.force(true);
        return null;
    } catch (FileNotFoundException e) {
        Log.e(t, "FileNotFoundException while copying file", e);
        return e.getMessage();
    } catch (IOException e) {
        Log.e(t, "IOException while copying file", e);
        return e.getMessage();
    } catch (Exception e) {
        Log.e(t, "Exception while copying file", e);
        return e.getMessage();
    } finally {
        IOUtils.closeQuietly(fileInputStream);
        IOUtils.closeQuietly(fileOutputStream);
        IOUtils.closeQuietly(src);
        IOUtils.closeQuietly(dst);
    }
}

From source file:de.metalcon.musicStorageServer.MusicStorageServerTest.java

@SuppressWarnings("unchecked")
@BeforeClass/*ww  w  .  j a  v  a  2  s.  c  om*/
public static void beforeClass() throws IOException {
    final MSSConfig config = new MSSConfig(CONFIG_PATH);
    TEST_FILE_DIRECTORY = new File(config.getMusicDirectory()).getParentFile();

    VALID_READ_META_DATA_JSON = new JSONObject();
    VALID_READ_META_DATA_JSON.put("title", "My Great Song");
    VALID_READ_META_DATA_JSON.put("album", "Testy Forever");
    VALID_READ_META_DATA_JSON.put("artist", "Testy");

    VALID_READ_META_DATA = VALID_READ_META_DATA_JSON.toJSONString();

    VALID_CREATE_META_DATA_JSON = new JSONObject();
    VALID_CREATE_META_DATA_JSON.putAll(VALID_READ_META_DATA_JSON);
    VALID_CREATE_META_DATA_JSON.put("license", "General Less AllYouCanEat License");
    VALID_CREATE_META_DATA_JSON.put("date", "1991-11-11");

    VALID_CREATE_META_DATA_JSON.put("comment", "All your cookies belong to me!");

    VALID_CREATE_META_DATA = VALID_CREATE_META_DATA_JSON.toJSONString();

    // convert files for reading tests once
    final MusicStorageServer server = new MusicStorageServer(CONFIG_PATH);
    server.clear();

    BACKUP_FILE_ORIGINAL = new File(TEST_FILE_DIRECTORY, "original.mp3");
    BACKUP_FILE_BASIS = new File(TEST_FILE_DIRECTORY, "basis.ogg");
    BACKUP_FILE_STREAMING = new File(TEST_FILE_DIRECTORY, "streaming.ogg");

    final String hash = "108053";
    final Calendar calendar = Calendar.getInstance();
    final String day = FORMATTER.format(calendar.getTime());
    final String year = String.valueOf(calendar.get(Calendar.YEAR));

    DESTINATION_FILE_ORIGINAL = new File(
            config.getMusicDirectory() + "originals/" + year + "/" + day + "/1/10/", hash);
    DESTINATION_FILE_BASIS = new File(config.getMusicDirectory() + "1/10/108/basis/", hash + ".ogg");
    DESTINATION_FILE_STREAMING = new File(config.getMusicDirectory() + "1/10/108/streaming/", hash + ".ogg");

    // convert and copy files if not existing
    if (!(BACKUP_FILE_ORIGINAL.exists() && BACKUP_FILE_BASIS.exists() && BACKUP_FILE_STREAMING.exists())) {
        try {
            assertTrue(server.createMusicItem(VALID_READ_IDENTIFIER,
                    new FileInputStream(new File(TEST_FILE_DIRECTORY, "mp3.mp3")), VALID_READ_META_DATA,
                    new CreateResponse()));

            FileUtils.copyFile(DESTINATION_FILE_ORIGINAL, BACKUP_FILE_ORIGINAL);
            FileUtils.copyFile(DESTINATION_FILE_BASIS, BACKUP_FILE_BASIS);
            FileUtils.copyFile(DESTINATION_FILE_STREAMING, BACKUP_FILE_STREAMING);
        } catch (final FileNotFoundException e) {
            fail("audio file for test is not avialable!\n" + e.getMessage());
        }
    }
}

From source file:be.fedict.trust.service.KeyStoreUtils.java

public static PrivateKeyEntry loadPrivateKeyEntry(KeyStoreType type, String path, String storePassword,
        String entryPassword, String alias) throws KeyStoreLoadException {

    LOG.debug("load keystore");
    InputStream keyStoreStream = null;

    if (type.equals(KeyStoreType.PKCS11)) {
        Security.addProvider(new SunPKCS11(path));
    } else {/* w  w w. j a v a  2  s . c om*/
        try {
            keyStoreStream = new FileInputStream(path);
        } catch (FileNotFoundException e) {
            throw new KeyStoreLoadException("Can't load keystore from config-specified location: " + path, e);
        }
    }

    /* Find the keystore. */
    KeyStore keyStore;
    try {
        keyStore = KeyStore.getInstance(type.name());
    } catch (Exception e) {
        throw new KeyStoreLoadException("keystore instance not available: " + e.getMessage(), e);
    }

    /* Open the keystore and find the key entry. */
    try {
        keyStore.load(keyStoreStream, storePassword.toCharArray());
    } catch (Exception e) {
        throw new KeyStoreLoadException("keystore load error: " + e.getMessage(), e);
    }
    Enumeration<String> aliases;
    try {
        aliases = keyStore.aliases();
    } catch (KeyStoreException e) {
        throw new KeyStoreLoadException("could not get aliases: " + e.getMessage(), e);
    }
    if (!aliases.hasMoreElements()) {
        throw new KeyStoreLoadException("keystore is empty");
    }
    if (null == alias || alias.isEmpty()) {
        alias = aliases.nextElement();
        LOG.debug("alias: " + alias);
    }

    try {
        if (!keyStore.isKeyEntry(alias))
            throw new KeyStoreLoadException("not key entry: " + alias);
    } catch (KeyStoreException e) {
        throw new KeyStoreLoadException("key store error: " + e.getMessage(), e);
    }

    /* Get the private key entry. */
    try {
        PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) keyStore.getEntry(alias,
                new KeyStore.PasswordProtection(entryPassword.toCharArray()));
        return privateKeyEntry;
    } catch (Exception e) {
        throw new KeyStoreLoadException("error retrieving key: " + e.getMessage(), e);
    }
}

From source file:com.fonoster.astive.server.AstiveServer.java

private static ServiceProperties getServiceProperties(String propPath, String serviceName)
        throws SystemException, IOException {
    Properties prop = new Properties();

    try {// w w w.ja v a2 s . com
        prop.load(new FileInputStream(propPath));

        return new ServicePropertiesImpl(prop, serviceName);
    } catch (FileNotFoundException ex) {
        throw new SystemException(
                AppLocale.getI18n("errorUnableToReadFile", new Object[] { propPath, ex.getMessage() }));
    }
}