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:com.mondora.chargify.ChargifyFactory.java

BeanFactory readFromSenseDirConf() throws FileNotFoundException {
    String fPath = System.getProperty("sense.dir.conf") + "/charge-context.xml";
    if (logger.isTraceEnabled())
        logger.trace("Try loading charge-context.xml from " + fPath);

    File chargeContext = new File(fPath);
    if (chargeContext.exists()) {
        return new XmlBeanFactory(new FileSystemResource(chargeContext));
    }/*from  w ww  .  j av a  2  s. co  m*/
    throw new FileNotFoundException("file " + fPath + " don't exists");
}

From source file:com.amazonaws.services.simpleworkflow.flow.examples.common.ConfigHelper.java

public static ConfigHelper createConfig() throws IOException, IllegalArgumentException {

    BasicConfigurator.configure();/*from  w w  w .  j a  va2  s  .c o  m*/
    Logger.getRootLogger().setLevel(Level.INFO);

    //        Logger.getLogger("org.apache.http").setLevel(Level.INFO);

    ConfigHelper configHelper = null;

    boolean envVariableExists = false;
    //first check the existence of environment variable
    String sampleConfigPath = System.getenv(SampleConstants.ACCESS_PROPERTIES_ENVIRONMENT_VARIABLE);
    if (sampleConfigPath != null && sampleConfigPath.length() > 0) {
        envVariableExists = true;
    }
    File accessProperties = new File(System.getProperty(SampleConstants.HOME_DIRECTORY_PROPERTY),
            SampleConstants.HOME_DIRECTORY_FILENAME);

    if (accessProperties.exists()) {
        configHelper = new ConfigHelper(accessProperties);
    } else if (envVariableExists) {
        accessProperties = new File(sampleConfigPath, SampleConstants.ACCESS_PROPERTIES_FILENAME);
        configHelper = new ConfigHelper(accessProperties);
    } else {
        //try checking the existence of file on relative path.
        try {
            accessProperties = new File(SampleConstants.ACCESS_PROPERTIES_RELATIVE_PATH,
                    SampleConstants.ACCESS_PROPERTIES_FILENAME);
            configHelper = new ConfigHelper(accessProperties);
        } catch (Exception e) {
            throw new FileNotFoundException(
                    "Cannot find AWS_SWF_SAMPLES_CONFIG environment variable, Exiting!!!");
        }
    }

    return configHelper;
}

From source file:com.chingo247.structureapi.plan.StructurePlan.java

public void load(AbstractDocument document) throws StructureDataException, IOException {
    xmlFile = document.getDocumentFile();
    pluginElement = document.getPluginElement(Bukkit.getPluginManager().getPlugin("SettlerCraft"));

    Element scElement = pluginElement.getAsElement();

    Node schematicNode = scElement.selectSingleNode(Nodes.SCHEMATIC_NODE);
    if (schematicNode == null) {
        throw new StructureDataException(
                "Missing  Structure Schematic in " + document.getDocumentFile().getAbsolutePath());
    }//from  w  w  w.java  2s .  co  m

    File s = new File(document.getDocumentFile().getParent(), schematicNode.getText());
    if (s.exists()) {
        schematic = s;
    } else {
        throw new FileNotFoundException("Couldn't resolve path for " + s.getAbsolutePath() + " for config:  "
                + document.getDocumentFile().getAbsolutePath());
    }

    checksum = FileUtils.checksumCRC32(s);

    name = pluginElement.getStringValue(Nodes.NAME_NODE);
    if (name == null) {
        name = FilenameUtils.getBaseName(schematic.getName());
    }
    category = pluginElement.getStringValue(Nodes.CATEGORY_NODE);
    if (category == null) {
        category = "Default";
    }

    description = pluginElement.getStringValue(Nodes.DESCRIPTION_NODE);
    if (description == null) {
        description = "-";
    }

    try {
        price = pluginElement.getDoubleValue(Nodes.PRICE_NODE);
    } catch (NumberFormatException nfe) {
        throw new StructureDataException("Value of 'Price' must be a number, error generated in "
                + document.getDocumentFile().getAbsolutePath());
    }
    if (price == null) {
        price = 0.0;
    }

    Node worldGuardFlagsNode = scElement.selectSingleNode(Nodes.WORLDGUARD_FLAGS_NODE);
    if (worldGuardFlagsNode != null) {
        regionFlags = new StructureRegionFlagLoader().load((Element) worldGuardFlagsNode);
    } else {
        regionFlags = new LinkedList<>();
    }

    Node structureOverviewsNode = scElement.selectSingleNode(Nodes.STRUCTURE_OVERVIEWS_NODE);
    if (structureOverviewsNode != null) {
        overviews = new StructureOverviewLoader().load((Element) structureOverviewsNode);
    } else {
        overviews = new LinkedList<>();
    }

    Node structureHologramsNode = scElement.selectSingleNode(Nodes.HOLOGRAMS_NODE);
    if (structureOverviewsNode != null) {
        holograms = new StructureHologramLoader().load((Element) structureHologramsNode);
    } else {
        holograms = new LinkedList<>();
    }
}

