Example usage for java.io FileNotFoundException FileNotFoundException

List of usage examples for java.io FileNotFoundException FileNotFoundException

Introduction

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

Prototype

public FileNotFoundException(String s) 

Source Link

Document

Constructs a FileNotFoundException with the specified detail message.

Usage

From source file:eu.planets_project.services.utils.cli.CliMigrationPaths.java

/**
 * @param resourceName The XML file containing the path configuration
 * @return The paths defined in the XML file
 * @throws ParserConfigurationException/*from   ww  w  . j ava2 s .  c o m*/
 * @throws IOException
 * @throws SAXException
 * @throws URISyntaxException
 */
// TODO: Clean up this exception-mess. Something like "InitialisationException" or "ConfigurationErrorException" should cover all these exceptions.
public static CliMigrationPaths initialiseFromFile(String resourceName)
        throws ParserConfigurationException, IOException, SAXException, URISyntaxException {

    InputStream instream;

    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL resourceURL = loader.getResource(resourceName);
    if (new File(defaultPath, resourceName).isFile()) {
        instream = new FileInputStream(new File(defaultPath, resourceName));
    } else if (new File(resourceName).isFile()) {
        instream = new FileInputStream(new File(resourceName));
    } else if (resourceURL != null) {
        instream = resourceURL.openStream();
    } else {
        String msg = String.format("Could not locate resource %s", resourceName);
        throw new FileNotFoundException(msg);
    }

    CliMigrationPaths paths = new CliMigrationPaths();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

    DocumentBuilder builder = dbf.newDocumentBuilder();
    Document doc = builder.parse(instream);

    Element fileformats = doc.getDocumentElement();
    if (fileformats != null) {
        NodeList children = fileformats.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                if (child.getNodeName().equals("path")) {
                    CliMigrationPath pathdef = decodePathNode(child);
                    paths.add(pathdef);
                }
            }
        }
    }
    IOUtils.closeQuietly(instream);
    return paths;
}

From source file:com.googlecode.jmxtrans.model.output.kafka.KafkaWriterFactoryTest.java

private InputStream openResource(String resource) throws IOException {
    InputStream inputStream = getClass().getResourceAsStream("/" + resource);
    if (inputStream == null) {
        throw new FileNotFoundException("Resource " + resource + "not found");
    }/*from w  ww  .  j a v  a  2 s  .  c  o  m*/
    return inputStream;
}

From source file:info.novatec.testit.livingdoc.agent.server.AgentConfiguration.java

public static String getKeyStore() throws IOException {
    if (!isSecured()) {
        return null;
    }/*from w  ww . ja  v  a 2  s  . c  o m*/

    if (keyStore == null) {
        throw new IllegalArgumentException("You must specify keystore file location");
    }

    final File keyStoreFile = new File(keyStore);

    if (!keyStoreFile.exists()) {
        throw new FileNotFoundException(
                String.format("KeyStore file '%s' does not exists", keyStoreFile.getAbsolutePath()));
    }

    return keyStore;
}

From source file:com.example.titan.dynamodb.hystrix.issue.TitanConfigurationProvider.java

public GraphDatabaseConfiguration load() throws ConfigurationException, FileNotFoundException {
    final PropertiesConfiguration configuration = new PropertiesConfiguration();

    // load property file if provided
    if (propertyFile != null) {
        final URL resource = getClass().getClassLoader().getResource(propertyFile);

        if (null == resource) {
            LOG.error("File 'titan.properties' cannot be found.");
            throw new FileNotFoundException("File 'titan.properties' cannot be found.");
        }//w ww .  j  a  v a  2  s. c  om

        configuration.load(resource);
    }

    configuration.setProperty(STORAGE_HOSTNAME_KEY, storageHostname);

    if (StringUtils.isEmpty(properties.getProperty("storage.dynamodb.client.credentials.class-name"))) {
        properties.remove("storage.dynamodb.client.credentials.class-name");
        properties.remove("storage.dynamodb.client.credentials.constructor-args");
    }

    if (properties != null) {

        properties.stringPropertyNames().stream()
                .forEach(prop -> configuration.setProperty(prop, properties.getProperty(prop)));
    }

    LOG.info("Titan configuration: \n" + secureToString(configuration));

    // Warning: calling GraphDatabaseConfiguration constructor results in opening connections to backend storage
    return new GraphDatabaseConfiguration(new CommonsConfiguration(configuration));
}

