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.qubell.jenkinsci.plugins.qubell.builders.StartInstanceBuilder.java

/**
 * Copies manifest from build workflow (either on master or slave), into temporary folder on master
 *
 * @param build    current build/*from w  w w  .j ava 2 s .c om*/
 * @param buildLog current build log
 * @return {@link FilePath} object for new temporary maifest file
 * @throws IOException          when file could not be copied/accessed
 * @throws InterruptedException when operation is interrupted
 */
protected FilePath copyManifest(AbstractBuild build, PrintStream buildLog)
        throws IOException, InterruptedException {
    logMessage(buildLog, "copying manifest from current build workspace. Relative path is %s",
            manifestRelativePathResolved);

    FilePath destinationManifest = getTemporaryManifestPath(build, buildLog);
    FilePath sourceManifest = build.getWorkspace().child(manifestRelativePathResolved);

    if (!sourceManifest.exists()) {
        logMessage(buildLog,
                "Unable to find manifest file with relative path %s, target file %s does not exist\n",
                manifestRelativePathResolved, sourceManifest.toURI());
        throw new FileNotFoundException("Manifest not found");
    }

    //logMessage(buildLog,  "Copying manifest running on  %s at %s to %s", currentMachine, sourceManifest.toURI(), destinationManifest.toURI());

    sourceManifest.copyTo(destinationManifest);
    return destinationManifest;
}

From source file:ffx.potential.utils.PotentialsDataConverter.java

/**
 * Attempt to get the file the Structure was loaded from. Assumes .pdb
 * format, mostly because Biojava can only load from PDB.
 *
 * @param structure A Biojava structure/*from ww  w  . j  a  v a  2s  .  c o  m*/
 * @return pdbcode.pdb, name.pdb, or a default file
 * @throws java.io.FileNotFoundException If no file could be found.
 */
public static File getBiojavaFile(Structure structure) throws FileNotFoundException {
    String filename = structure.getPDBCode();
    if (filename == null || filename.trim().equals("")) {
        filename = structure.getName();
        if (filename == null || filename.trim().equals("")) {
            filename = BIOJAVA_DEFAULT_FILENAME;
        }
    }
    filename += ".pdb";
    File retFile = new File(filename);
    int counter = 1;
    while (retFile.isDirectory() && counter < 1000) {
        retFile = new File(String.format("%s_%d", filename, counter++));
    }
    if (retFile.isDirectory()) {
        throw new FileNotFoundException(
                String.format(" Could not find a file " + "for structure %s", structure.toString()));
    }
    return retFile;
}

From source file:com.bstek.dorado.idesupport.RuleTemplateBuilder.java

private Resource getResource(String file) throws FileNotFoundException {
    Resource resource = Context.getCurrent().getResource(file);
    if (!resource.exists()) {
        throw new FileNotFoundException("File not exists - [" + resource + "]");
    }//from  www.j a  va  2s  .  c o  m
    return resource;
}

From source file:geva.Operator.Operations.StatisticsCollectionOperation.java

/**
 * Set properties/*from   w w w .  j  a va2 s  .co m*/
 *
 * @param p object containing properties
 */
public void setProperties(Properties p) {
    String value = System.getProperty("user.dir");
    File f;
    String key;
    try {
        key = Constants.OUTPUT;
        String tmp = p.getProperty(key);
        if (tmp != null) {
            if (tmp.equals(Constants.FALSE)) {
                value = "";
            } else {
                if (!tmp.startsWith(System.getProperty("file.separator"))) {
                    value += System.getProperty("file.separator");
                }
                value += tmp;
                f = new File(value);
                if (value.endsWith(System.getProperty("file.separator")) && !f.isDirectory()) {
                    throw new FileNotFoundException(value);
                }
                logger.info("Output directory is " + value);
            }
        } else {
            value = "";
        }
    } catch (Exception e) {
        value = System.getProperty("user.dir") + System.getProperty("file.separator");
        logger.warn("Using default output directory: " + value);
    }
    this.fileName = value;
    //HACK FIXME??!!
    this.cntIntervall = Integer.parseInt(p.getProperty("intervall_cnt", "10000000"));

}

From source file:it.greenvulcano.configuration.BaseConfigurationManager.java

@Override
public void delete(String name) throws IOException, FileNotFoundException {
    Path configurationPath = getConfigurationPath(name);
    if (!Files.deleteIfExists(configurationPath)) {
        throw new FileNotFoundException(configurationPath.toString());
    }//from   w w w. j  a  va  2  s .c  om
}