From source file:FileLocator.java

/**
 * Locate the specific file.//from   w w w.  ja  v  a2 s . com
 * Return the file name in URL form or null.
 */
public static URL locateURL(String findFile) throws FileNotFoundException {
    URL url;
    String fullPathName;

    if (findFile == null)
        throw new FileNotFoundException("locateURL: null file name");

    try {
        if (findFile.startsWith(absolutePath)) {
            return (new URL("file:/" + findFile.substring(absolutePath.length())));
        }

        if ((fullPathName = locateByProperty(findFile)) != null) {
            if (platformIsWindows())
                url = new URL("file:/" + fullPathName);
            else
                url = new URL("file:" + fullPathName);
            return url;
        }
        //TODO: TR: used for testing:  return new URL(findFile);
    } catch (MalformedURLException e) {
        System.err.println("locateURL: URL creation problem");
        throw new FileNotFoundException("locateURL: URL creation problem");
    }
    if ((url = locateByResource(findFile)) != null)
        return url;

    throw new FileNotFoundException("locateURL: file not found: " + findFile);
}

From source file:edu.abreksa.BeanTest.components.Test.java

public static Test testLoader(String filepath) throws IOException {
    Log.debug("Loading test \"" + filepath + "\"");
    File testFile = new File(filepath);
    if (!testFile.exists()) {
        throw new FileNotFoundException("The test definition file \"" + filepath + "\" does not exist.");
    }//from w w  w . j a  v  a 2  s  . com
    Test test = Main.gson.fromJson(Main.Utils.readFile(testFile.getAbsolutePath()), Test.class);
    StringBuilder stringBuilder = new StringBuilder();
    Queue<Object> queue = new LinkedList<Object>();
    if (!Main.config.disableHelperMethods) {
        queue.add("imports(){import *;}\r\nimports();\r\n");
        //Add log methods
        queue.add("debug(string){com.esotericsoftware.minlog.Log.debug(testHandle.getName(), string);}");
        queue.add("error(string){com.esotericsoftware.minlog.Log.error(testHandle.getName(), string);}");
        queue.add("warn(string){com.esotericsoftware.minlog.Log.warn(testHandle.getName(), string);}");
        queue.add("info(string){com.esotericsoftware.minlog.Log.info(testHandle.getName(), string);}");
        queue.add("trace(string){com.esotericsoftware.minlog.Log.trace(testHandle.getName(), string);}");
        //Add (webDriver/selenium)/webClient variables
        queue.add(
                "if(testHandle.getDriver().equals(\"WebDriver\")){webDriver = testHandle.getWebDriver();} else if(testHandle.getDriver().equals(\"HTMLUnit\")){webClient = testHandle.getWebClient();}");
    }
    //The before scripts
    for (String string : Main.config.before) {
        queue.add(new File(string));
    }
    //The test before
    for (String string : test.before) {
        queue.add(new File(string));
    }
    if (test.scriptCode != null) {
        queue.add(test.scriptCode);
    }
    //The test
    File scriptFile = new File(test.script);
    if (!scriptFile.exists()) {
        throw new FileNotFoundException("The script file \"" + test.script + "\" does not exist.");
    } else {
        queue.add(new File(scriptFile.getAbsolutePath()));
    }
    //The test after
    for (String string : test.after) {
        queue.add(new File(string));
    }
    //The after
    for (String string : Main.config.after) {
        queue.add(new File(string));
    }
    Log.debug("Queued " + Main.gson.toJson(queue));
    Log.debug("Loading " + queue.size() + " external scripts");
    for (Object object : queue) {
        if (object instanceof File) {
            if (((File) object).exists()) {
                Log.debug("Loading external script file \"" + object + "\"");
                stringBuilder.append("\r\n" + Main.Utils.readFile(((File) object).getAbsolutePath()));
            } else {
                Log.warn("External script file \"" + object + "\" does not exist.");
            }
        } else if (object instanceof String) {
            stringBuilder.append("\r\n" + object);
        }
    }
    test.scriptCode = stringBuilder.toString().replace("\r\n\r\n", "\r\n");
    Log.debug("Final script \"" + test.scriptCode + "\"");
    return test;
}

