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.shengpay.commons.bp.logback.LogbackConfigurer.java

/**
 * Initialize logback from the given file location, with no config file refreshing. Assumes an XML file in case of a ".xml" file extension, and a properties file otherwise.
 * //  w w w . j  a  v  a  2  s .c o m
 * @param location
 *            the location of the config file: either a "classpath:" location (e.g. "classpath:mylogback.properties"), an absolute file URL (e.g. "file:C:/logback.properties), or a plain absolute path in the file system (e.g. "C:/logback.properties")
 * @throws FileNotFoundException
 *             if the location specifies an invalid file path
 */
public static void initLogging(String location) throws FileNotFoundException {
    String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
    URL url = ResourceUtils.getURL(resolvedLocation);
    if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) {
        //          DOMConfigurator.configure(url);
        configurator.setContext(lc);
        lc.reset();
        try {
            configurator.doConfigure(url);
        } catch (JoranException ex) {
            throw new FileNotFoundException(url.getPath());
        }
        lc.start();
    }
    //      else {
    //          PropertyConfigurator.configure(url);
    //      }
}

From source file:com.sarm.aussiepayslipgenerator.service.BracketServiceImpl.java

@Override
public Bracket populate(String bracketType) {
    Bracket bracket = new Bracket();
    Properties prop = new Properties();

    String propFileName = "brackets.properties";

    try (InputStream input = getClass().getClassLoader().getResourceAsStream(propFileName)) {

        if (input == null) {
            logger.debug("input Stream for brackets.properties file : is Null  ");
            throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
        }//from ww  w  .  ja  v a2 s. c  om
        prop.load(input);
        //            for (String key : prop.stringPropertyNames()) {
        //                String value = prop.getProperty(key);
        //                System.out.println(key + " => " + value);
        //            }
        //load a properties file from class path, inside static method

        //get the property value and print it out
        logger.debug("bracketType : " + bracketType);
        logger.debug(prop.getProperty(bracketType + ".low"));
        logger.debug(prop.getProperty(bracketType + ".ceiling"));
        logger.debug(prop.getProperty(bracketType + ".flat"));
        logger.debug(prop.getProperty(bracketType + ".rate"));
        logger.debug(prop.getProperty(bracketType + ".over"));

        bracket.setLowerLimit(Integer.valueOf(prop.getProperty(bracketType + ".low")));
        bracket.setCeiling(Integer.valueOf(prop.getProperty(bracketType + ".ceiling")));
        bracket.setIncomeTaxRate(Double.valueOf(prop.getProperty(bracketType + ".rate")));
        bracket.setOver(Integer.valueOf(prop.getProperty(bracketType + ".over")));
        bracket.setFlat(Integer.valueOf(prop.getProperty(bracketType + ".flat")));

    } catch (IOException ex) {
        logger.debug(" IOException caught while populating Bracket" + ex);
        ex.printStackTrace();

    } catch (Exception e) {
        logger.debug(" Exception caught while populating Bracket" + e);

        e.printStackTrace();
    } finally {
        // try with resources will close the inputstream
    }

    return bracket;

}

From source file:hd3gtv.mydmam.useraction.fileoperation.CopyMove.java

public static void checkIsDirectory(File element) throws FileNotFoundException {
    if (element.isDirectory() == false) {
        throw new FileNotFoundException("\"" + element.getPath() + "\" is not a directory");
    }// ww  w .j a  v  a  2 s  .co m
}

From source file:FileLocator.java

/**
 * Locate the specific file.//from w  w  w  . j a va  2  s  .c o m
 * Return the (URL decoded) abolute pathname to the file or null.
 */