From source file:com.c4om.xsdfriendlyvalidator.XSDFriendlyValidatorLauncher.java

/**
 * This method parses an array of "schemas" command line option values to get a {@link Map} between namespace URIs and the XSDs that describe them. 
 * Such a {@link Map} is suitable as input parameter for {@link XSDFriendlyValidator#validate(Document, Map)} and {@link XSDFriendlyValidator#validate(List, Map)}. 
 * Null, empty and whitespace values are ignored.
 * @param commandLineOptionValues the array of command line option values
 * @return A {@link Map} between URIs and XSD documents, suitable to be used as input in a {@link XSDFriendlyValidator}
 * @throws IOException If there are problems related to I/O
 * @throws SAXException If there are problems at XML parsing
 * @throws ParserConfigurationException If there are problems at XML parsing 
 * @throws IllegalArgumentException if the array is empty or only contains null, empty or whitespace values.
 * // w w  w .j a  v a2s  .c o  m
 */
private static Map<String, Document> getSchemaFilesFromCommandLine(String[] commandLineOptionValues)
        throws IOException, ParserConfigurationException, SAXException {
    Map<String, Document> result = new HashMap<>();
    if (commandLineOptionValues.length == 0) {
        throw new IllegalArgumentException("Empty array");
    }
    for (int i = 0; i < commandLineOptionValues.length; i++) {
        while (commandLineOptionValues[i] == null || commandLineOptionValues[i].trim().equals("")) {
            i++;
        }
        if (i >= commandLineOptionValues.length) {
            throw new IllegalArgumentException("Array only with empty or null values");
        }
        if (!(i == (commandLineOptionValues.length - 1))) {
            String uri = commandLineOptionValues[i];
            i++;
            String filePath = commandLineOptionValues[i];
            File file = new File(filePath);
            if (!file.exists()) {
                throw new FileNotFoundException("File '" + filePath + "' does not exist.");
            } else if (!file.isFile()) {
                throw new IOException("'" + filePath + "' is not a file.");
            }
            Document schemaDocument = loadW3CDocumentFromInputFile(file);
            result.put(uri, schemaDocument);
        } else {
            String filePath = commandLineOptionValues[i];
            File file = new File(filePath);
            if (!file.exists()) {
                throw new FileNotFoundException("File '" + filePath + "' does not exist.");
            } else if (!file.isFile()) {
                throw new IOException("'" + filePath + "' is not a file.");
            }
            Document schemaDocument = loadW3CDocumentFromInputFile(file);
            result.put("", schemaDocument);
        }

    }
    return result;
}

From source file:org.wikipedia.vlsergey.secretary.jwpf.HttpBot.java

protected void get(final HttpGet getMethod, final ContentProcessable action)
        throws IOException, CookieException, ProcessException {
    getMethod.getParams().setParameter("http.protocol.content-charset", MediaWikiBot.ENCODING);

    getMethod.setHeader("Accept-Encoding", GZIP_CONTENT_ENCODING);

    httpClient.execute(getMethod, new ResponseHandler<Object>() {
        @Override/* w ww.j a v a  2  s.co  m*/
        public Object handleResponse(HttpResponse httpResponse) throws ClientProtocolException, IOException {

            try {
                action.validateReturningCookies(httpClient.getCookieStore().getCookies(), getMethod);

                InputStream inputStream = httpResponse.getEntity().getContent();
                String contentEncoding = httpResponse.getEntity().getContentEncoding() != null
                        ? httpResponse.getEntity().getContentEncoding().getValue()
                        : "";
                if ("gzip".equalsIgnoreCase(contentEncoding))
                    inputStream = new GZIPInputStream(inputStream);

                int statuscode = httpResponse.getStatusLine().getStatusCode();

                if (statuscode == HttpStatus.SC_NOT_FOUND) {
                    log.warn("Not Found: " + getMethod.getRequestLine().getUri());
                    throw new FileNotFoundException(getMethod.getRequestLine().getUri());
                }
                if (statuscode == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
                    throw new ServerErrorException(httpResponse.getStatusLine());
                }
                if (statuscode != HttpStatus.SC_OK) {
                    throw new ClientProtocolException(httpResponse.getStatusLine().toString());
                }

                String encoding = StringUtils
                        .substringAfter(httpResponse.getEntity().getContentType().getValue(), "charset=");
                String out = IoUtils.readToString(inputStream, encoding);
                action.processReturningText(getMethod, out);
            } catch (CookieException exc) {
                throw new ClientProtocolException(exc);
            } catch (ProcessException exc) {
                throw new ClientProtocolException(exc);
            }
            return null;
        }
    });

}