From source file:com.thoughtworks.go.util.HttpService.java

public int upload(String url, long size, File artifactFile, Properties artifactChecksums) throws IOException {
    String absolutePath = artifactFile.getAbsolutePath();
    if (!artifactFile.exists()) {
        String message = "Failed to find file [" + absolutePath + "]";
        LOGGER.error(message);//w  w  w .  j ava 2s.  co m
        throw new FileNotFoundException(message);
    }
    LOGGER.info("Uploading file [{}] to url [{}]", absolutePath, url);

    HttpPost filePost = createHttpPostForUpload(url, size, artifactFile, artifactChecksums);
    try (CloseableHttpResponse response = execute(filePost)) {
        return response.getStatusLine().getStatusCode();
    } catch (IOException e) {
        LOGGER.error("Error while uploading file [{}]", artifactFile.getAbsolutePath(), e);
        throw e;
    } finally {
        filePost.releaseConnection();
    }
}

From source file:de.iai.ilcd.xml.read.DataSetReader.java

public DataSet readDataSetFromFile(File file, PrintWriter out)
        throws FileNotFoundException, IOException, UnsupportedEncodingException {

    dataSetFileName = file.getAbsolutePath();
    this.out = out;

    DataSet dataSet = null;/*ww  w  .  j a  va2  s.  co  m*/

    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
    } catch (Exception e) {
        out.println("Warning: Cannot find file " + file.getName());
        throw new FileNotFoundException("File " + file.getName() + " cannot be found");
    }
    dataSet = readDataSetFromStream(inputStream, out);
    inputStream.close();

    return dataSet;
}

From source file:fr.adfab.magebeans.processes.CreateModuleProcess.java

public void setProjectDir(String projectDir) throws FileNotFoundException {
    File tmp = new File(projectDir);
    if (!tmp.exists()) {
        throw new FileNotFoundException("Project directory not found");
    }//from   ww  w  . jav  a2 s . c  om
    this.projectDir = projectDir;
}

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

/**
 * Load the template from a template repository.
 *
 * @param uri The resource's uri. Required.
 * @return The requested resource.//  w  w  w .  j ava2 s.co  m
 * @throws IOException If the resource cannot be loaded.
 */
public Reader load(final URI uri) throws IOException {
    notNull(uri, "The uri is required.");
    notEmpty(uri.toString(), "The uri is required.");
    String location = resolve(normalize(uri.toString()));
    Handlebars.debug("Loading resource: %s", location);
    Reader reader = read(location);
    if (reader == null) {
        throw new FileNotFoundException(location.toString());
    }
    Handlebars.debug("Resource found: %s", location);
    return reader;
}

From source file:com.relicum.ipsum.io.PropertyIO.java

/**
 * Return a {@link java.util.Properties} read from the specified string file path.
 *
 * @param file the {@link java.nio.file.Path } name of the file to read the properties from.
 * @return the {@link java.util.Properties} instance.
 * @throws IOException the {@link java.io.IOException} if the file was not found or there were problems reading from it.
 *///from w w w.j a  v  a 2s . co m
default Properties readFromFile(File file) throws IOException {

    Validate.notNull(file);

    if (Files.exists(file.toPath()))
        throw new FileNotFoundException("File at " + file.getPath() + " was not found");

    Properties properties = new Properties();
    try {

        properties.load(Files.newBufferedReader(file.toPath(), Charset.defaultCharset()));
    } catch (IOException e) {
        Logger.getGlobal().log(Level.SEVERE, e.getMessage(), e.getCause());
        throw e;
    }

    return properties;
}