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:fm.last.moji.local.LocalMojiFile.java

@Override
public void delete() throws IOException {
    if (!file.exists()) {
        throw new FileNotFoundException(file.getCanonicalPath());
    }/*from   w  w w.  j  a va2  s .  co  m*/
    file.delete();
}

From source file:com.chiorichan.http.ssl.CertificateWrapper.java

public CertificateWrapper(File sslCertFile, File sslKeyFile, String sslSecret)
        throws FileNotFoundException, CertificateException {
    if (!sslCertFile.exists())
        throw new FileNotFoundException("The SSL Certificate '" + FileFunc.relPath(sslCertFile)
                + "' (aka. SSL Cert) file does not exist");

    if (!sslKeyFile.exists())
        throw new FileNotFoundException(
                "The SSL Key '" + FileFunc.relPath(sslKeyFile) + "' (aka. SSL Key) file does not exist");

    this.sslCertFile = sslCertFile;
    this.sslKeyFile = sslKeyFile;
    this.sslSecret = sslSecret;

    CertificateFactory cf;//from   w  w  w  .  j  a va  2 s . c  om
    try {
        cf = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new IllegalStateException("Failed to initalize X.509 certificate factory.");
    }

    InputStream in = null;
    try {
        in = new FileInputStream(sslCertFile);
        cert = (X509Certificate) cf.generateCertificate(in);
    } finally {
        if (in != null)
            IOUtils.closeQuietly(in);
    }
}

From source file:com.dhenton9000.filedownloader.CheckFileHash.java

/**
 * Performs a expectedFileHash check on a File.
 *
 * @return/*w  ww  . j  a  va2  s .  c om*/
 * @throws IOException
 */
public boolean hasAValidHash() throws IOException {
    if (this.fileToCheck == null) {
        throw new FileNotFoundException("File to check has not been set!");
    }
    if (this.expectedFileHash == null || this.typeOfHash == null) {
        throw new NullPointerException("Hash details have not been set!");
    }
    if (!this.fileToCheck.exists()) {
        throw new FileNotFoundException("File '" + fileToCheck.getCanonicalPath() + "' not found");
    }

    String actualFileHash = "";
    boolean isHashValid = false;

    switch (this.typeOfHash) {
    case MD5:
        actualFileHash = DigestUtils.md5Hex(new FileInputStream(this.fileToCheck));
        if (this.expectedFileHash.equals(actualFileHash)) {
            isHashValid = true;
        }
        break;
    case SHA1:
        actualFileHash = DigestUtils.shaHex(new FileInputStream(this.fileToCheck));
        if (this.expectedFileHash.equals(actualFileHash)) {
            isHashValid = true;
        }
        break;
    }

    LOG.info("Filename = '" + this.fileToCheck.getName() + "'");
    LOG.info("Expected Hash = '" + this.expectedFileHash + "'");
    LOG.info("Actual Hash = '" + actualFileHash + "'");

    return isHashValid;
}

From source file:com.ysheng.auth.frontend.configuration.ConfigurationParser.java

/**
 * Parses the given configuration file and returns a configuration object.
 *
 * @param configurationFileName The name of the configuration file.
 * @return A configuration object.//from   w  ww  . jav a 2  s  .c  o  m
 * @throws IOException The IO error that contains detail information.
 * @throws ConfigurationException The configuration error that contains detail information.
 */
public static ApiConfiguration parse(String configurationFileName) throws IOException, ConfigurationException {
    if (StringUtils.isBlank(configurationFileName)) {
        throw new IllegalArgumentException("Configuration file cannot be blank");
    }

    ObjectMapper objectMapper = null;
    if (configurationFileName.endsWith("yml") || configurationFileName.endsWith("yaml")) {
        objectMapper = Jackson.newObjectMapper(new YAMLFactory());
    } else if (configurationFileName.endsWith("json")) {
        objectMapper = Jackson.newObjectMapper(new JsonFactory());
    } else {
        throw new IllegalArgumentException("Unrecognized configuration file type");
    }

    ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper()).buildValidatorFactory();

    final ConfigurationFactory<ApiConfiguration> configurationFactory = new DefaultConfigurationFactoryFactory<ApiConfiguration>()
            .create(ApiConfiguration.class, validatorFactory.getValidator(), objectMapper, "dw");

    final File file = new File(configurationFileName);
    if (!file.exists()) {
        throw new FileNotFoundException("Configuration file " + configurationFileName + " not found");
    }

    return configurationFactory.build(file);
}

From source file:ch.cern.dss.teamcity.agent.util.ArchiveExtractor.java