From source file:com.sugarcrm.candybean.configuration.Configuration.java

public void load(File file) throws IOException {
    try {//from   ww  w  .ja  v  a2  s  . c  om
        if (file == null) {
            throw new FileNotFoundException("Given file is null.");
        } else {
            this.load(new FileInputStream(file));
        }
    } catch (FileNotFoundException e) {
        // get file name using substring of adjustedPath that starts after the last /
        logger.severe(e.getMessage());
    } catch (IOException e) {
        logger.warning("Unable to load " + file.getCanonicalPath() + ".\n");
        logger.severe(e.getMessage());
    } catch (NullPointerException e) {
        logger.warning("File path is null.\n");
        logger.severe(e.getMessage());
    }

}

From source file:com.cedarsoft.io.LinkUtils.java

/**
 * Deletes the symbolic link//w  ww  . jav  a2s .c  om
 *
 * @param linkFile the link file
 * @throws IOException if any.
 */
public static void deleteSymbolicLink(@Nonnull File linkFile) throws IOException {
    if (!linkFile.exists()) {
        throw new FileNotFoundException("No such symlink: " + linkFile);
    }
    // find the resource of the existing link:
    File canonicalFile = linkFile.getCanonicalFile();

    // rename the resource, thus breaking the link:
    File temp = createTempFile("symlink", ".tmp", canonicalFile.getParentFile());
    try {
        try {
            FileUtils.moveFile(canonicalFile, temp);
        } catch (IOException e) {
            throw new IOException("Couldn't rename resource when attempting to delete " + linkFile);
        }
        // delete the (now) broken link:
        if (!linkFile.delete()) {
            throw new IOException("Couldn't delete symlink: " + linkFile
                    + " (was it a real file? is this not a UNIX system?)");
        }
    } finally {
        // return the resource to its original name:
        try {
            FileUtils.moveFile(temp, canonicalFile);
        } catch (IOException e) {
            throw new IOException("Couldn't return resource " + temp + " to its original name: "
                    + canonicalFile.getAbsolutePath() + "\n THE RESOURCE'S NAME ON DISK HAS "
                    + "BEEN CHANGED BY THIS ERROR!\n");
        }
    }
}

From source file:com.hygenics.parser.ExistanceChecker.java

public void run() {

    if (globsExists != null && globsExists.size() > 0) {
        ArrayList<Boolean> matches = checkFilesExist(globsExists, directories, true);
        if (matches.contains(false)) {
            try {
                throw new FileNotFoundException("A Required File was Not Found");
            } catch (FileNotFoundException e) {
                e.printStackTrace();/*from  w w w. j  a va2s.co  m*/
                System.exit(-1);
            }
        }
    }

    if (globsNotExists != null && globsNotExists.size() > 0) {
        ArrayList<Boolean> matches = checkFilesExist(globsNotExists, directories, false);

        if (matches.contains(false)) {
            try {
                throw new Exception("A File That Cannot Be Present Was Found");
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(-1);
            }
        }
    }

    if (schemaExists != null && schemaExists.size() > 0) {
        ArrayList<Boolean> matches = checkSchemasExist(schemaExists, true);
        if (matches.contains(false)) {
            try {
                throw new SchemaMissingException("A Required Schema was Not Found.");
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(-1);
            }
        }
    }

    if (schemaNotExists != null && schemaNotExists.size() > 0) {
        ArrayList<Boolean> matches = checkSchemasExist(schemaNotExists, false);
        if (matches.contains(false)) {
            try {
                throw new Exception("A Schema was Found that Cannot Be Present");
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(-1);
            }
        }
    }

    if (tableExists != null && tableExists.size() > 0) {
        ArrayList<Boolean> matches = checkTablesExist(tableExists, true);
        if (matches.contains(false)) {
            try {
                throw new TableMissingException("A Required Table Was Missing");
            } catch (TableMissingException e) {
                e.printStackTrace();
                System.exit(-1);
            }
        }
    }

    if (tableNotExists != null && tableNotExists.size() > 0) {
        ArrayList<Boolean> matches = checkTablesExist(tableExists, false);
        if (matches.contains(false)) {
            try {
                throw new Exception("A Table WasFound that Cannot Exist");
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(-1);
            }
        }
    }

}