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:fr.ens.biologie.genomique.eoulsan.actions.UploadS3Action.java

/**
 * Run Eoulsan in hadoop mode./* w ww  .j a  va 2 s.c om*/
 * @param workflowFile workflow file
 * @param designFile design file
 * @param s3Path path of data on S3 file system
 * @param jobDescription job description
 */
private static void run(final File workflowFile, final File designFile, final DataFile s3Path,
        final String jobDescription) {

    checkNotNull(workflowFile, "paramFile is null");
    checkNotNull(designFile, "designFile is null");
    checkNotNull(s3Path, "s3Path is null");

    getLogger().info("Parameter file: " + workflowFile);
    getLogger().info("Design file: " + designFile);

    try {

        // Test if worklflow file exists
        if (!workflowFile.exists()) {
            throw new FileNotFoundException(workflowFile.toString());
        }

        // Test if design file exists
        if (!designFile.exists()) {
            throw new FileNotFoundException(designFile.toString());
        }

        // Create ExecutionArgument object
        final ExecutorArguments arguments = new ExecutorArguments(workflowFile, designFile);
        arguments.setJobDescription(jobDescription);

        // Create the log Files
        Main.getInstance().createLogFiles(arguments.logPath(Globals.LOG_FILENAME),
                arguments.logPath(Globals.OTHER_LOG_FILENAME));

        // Create the executor
        final Executor e = new Executor(arguments);

        // Launch executor
        e.execute(Lists.newArrayList((Module) new LocalUploadModule(s3Path), new TerminalModule()), null);

    } catch (FileNotFoundException e) {
        Common.errorExit(e, "File not found: " + e.getMessage());
    } catch (Throwable e) {
        Common.errorExit(e, "Error while executing " + Globals.APP_NAME_LOWER_CASE + ": " + e.getMessage());
    }

}

From source file:com.github.rnewson.couchdb.lucene.LuceneServlet.java

private Couch getCouch(final HttpServletRequest req) throws IOException {
    final String sectionName = new PathParts(req).getKey();
    final Configuration section = ini.getSection(sectionName);
    if (!section.containsKey("url")) {
        throw new FileNotFoundException(sectionName + " is missing or has no url parameter.");
    }/*w  w  w  . j a va 2  s.c om*/
    return new Couch(client, section.getString("url"));
}

From source file:de.iteratec.iteraplan.businesslogic.reports.staticquery.PropertiesFacade.java

/**
 * Reads the properties list from the resource specified in the
 * field {@link PropertiesFacade#RESOURCE}.
 * // w  ww . j  av  a  2 s.c om
 * @throws FileNotFoundException
 *    If the properties file could not be found
 */
