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.tc.test.ClassBasedDirectoryTree.java

public ClassBasedDirectoryTree(File root) throws FileNotFoundException {
    Assert.assertNotNull(root);//  w  w w .  j  a va 2  s.  co m
    if ((!root.exists()) || (!root.isDirectory()))
        throw new FileNotFoundException(
                "Root '" + root.getAbsolutePath() + "' does not exist, or is not a directory..");
    this.root = root;
}

From source file:de.elomagic.carafile.client.CaraFileUtils.java

/**
 * Creates a meta file from the given file.
 *
 * @param path Path of the file/*from  w  w w.j  a va 2s .c om*/
 * @param filename Real name of the file because it can differ from path parameter
 * @return
 * @throws IOException
 * @throws GeneralSecurityException
 */
public static final MetaData createMetaData(final Path path, final String filename)
        throws IOException, GeneralSecurityException {
    if (Files.notExists(path)) {
        throw new FileNotFoundException("File " + path.toString() + " not found!");
    }

    if (Files.isDirectory(path)) {
        throw new IllegalArgumentException("Not a file: " + path.toString());
    }

    MetaData md = new MetaData();
    md.setSize(Files.size(path));
    md.setFilename(filename);
    md.setCreationDate(new Date());
    md.setChunkSize(DEFAULT_PIECE_SIZE);

    try (InputStream in = Files.newInputStream(path, StandardOpenOption.READ);
            BufferedInputStream bin = new BufferedInputStream(in)) {
        MessageDigest mdComplete = MessageDigest.getInstance(MessageDigestAlgorithms.SHA_1);

        byte[] buffer = new byte[DEFAULT_PIECE_SIZE];
        int bytesRead;

        while ((bytesRead = bin.read(buffer)) > 0) {
            mdComplete.update(buffer, 0, bytesRead);

            ChunkData chunk = new ChunkData(
                    DigestUtils.sha1Hex(new ByteArrayInputStream(buffer, 0, bytesRead)));
            md.addChunk(chunk);
        }

        String sha1 = Hex.encodeHexString(mdComplete.digest());
        md.setId(sha1);
    }

    return md;
}

From source file:com.sec.ose.osi.util.tools.FileOperator.java

public static void copyFile(File pSource, File pDest) throws FileNotFoundException {

    if (pSource == null)
        throw new FileNotFoundException("Source file is not found");

    if (pSource.exists() == false)
        throw new FileNotFoundException(pSource.getPath());

    if (pDest == null)
        throw new FileNotFoundException("Report file is not found");

    BufferedInputStream bi = null;
    BufferedOutputStream bo = null;

    try {/*w ww .j  a v a 2 s . c o  m*/
        bi = new BufferedInputStream(new FileInputStream(pSource)); // FileNotFoundExeption
        bo = new BufferedOutputStream(new FileOutputStream(pDest));

        byte buffer[] = new byte[BUF_SIZE];

        int readByte = 0;

        while ((readByte = bi.read(buffer)) != -1) { // IOException
            bo.write(buffer, 0, readByte);

        }

    } catch (FileNotFoundException e) {
        log.warn(e);
        throw e;
    } catch (IOException e) {
        log.warn(e);
    } finally {

        if (bo != null) {
            try {
                bo.flush();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.warn(e);
            }
            try {
                bo.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.warn(e);
            }

            bo = null;
        }
        if (bi != null) {
            try {
                bi.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.warn(e);
            }
            bi = null;
        }
    }

}

From source file:com.haulmont.cuba.core.sys.javacl.SourceProvider.java

public String getSourceString(String name) throws IOException {
    File srcFile = getSourceFile(name);
    if (!srcFile.exists()) {
        throw new FileNotFoundException(String.format("Java source for %s not found", name));
    }/*from www  .j  ava2 s.  co m*/
    return FileUtils.readFileToString(srcFile, StandardCharsets.UTF_8);
}

From source file:Main.java

/**
 * Opens a {@link FileInputStream} for the specified file, providing better
 * error messages than simply calling <code>new FileInputStream(file)</code>.
 * <p/>/*from  w ww  . j av a  2 s.  c o  m*/
 * At the end of the method either the stream will be successfully opened,
 * or an exception will have been thrown.
 * <p/>
 * An exception is thrown if the file does not exist.
 * An exception is thrown if the file object exists but is a directory.
 * An exception is thrown if the file exists but cannot be read.
 *
 * @param file the file to open for input, must not be {@code null}
 * @return a new {@link FileInputStream} for the specified file
 * @throws FileNotFoundException if the file does not exist
 * @throws IOException           if the file object is a directory
 * @throws IOException           if the file cannot be read
 * @since 1.3
 */
public static FileInputStream openInputStream(File file) throws IOException {
    if (file.exists()) {
        if (file.isDirectory()) {
            throw new IOException("File '" + file + "' exists but is a directory");
        }
        if (file.canRead() == false) {
            throw new IOException("File '" + file + "' cannot be read");
        }
    } else {
        throw new FileNotFoundException("File '" + file + "' does not exist");
    }
    return new FileInputStream(file);
}

From source file:com.sarm.Travelogue.process.DestinationProcessorTest.java