public static String locateFile(String findFile) throws FileNotFoundException {
    URL url;
    String fullPathName;
    StringBuffer decodedPathName;
    int pos, len, start;

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

    if (findFile.startsWith(absolutePath))
        return findFile.substring(absolutePath.length());

    if ((fullPathName = locateByProperty(findFile)) != null)
        return fullPathName;

    if ((url = locateByResource(findFile)) != null) {
        /*
         * The URL that we receive from getResource /might/ have ' '
         * (space) characters converted to "%20" strings.  However,
         * it doesn't have other URL encoding (e.g '+' characters are
         * kept intact), so we'll just convert all "%20" strings to
         * ' ' characters and hope for the best.
         */
        fullPathName = url.getFile();
        pos = 0;
        len = fullPathName.length();
        start = 0;
        decodedPathName = new StringBuffer();

        while ((pos = fullPathName.indexOf(pct20, start)) != -1) {
            decodedPathName.append(fullPathName.substring(start, pos));
            decodedPathName.append(' ');
            start = pos + pct20len;
        }

        if (start < len)
            decodedPathName.append(fullPathName.substring(start, len));

        fullPathName = decodedPathName.toString();

        if (platformIsWindows())
            fullPathName = fullPathName.substring(1, fullPathName.length());

        return fullPathName;
    }

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

From source file:com.lazerycode.selenium.filedownloader.CheckFileHash.java

/**
 * The File to perform a Hash check upon
 *
 * @param fileToCheck/*from  w w  w . j a  v a2s.c o m*/
 * @throws FileNotFoundException
 */
public void fileToCheck(File fileToCheck) throws FileNotFoundException {
    if (!fileToCheck.exists())
        throw new FileNotFoundException(fileToCheck + " does not exist!");

    this.fileToCheck = fileToCheck;
}

From source file:com.vmware.photon.controller.api.frontend.config.ConfigurationUtils.java

public static ApiFeConfiguration parseConfiguration(String filename)
        throws IOException, ConfigurationException {
    ObjectMapper objectMapper = Jackson.newObjectMapper(new YAMLFactory());
    ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper()).buildValidatorFactory();
    final ConfigurationFactory<ApiFeStaticConfiguration> configurationFactory = new DefaultConfigurationFactoryFactory<ApiFeStaticConfiguration>()
            .create(ApiFeStaticConfiguration.class, validatorFactory.getValidator(), objectMapper, "dw");
    checkArgument(StringUtils.isNotBlank(filename), "filename cannot be blank");
    final File file = new File(filename);
    if (!file.exists()) {
        throw new FileNotFoundException("File " + file + " not found");
    }//from   w w  w  .j  ava  2  s. c o m
    return configurationFactory.build(file);
}

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

/**
 * Returns whether the given file is a link
 *
 * @param file a File object./*w w w.j a  va 2  s .c o m*/
 * @return whether the given file is a sym link
 *
 * @throws IOException if any.
 */
public static boolean isLink(@Nonnull File file) throws IOException {
    if (!file.exists()) {
        throw new FileNotFoundException(file.getAbsolutePath());
    }

    @Nonnull
    String canonicalPath = file.getCanonicalPath();
    @Nonnull
    String absolutePath = file.getAbsolutePath();
    return !absolutePath.equals(canonicalPath);
}

From source file:com.mycila.testing.plugins.jetty.RegFileLocator.java

/**
 * {@inheritDoc}//from  w w  w  .  j  a v a 2  s .c  o  m
 * 
 * @see com.mycila.testing.plugins.jetty.FileLocator#locate(java.lang.String)
 */
public File locate(final String path) throws FileNotFoundException {
    final Collection<File> files = listFiles(new File("."), new RegExpFileFilter(path), trueFileFilter());
    if (files.size() < 1) {
        throw new FileNotFoundException(
                "regexp '" + quoteReplacement(path) + "' matches less than one file : " + files);
    } else if (files.size() > 1) {
        throw new FileNotFoundException(
                "regexp '" + quoteReplacement(path) + "' matches more than one file : " + files);
    }

    final File file = files.iterator().next();
    return file;
}

From source file:com.sarm.lonelyplanet.common.GeoUtilsTest.java

/**
 * This is the initialization step of this test class.This test depends on
 * the sample test file that is provided in the test.properties. It is
 * designed to be a certain subset for these tests to pass.
 *
 */// www .j a v  a  2 s.  co m
@BeforeClass
public static void setUpClass() {
    Properties prop = new Properties();
    logger.info("GeoUtilsTest : Commencing loading test 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");
        }
        prop.load(input);

    } catch (FileNotFoundException ex) {
        ex.printStackTrace();

        logger.debug("");
    } catch (IOException ex) {
        logger.debug("");
    }
    taxonomyFileName = prop.getProperty(LonelyConstants.propertyTaxonomy);
    destinationTitle = prop.getProperty(LonelyConstants.destinationTitle);
    parentLink = prop.getProperty(LonelyConstants.parentLink);
    childrenLink = prop.getProperty(LonelyConstants.childrenLink);
    sampleDestinationHtml = prop.getProperty(LonelyConstants.sampleDestinationHtml);

    try {
        taxonomies = TaxonomyProcessor.processTaxonomy(taxonomyFileName);
    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException  on file  : " + taxonomyFileName);
        ex.printStackTrace();
    } catch (JAXBException ex) {
        logger.debug("JAXBException  : ");
        ex.printStackTrace();
    }
    populateParentNode = taxonomies.getTaxonomy().getNodesInTaxonomy().get(0).getChildrenNodes().get(0)
            .getChildrenNodes().get(0);
    navigateIntoChildrenNode = taxonomies.getTaxonomy().getNodesInTaxonomy().get(0);
}

From source file:com.cloudseal.spring.client.namespace.Utility.java

public static Element domFromFile(final String fileName, final String rootElement)
        throws ParserConfigurationException, IOException, SAXException {
    final InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
    if (stream == null)
        throw new FileNotFoundException("Cannot find file: " + fileName);
    return DomUtils.getChildElementByTagName(domFromReader(new InputStreamReader(stream, "UTF-8")),
            rootElement);/*from  w w  w .j a v a 2s  .co m*/
}