/**
 * @param archivePath// ww w. j  a va2s  .  co  m
 * @param outputFolder
 * @throws CompressorException
 * @throws ArchiveException
 * @throws IOException
 * @throws InterruptedException
 */
public void extract(String archivePath, String outputFolder)
        throws CompressorException, ArchiveException, IOException, InterruptedException, RunBuildException {
    logger.message("Extracting archive: " + archivePath);

    if (!new File(archivePath).exists()) {
        throw new FileNotFoundException("Archive not found: " + archivePath);
    }

    File folder = new File(outputFolder);
    if (!folder.exists()) {
        folder.mkdirs();
    }

    if (archivePath.endsWith(".gz") || archivePath.endsWith(".tgz") || archivePath.endsWith(".bz2")) {
        archivePath = decompress(archivePath);
        extractTar(archivePath, outputFolder);
    } else if (archivePath.endsWith(".rpm")) {
        archivePath = rpm2cpio(archivePath);
        extractCpio(archivePath, outputFolder);
    } else if (archivePath.endsWith(".cpio")) {
        extractCpio(archivePath, outputFolder);
    } else if (archivePath.endsWith(".zip")) {
        extractZip(archivePath, outputFolder);
    } else {
        throw new IOException("Unsupported archive type: " + archivePath);
    }
}

From source file:eu.contrail.security.DelegatedUserCertClientTest.java

public void testFOpenP12() throws Exception {

    System.out.println("openP12");

    String propsPath = "./src/test/resources/keystore.p12";

    File propsFile = null;/*from  w  w w.  j  av  a  2 s. c  o m*/

    try {

        propsFile = new File(propsPath);
        if (!propsFile.exists()) {
            throw new FileNotFoundException(propsPath);
        }

    } catch (FileNotFoundException ex) {
        System.err.println(ex);
    }

}

From source file:com.github.jknack.handlebars.io.URLTemplateLoader.java

@Override
public TemplateSource sourceAt(final String uri) throws IOException {
    notEmpty(uri, "The uri is required.");
    String location = resolve(normalize(uri));
    URL resource = getResource(location);
    if (resource == null) {
        throw new FileNotFoundException(location);
    }/*from w  w  w. ja v  a2  s .  co  m*/
    return new URLTemplateSource(location, resource);
}

From source file:dk.statsbiblioteket.util.Files.java

/**
 * Delete the file or directory given by <code>path</code> (recursively if
 * <code>path</code> is a directory).
 *
 * @param path a {@link File} representing the file or directory to be
 *             deleted./*w ww  .  jav  a2  s .  com*/
 * @throws IOException if the path doesn't exist or could not be deleted.
 */
public static void delete(File path) throws IOException {
    log.trace("delete(" + path + ") called");
    if (!path.exists()) {
        throw new FileNotFoundException(path.toString());
    }
    if (path.isFile()) {
        if (!path.delete()) {
            throw new IOException("Could not delete the file '" + path + "'");
        }
        return;
    }
    for (String child : path.list()) {
        delete(new File(path, child));
    }
    if (!path.delete()) {
        throw new IOException("Could not delete the folder '" + path + "'");
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.osgi.OsgiLayerIntegratedTestHelper.java

public static File getModuleRelativeDirectory(String moduleName, String directory) throws IOException {
    File dir = new File(findProjectRootDirectory(), moduleName.replaceAll(":", "/"));
    dir = new File(dir, directory);
    if (dir.exists())
        return dir;

    throw new FileNotFoundException(
            String.format("Could not find directory %s relative to module %s from project directory %s",
                    directory, moduleName, findProjectRootDirectory().getCanonicalPath()));
}

From source file:com.tc.test.TempDirectoryHelper.java

@Override
protected File fetchDirectory() throws IOException {
    File root = getRoot();//w  w w .j a v a  2s .  com
    if (!root.exists()) {
        root.mkdirs();
    }
    String shortClassName = getTargetClass().getName();
    String[] tokens = shortClassName.split("\\.");
    if (tokens.length > 1) {
        shortClassName = tokens[tokens.length - 1];
    }
    File directory = new File(root, shortClassName);
    if ((!directory.exists()) && (!directory.mkdirs())) {
        FileNotFoundException fnfe = new FileNotFoundException(
                "Directory '" + directory.getAbsolutePath() + "' can't be created.");
        throw fnfe;
    }

    if (cleanDir) {
        int count = 0;
        while (true) {
            count++;
            try {
                FileUtils.cleanDirectory(directory);
                break;
            } catch (Exception e) {
                System.err.println("Unable to clean up the directory - " + directory + "; Exception: " + e);
            }

            if (count > 10) {
                System.err.println("Skipping clean up for directory - " + directory);
                break;
            }

            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
    return directory;
}