From source file:edu.wright.daselab.linkgen.ConfigurationLoader.java

public final Configuration getConfig(String filePath) throws FileException {
    //at this point, we haven't loaded the path of log4j.properties file, so ignore any logger errors.
    org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
    Configuration config = null;//  w  ww .jav a 2 s .c o  m
    String message = "";
    try {
        File configFile = new File(filePath); // outside the jar file
        if (!configFile.exists()) {
            message = ErrorCodes.Error.CONFIG_FILE_NOT_EXISTS.toString() + "FAILED - " + configFile;
            Monitor.error(message);
            throw new FileNotFoundException(message);
        }
        config = new PropertiesConfiguration(configFile);
        if (config.isEmpty()) {
            message = ErrorCodes.Error.CONFIG_FILE_EMPTY.toString();
            Monitor.error(message);
            throw new FileException(message);
        }
    } catch (Exception e) {
        message = ErrorCodes.Error.CONFIG_FILE_LOAD_ERROR.toString();
        Monitor.error(message);
        throw new FileException(message);
    }
    return (Configuration) config;
}

From source file:com.github.jknack.handlebars.MapTemplateLoader.java

@Override
public TemplateSource sourceAt(final String uri) throws FileNotFoundException {
    notNull(uri, "The uri is required.");
    notEmpty(uri.toString(), "The uri is required.");
    String location = resolve(normalize(uri));
    String text = map.get(location);
    if (text == null) {
        throw new FileNotFoundException(location);
    }/*from   www  . j  ava  2  s .c o  m*/
    return new StringTemplateSource(location, text);
}

From source file:com.excilys.ebi.gatling.jenkins.SimulationReport.java

private File locateStatsFile() throws IOException, InterruptedException {
    FilePath[] files = reportDirectory.list(STATS_FILE_PATTERN);

    if (files.length == 0)
        throw new FileNotFoundException("Unable to locate the simulation results for " + simulation.getName());

    return new File(files[0].getRemote());
}

From source file:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.AnsibleVault.java

private static void handleFile(File file, Function<byte[], byte[]> vaultHandler) throws IOException {
    if (!file.exists()) {
        throw new FileNotFoundException(file.getPath());
    }//w  w  w.  j a v  a 2  s  .com
    byte[] input = FileUtils.readFileToByteArray(file);
    byte[] output = vaultHandler.apply(input);
    file.delete();
    FileUtils.writeByteArrayToFile(file, output);
}

From source file:Main.java

/**
 * Method read./*  ww w  .ja  v a2  s. c  om*/
 * 
 * @param filepath
 *            String
 * @return Properties
 * @throws FileNotFoundException
 */
public static Properties read(String filepath) throws FileNotFoundException {
    Properties rval;
    BufferedInputStream bis = null;

    try {
        File file = new File(filepath);

        bis = new BufferedInputStream(new FileInputStream(file));
        rval = new Properties();

        rval.load(bis);

        return rval;
    } catch (IOException e) {
    } finally {
        if (bis != null) {
            try {
                bis.close();
            } catch (IOException e) {
            }

            bis = null;
        }
    }

    // try relative to java.home
    try {
        File file = new File(System.getProperty("java.home") + File.separator + filepath);

        bis = new BufferedInputStream(new FileInputStream(file));
        rval = new Properties();

        rval.load(bis);

        return rval;
    } catch (IOException e) {
    } finally {
        if (bis != null) {
            try {
                bis.close();
            } catch (IOException e) {
            }

            bis = null;
        }
    }

    throw new FileNotFoundException("Property file " + filepath + " not found");
}

From source file:org.apache.james.container.spring.filesystem.ResourceLoaderFileSystem.java

@Override
public File getFile(String fileURL) throws FileNotFoundException {
    try {/* www. j av  a 2  s.  com*/
        return loader.getResource(fileURL).getFile();
    } catch (IOException e) {
        throw new FileNotFoundException("Could not load file " + fileURL);
    }
}