private void init() throws FileNotFoundException {
    BufferedReader br = null;
    InputStreamReader inReader = null;

    final InputStream stream = this.getClass().getResourceAsStream(RESOURCE);
    if (stream == null) {
        throw new FileNotFoundException("Properties file '" + RESOURCE + "' not found in classpath.");
    }

    try {
        inReader = new InputStreamReader(stream);
        br = new BufferedReader(inReader);

        String line = br.readLine();
        while (line != null) {
            if (!(line.length() == 0 || line.charAt(0) == '#')) {
                String[] tokens = line.split("=");
                keys.add(tokens[0]);
                properties.put(tokens[0], tokens[1]);
            }
            line = br.readLine();
        }
    } catch (IOException e) {
        LOGGER.error("Cannot access resource + " + RESOURCE, e);
    } finally {
        IOUtils.closeQuietly(br);
        IOUtils.closeQuietly(inReader);
    }
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.templates.TemplateLocatorServiceImpl.java

/** {@inheritDoc} */
public File getFile(TemplateType type, String templateName) {
    if (StringUtils.isBlank(templateName)) {
        // purge cache, so it can be re-initialized
        clearCache();/*from  w  w w . ja v a  2s  . c om*/
        Exception detailMessage = new FileNotFoundException(
                "The template file " + templateName + " does no longer exist in the filesystem.");
        throw new IteraplanTechnicalException(IteraplanErrorMessages.FILE_NOT_FOUND_EXCEPTION, detailMessage);
    }

    File file = getTemplateFiles(type).get(templateName);
    if ((file != null) && (!file.canRead())) {
        // purge cache, so it can be re-initialized
        clearCache();
        Exception detailMessage = new FileNotFoundException(
                "The template file " + templateName + " does no longer exist in the filesystem.");
        throw new IteraplanTechnicalException(IteraplanErrorMessages.FILE_NOT_FOUND_EXCEPTION, detailMessage);
    }
    return file;
}

From source file:FileUtils.java

private static void removeFile(File file) throws IOException {
    ////from   ww  w .jav  a2s.c o m
    // make sure the file exists, then delete it
    //

    if (!file.exists())
        throw new FileNotFoundException(file.getAbsolutePath());

    if (!file.delete()) {
        Object[] filler = { file.getAbsolutePath() };
        String message = "DeleteFailed";
        throw new IOException(message);
    }
}

From source file:edu.cmu.tetrad.cli.util.Args.java

public static Path getPathFile(String file, boolean requireNotNull) throws FileNotFoundException {
    if (file == null) {
        if (requireNotNull) {
            throw new IllegalArgumentException("File argument is null.");
        } else {/*  www.j  a v  a  2  s .com*/
            return null;
        }
    }

    Path path = Paths.get(file);

    if (Files.exists(path)) {
        if (!Files.isRegularFile(path)) {
            throw new FileNotFoundException(String.format("'%s' is not a file.\n", file));
        }
    } else {
        throw new FileNotFoundException(String.format("File '%s' does not exist.\n", file));
    }

    return path;
}

From source file:com.splunk.shuttl.archiver.model.Bucket.java

private void verifyDirectoryExists(File directory) throws FileNotFoundException, FileNotDirectoryException {
    if (!isUriSet() || isRemote())
        return; // Stop verifying.
    if (!directory.exists())
        throw new FileNotFoundException("Could not find directory: " + directory);
    else if (!directory.isDirectory())
        throw new FileNotDirectoryException("Directory " + directory + " is not a directory");
}

From source file:com.joyent.manta.client.multipart.AbstractMultipartManager.java

@Override
public PART uploadPart(final UPLOAD upload, final int partNumber, final File file) throws IOException {
    validatePartNumber(partNumber);//from ww  w .  ja va2s.co  m
    Validate.notNull(file, "File must not be null");

    if (!file.exists()) {
        String msg = String.format("File doesn't exist: %s", file.getPath());
        throw new FileNotFoundException(msg);
    }

    if (!file.canRead()) {
        String msg = String.format("Can't access file for read: %s", file.getPath());
        throw new IOException(msg);
    }

    HttpEntity entity = new FileEntity(file, ContentType.APPLICATION_OCTET_STREAM);
    return uploadPart(upload, partNumber, entity, null);
}

From source file:com.samsung.sjs.Compiler.java

@SuppressWarnings("static-access")
public static void main(String[] args) throws IOException, SolverException, InterruptedException {
    boolean debug = false;
    boolean use_gc = true;
    CompilerOptions.Platform p = CompilerOptions.Platform.Native;
    CompilerOptions opts = null;/*from   ww  w.  java2s  .  c om*/
    boolean field_opts = false;
    boolean typecheckonly = false;
    boolean showconstraints = false;
    boolean showconstraintsolution = false;
    String[] decls = null;
    String[] links = null;
    String[] objs = null;
    boolean guest = false;
    boolean stop_at_c = false;
    String external_compiler = null;
    boolean encode_vals = false;
    boolean x32 = false;
    boolean validate = true;
    boolean interop = false;
    boolean boot_interop = false;
    boolean oldExpl = false;
    String explanationStrategy = null;
    boolean efl = false;

    Options options = new Options();
    options.addOption("debugcompiler", false, "Enable compiler debug spew");
    //options.addOption("o", true, "Set compiler output file (must be .c)");
    options.addOption(OptionBuilder //.withArgName("o")
            .withLongOpt("output-file").withDescription("Output file (must be .c)").hasArg().withArgName("file")
            .create("o"));
    options.addOption(OptionBuilder.withLongOpt("target")
            .withDescription("Select target platform: 'native' or 'web'").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("gc")
            .withDescription("Disable GC: param is 'on' (default) or 'off'").hasArg().create());

    options.addOption(OptionBuilder
            .withDescription("Enable field access optimizations: param is 'true' (default) or 'false'").hasArg()
            .create("Xfields"));

    options.addOption(OptionBuilder
            .withDescription("Compile for encoded values.  TEMPORARY.  For testing interop codegen").hasArg()
            .create("XEncodedValues"));

    options.addOption(OptionBuilder.withLongOpt("typecheck-only")
            .withDescription("Only typecheck the file, don't compile").create());
    options.addOption(OptionBuilder.withLongOpt("show-constraints")
            .withDescription("Show constraints generated during type inference").create());
    options.addOption(OptionBuilder.withLongOpt("show-constraint-solution")
            .withDescription("Show solution to type inference constraints").create());
    options.addOption(OptionBuilder.withLongOpt("extra-decls")
            .withDescription("Specify extra declaration files, comma-separated").hasArg()
            .withValueSeparator(',').create());
    options.addOption(OptionBuilder.withLongOpt("native-libs")
            .withDescription("Specify extra linkage files, comma-separated").hasArg().withValueSeparator(',')
            .create());
    Option extraobjs = OptionBuilder.withLongOpt("extra-objs")
            .withDescription("Specify extra .c/.cpp files, comma-separated").hasArg().withValueSeparator(',')
            .create();
    extraobjs.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(extraobjs);
    options.addOption(OptionBuilder.withLongOpt("guest-runtime")
            .withDescription(
                    "Emit code to be called by another runtime (i.e., main() is written in another language).")
            .create());
    options.addOption(OptionBuilder.withLongOpt("only-c")
            .withDescription("Generate C code, but do not attempt to compile it").create());
    options.addOption(OptionBuilder.withLongOpt("c-compiler")
            .withDescription("Disable GC: param is 'on' (default) or 'off'").hasArg().create("cc"));
    options.addOption(OptionBuilder.withLongOpt("runtime-src")
            .withDescription("Specify path to runtime system source").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("ext-path")
            .withDescription("Specify path to external dependency dir (GC, etc.)").hasArg().create());
    options.addOption(OptionBuilder.withLongOpt("skip-validation")
            .withDescription("Run the backend without validating the results of type inference").create());

    options.addOption(OptionBuilder.withLongOpt("m32").withDescription("Force 32-bit compilation").create());
    options.addOption(OptionBuilder.withLongOpt("Xbootinterop")
            .withDescription("Programs start with global interop dirty flag set (experimental)").create());
    options.addOption(OptionBuilder.withLongOpt("Xinterop")
            .withDescription("Enable (experimental) interoperability backend").create());

    options.addOption(OptionBuilder.withDescription("C compiler default optimization level").create("O"));
    options.addOption(OptionBuilder.withDescription("C compiler optimization level 0").create("O0"));
    options.addOption(OptionBuilder.withDescription("C compiler optimization level 1").create("O1"));
    options.addOption(OptionBuilder.withDescription("C compiler optimization level 2").create("O2"));
    options.addOption(OptionBuilder.withDescription("C compiler optimization level 3").create("O3"));

    options.addOption(
            OptionBuilder.withLongOpt("oldExpl").withDescription("Use old error explanations").create());

    String explanationStrategyHelp = "default: " + FixingSetFinder.defaultStrategy() + "; other choices: "
            + FixingSetFinder.strategyNames().stream().filter(s -> !s.equals(FixingSetFinder.defaultStrategy()))
                    .collect(Collectors.joining(", "));

    options.addOption(OptionBuilder.withLongOpt("explanation-strategy")
            .withDescription("Error explanation strategy to use (" + explanationStrategyHelp + ')').hasArg()
            .create());

    options.addOption(
            OptionBuilder.withLongOpt("efl").withDescription("Set up efl environment in main()").create());

    try {
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        String[] newargs = cmd.getArgs();
        if (newargs.length != 1) {
            throw new ParseException("Invalid number of arguments");
        }

        String sourcefile = newargs[0];
        if (!sourcefile.endsWith(".js")) {
            throw new ParseException("Invalid file extension on input file: " + sourcefile);
        }

        String gc = cmd.getOptionValue("gc", "on");
        if (gc.equals("on")) {
            use_gc = true;
        } else if (gc.equals("off")) {
            use_gc = false;
        } else {
            throw new ParseException("Invalid GC option: " + gc);
        }
        String fields = cmd.getOptionValue("Xfields", "true");
        if (fields.equals("true")) {
            field_opts = true;
        } else if (fields.equals("false")) {
            field_opts = false;
        } else {
            throw new ParseException("Invalid field optimization option: " + fields);
        }
        String encoding = cmd.getOptionValue("XEncodedValues", "false");
        if (encoding.equals("true")) {
            encode_vals = true;
        } else if (encoding.equals("false")) {
            encode_vals = false;
        } else {
            throw new ParseException("Invalid value encoding option: " + encode_vals);
        }
        String plat = cmd.getOptionValue("target", "native");
        if (plat.equals("native")) {
            p = CompilerOptions.Platform.Native;
        } else if (plat.equals("web")) {
            p = CompilerOptions.Platform.Web;
        } else {
            throw new ParseException("Invalid target platform: " + plat);
        }
        if (cmd.hasOption("cc")) {
            external_compiler = cmd.getOptionValue("cc");
        }
        if (cmd.hasOption("skip-validation")) {
            validate = false;
        }
        if (cmd.hasOption("typecheck-only")) {
            typecheckonly = true;
        }
        if (cmd.hasOption("show-constraints")) {
            showconstraints = true;
        }
        if (cmd.hasOption("show-constraint-solution")) {
            showconstraintsolution = true;
        }
        if (cmd.hasOption("debugcompiler")) {
            debug = true;
        }
        if (cmd.hasOption("m32")) {
            x32 = true;
        }
        if (cmd.hasOption("Xinterop")) {
            interop = true;
        }
        if (cmd.hasOption("Xbootinterop")) {
            boot_interop = true;
            if (!interop) {
                System.err.println("WARNING: --Xbootinterop enabled without --Xinterop (no effect)");
            }
        }
        if (cmd.hasOption("oldExpl")) {
            oldExpl = true;
        }
        if (cmd.hasOption("explanation-strategy")) {
            explanationStrategy = cmd.getOptionValue("explanation-strategy");
        }
        String output = cmd.getOptionValue("o");
        if (output == null) {
            output = sourcefile.replaceFirst(".js$", ".c");
        } else {
            if (!output.endsWith(".c")) {
                throw new ParseException("Invalid file extension on output file: " + output);
            }
        }
        String runtime_src = cmd.getOptionValue("runtime-src");
        String ext_path = cmd.getOptionValue("ext-path");
        if (ext_path == null) {
            ext_path = new File(".").getCanonicalPath() + "/external";
        }

        if (cmd.hasOption("extra-decls")) {
            decls = cmd.getOptionValues("extra-decls");
        }
        if (cmd.hasOption("native-libs")) {
            links = cmd.getOptionValues("native-libs");
        }
        if (cmd.hasOption("extra-objs")) {
            objs = cmd.getOptionValues("extra-objs");
        }
        if (cmd.hasOption("guest-runtime")) {
            guest = true;
        }
        if (cmd.hasOption("only-c")) {
            stop_at_c = true;
        }
        if (cmd.hasOption("efl")) {
            efl = true;
        }

        int coptlevel = -1; // default optimization
        if (cmd.hasOption("O3")) {
            coptlevel = 3;
        } else if (cmd.hasOption("O2")) {
            coptlevel = 2;
        } else if (cmd.hasOption("O1")) {
            coptlevel = 1;
        } else if (cmd.hasOption("O0")) {
            coptlevel = 0;
        } else if (cmd.hasOption("O")) {
            coptlevel = -1;
        } else {
            coptlevel = 3;
        }

        if (!Files.exists(Paths.get(sourcefile))) {
            System.err.println("File " + sourcefile + " was not found.");
            throw new FileNotFoundException(sourcefile);
        }

        String cwd = new java.io.File(".").getCanonicalPath();

        opts = new CompilerOptions(p, sourcefile, debug, output, use_gc,
                external_compiler == null ? "clang" : external_compiler,
                external_compiler == null ? "emcc" : external_compiler, cwd + "/a.out", // emcc automatically adds .js
                new File(".").getCanonicalPath(), true, field_opts, showconstraints, showconstraintsolution,
                runtime_src, encode_vals, x32, oldExpl, explanationStrategy, efl, coptlevel);
        if (guest) {
            opts.setGuestRuntime();
        }
        if (interop) {
            opts.enableInteropMode();
        }
        if (boot_interop) {
            opts.startInInteropMode();
        }
        opts.setExternalDeps(ext_path);
        if (decls != null) {
            for (String s : decls) {
                Path fname = FileSystems.getDefault().getPath(s);
                opts.addDeclarationFile(fname);
            }
        }
        if (links != null) {
            for (String s : links) {
                Path fname = FileSystems.getDefault().getPath(s);
                opts.addLinkageFile(fname);
            }
        }
        if (objs == null) {
            objs = new String[0];
        }

    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("sjsc", options);
    }

    if (opts != null) {
        // This typechecks, and depending on flags, also generates C
        compile(opts, typecheckonly, validate); // don't worry about type validation on command line for now
        if (!typecheckonly && !stop_at_c) {
            int ret = 0;
            // Kept around for debugging 32-bit...
            if (p == CompilerOptions.Platform.Native) {
                if (opts.m32()) {
                    String[] x = new String[2];
                    x[0] = "-m32";
                    x[1] = opts.getExternalDeps() + "/gc/x86/lib/libgc.a";
                    ret = clang_compile(opts, objs, x);
                } else {
                    ret = clang_compile(opts, objs, new String[0]);
                }
            } else {
                ret = emcc_compile(opts, objs, new String[0]);
            }
            // If clang failed, propagate the failure outwards
            if (ret != 0) {
                System.exit(ret);
            }
        }
    }
}

From source file:net.lightbody.bmp.proxy.jetty.html.Include.java

private void includeFile(File file) throws IOException {
    if (!file.exists())
        throw new FileNotFoundException(file.toString());

    if (file.isDirectory()) {
        List list = new List(List.Unordered);
        String[] ls = file.list();
        for (int i = 0; i < ls.length; i++)
            list.add(ls[i]);//  w  w w  .  ja v a 2 s. c  o  m
        StringWriter sw = new StringWriter();
        list.write(sw);
        reader = new StringReader(sw.toString());
    } else {
        reader = new BufferedReader(new FileReader(file));
    }
}