@BeforeClass
public static void setUpClass() {
    logger.info("DestinationProcessorTest  Commencing loading test properties ...");
    Properties prop = new Properties();

    String propFileName = LonelyConstants.testPropertyFile;

    try (InputStream input = new FileInputStream(propFileName)) {

        if (input == null) {
            logger.debug("input Stream for test.properties file : is Null  ");
            throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
        }/* www .j a va 2s .  c om*/
        logger.debug("Loading properties file   " + propFileName);

        prop.load(input);
    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException  " + propFileName);
        ex.printStackTrace();
    } catch (IOException ex) {
        logger.debug("IOException  " + propFileName);
        ex.printStackTrace();
    }

    taxonomyFileName = prop.getProperty(LonelyConstants.propertyTaxonomy);
    targetLocation = prop.getProperty(LonelyConstants.propertyHtmlTarget);
    destinationFileName = prop.getProperty(LonelyConstants.propertyDestination);
    destinationsConcurrantlyExpresult = prop.getProperty(LonelyConstants.destinationsConcurrantlyExpresult);
    numOfDestinations = Integer.valueOf(prop.getProperty(LonelyConstants.numOfDestinations));
    regressDestinationfile = prop.getProperty(LonelyConstants.regressDestinationfile);
    indexOfdestInConcurrent = prop.getProperty(LonelyConstants.indexOfdestInConcurrent);
    try {
        sampleTesttaxonomies = TaxonomyProcessor.processTaxonomy(taxonomyFileName);
    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException  on file  : " + taxonomyFileName);
        ex.printStackTrace();
    } catch (JAXBException ex) {
        logger.debug("JAXBException  : ");
        ex.printStackTrace();
    }

}

From source file:info.evanchik.eclipse.karaf.core.KarafCorePluginUtils.java

/**
 * Copies the source file to the destination file
 *
 * @param src// w w w .  j  av a2  s .c om
 *            the source file
 * @param dst
 *            the destination file
 * @throws IOException
 *             if there is a problem during the file copy
 */
public static void copyFile(final File src, final File dst) throws IOException {
    if (!src.exists()) {
        throw new FileNotFoundException("File does not exist: " + src.getAbsolutePath());
    }

    if (!dst.exists()) {
        dst.createNewFile();
    }

    FileChannel source = null;
    FileChannel destination = null;
    try {
        source = new FileInputStream(src).getChannel();
        destination = new FileOutputStream(dst).getChannel();

        destination.transferFrom(source, 0, source.size());
    } finally {
        if (source != null) {
            source.close();
        }

        if (destination != null) {
            destination.close();
        }
    }
}

From source file:com.sarm.lonelyplanet.process.DestinationProcessorTest.java

@BeforeClass
public static void setUpClass() {
    logger.info("DestinationProcessorTest  Commencing loading test properties ...");
    Properties prop = new Properties();

    String propFileName = LonelyConstants.testPropertyFile;

    try (InputStream input = new FileInputStream(propFileName)) {

        if (input == null) {
            logger.debug("input Stream for test.properties file : is Null  ");
            throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
        }//from w w  w  .  j  ava  2 s . co m
        logger.debug("Loading properties file   " + propFileName);

        prop.load(input);
    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException  " + propFileName);
        ex.printStackTrace();
    } catch (IOException ex) {
        logger.debug("IOException  " + propFileName);
        ex.printStackTrace();
    }

    taxonomyFileName = prop.getProperty(LonelyConstants.propertyTaxonomy);
    targetLocation = prop.getProperty(LonelyConstants.propertyHtmlTarget);
    destinationFileName = prop.getProperty(LonelyConstants.propertyDestination);
    destinationsConcurrantlyExpresult = prop.getProperty(LonelyConstants.destinationsConcurrantlyExpresult);
    numOfDestinations = Integer.valueOf(prop.getProperty(LonelyConstants.numOfDestinations));
    regressDestinationfile = prop.getProperty(LonelyConstants.regressDestinationfile);
    indexOfdestInConcurrent = prop.getProperty(LonelyConstants.indexOfdestInConcurrent);
    try {
        sampleTesttaxonomies = TaxonomyProcessor.processTaxonomy(taxonomyFileName);
    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException  on file  : " + taxonomyFileName);
        ex.printStackTrace();
    } catch (JAXBException ex) {
        logger.debug("JAXBException  : ");
        ex.printStackTrace();
    }

    try {
        testMarshall(".//destinations.xml");
    } catch (JAXBException | FileNotFoundException | XMLStreamException | UnsupportedEncodingException ex) {
        ex.printStackTrace();

    }

}

From source file:jp.ac.u.tokyo.m.resource.ResourceLoadUtil.java

private static Ini loadNecessaryIni(Class<?> aClass, String aFileName, InputStream aResourceAsStream) {
    try {/*from   w  ww .j  av a2 s  .com*/
        return loadIni(aClass, aFileName, aResourceAsStream);
    } catch (NullPointerException e) {
        throw new RuntimeException(new FileNotFoundException(aClass.getPackage() + "." + aFileName));
    }
}

From source file:com.stratio.mojo.scala.crossbuild.FileRewriter.java

public void rewrite(final File file) throws IOException {
    if (!file.exists()) {
        throw new FileNotFoundException("File does not exist: " + file);
    }//from w w w  .  j av  a  2 s .  c o m
    backupFile(file);
    String result = IOUtils.toString(new FileInputStream(file), StandardCharsets.UTF_8);
    for (final RewriteRule rule : rules) {
        result = rule.replace(result);
    }
    IOUtils.write(result, new FileOutputStream(file), StandardCharsets.UTF_8);
}