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:bixo.examples.webmining.DemoWebMiningWorkflow.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void importSeedUrls(BasePlatform platform, BasePath crawlDbPath, String fileName)
        throws Exception {

    SimpleUrlNormalizer normalizer = new SimpleUrlNormalizer();

    InputStream is = null;// w  w  w .  j  a v a  2  s. c o  m
    TupleEntryCollector writer = null;
    try {
        Tap urlSink = platform.makeTap(platform.makeTextScheme(), crawlDbPath, SinkMode.REPLACE);
        writer = urlSink.openForWrite(platform.makeFlowProcess());

        is = DemoWebMiningWorkflow.class.getResourceAsStream(fileName);
        if (is == null) {
            throw new FileNotFoundException("The seed urls file doesn't exist");
        }

        List<String> lines = IOUtils.readLines(is);
        for (String line : lines) {
            line = line.trim();
            if (line.startsWith("#")) {
                continue;
            }

            CrawlDbDatum datum = new CrawlDbDatum(normalizer.normalize(line), 0, UrlStatus.UNFETCHED, 0.0f,
                    0.0f);
            writer.add(datum.getTuple());
        }

    } catch (IOException e) {
        crawlDbPath.delete(true);
        throw e;
    } finally {
        IoUtils.safeClose(is);
        if (writer != null) {
            writer.close();
        }
    }

}

From source file:com.jeeframework.util.resource.ClassPathResource.java

/**
 * This implementation opens an InputStream for the given class path resource.
 * @see java.lang.ClassLoader#getResourceAsStream(String)
 * @see java.lang.Class#getResourceAsStream(String)
 *///w  w w . ja  v a2 s.  c  o  m
public InputStream getInputStream() throws IOException {
    InputStream is = null;
    if (this.clazz != null) {
        is = this.clazz.getResourceAsStream(this.path);
    } else {
        is = this.classLoader.getResourceAsStream(this.path);
    }
    if (is == null) {
        throw new FileNotFoundException(getDescription() + " cannot be opened because it does not exist");
    }
    return is;
}

From source file:edu.caltech.ipac.firefly.server.servlets.AnyFileUpload.java

private File resolveDestDir(String dest, FileType fType) throws FileNotFoundException {
    File destDir = ServerContext.getTempWorkDir();
    if (!StringUtils.isEmpty(dest)) {
        destDir = ServerContext.convertToFile(dest);
    } else if (fType == FileType.FITS) {
        destDir = ServerContext.getVisCacheDir();
    }//  w w w.j a  v a2 s.  c  om
    if (!destDir.exists()) {
        throw new FileNotFoundException("Destination path does not exists: " + destDir.getPath());
    }
    return destDir;
}

From source file:ca.simplegames.micro.utils.ResourceUtils.java

/**
 * Resolve the given resource location to a <code>java.io.File</code>,
 * i.e. to a file in the file system.//from www .  ja v a2s.c o m
 * <p>Does not check whether the fil actually exists; simply returns
 * the File that the given location would correspond to.
 *
 * @param resourceLocation the resource location to resolve: either a
 *                         "classpath:" pseudo URL, a "file:" URL, or a plain file path
 * @return a corresponding File object
 * @throws FileNotFoundException if the resource cannot be resolved to
 *                               a file in the file system
 */
public static File getFile(String resourceLocation) throws FileNotFoundException {
    Assert.notNull(resourceLocation, "Resource location must not be null");
    if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) {
        String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length());
        String description = "class path resource [" + path + "]";
        URL url = ClassUtils.getDefaultClassLoader().getResource(path);
        if (url == null) {
            throw new FileNotFoundException(description + " cannot be resolved to absolute file path "
                    + "because it does not reside in the file system");
        }
        return getFile(url, description);
    }
    try {
        // try URL
        return getFile(new URL(resourceLocation));
    } catch (MalformedURLException ex) {
        // no URL -> treat as file path
        return new File(resourceLocation);
    }
}

From source file:com.textocat.textokit.corpus.statistics.dao.corpus.XmiFileTreeCorpusDAO.java

@Override
public void getDocumentCas(URI docURI, String annotatorId, CAS aCAS) throws SAXException, IOException {
    if (fileByURIandAnnotatorId.containsKey(new UriAnnotatorPair(docURI, annotatorId))) {
        FileInputStream xmiFileIn = new FileInputStream(
                fileByURIandAnnotatorId.get(new UriAnnotatorPair(docURI, annotatorId)));
        XmlCasDeserializer.deserialize(xmiFileIn, aCAS);
        closeQuietly(xmiFileIn);//w  w  w .j  a v  a 2  s.  co m
    } else {
        throw new FileNotFoundException(
                String.format("There is no document '%s' annotated by '%s'", docURI, annotatorId));
    }
}

From source file:net.ontopia.utils.TestFileUtils.java

public static URL getTestInputURL(String resource) throws FileNotFoundException {
    URL url = Thread.currentThread().getContextClassLoader().getResource(
            resource.startsWith("classpath:") ? resource.substring("classpath:".length()) : resource);
    if (url == null)
        throw new FileNotFoundException("Test resource " + resource + " not found");
    return url;/* ww  w. j  ava  2  s  .co  m*/
}

From source file:com.funambol.lanciadelta.LanciaDeltaShell.java

/**
 * Executes the script read from the standard input stream or given URL
 *
 * @throws Exceptino in case of errors//w w  w .java  2s . c  om
 *
 */
private void execute() throws Exception {
    if (isInteractive()) {
        while (true) {
            try {
                Interpreter beanshell = getInterpreter();
                beanshell.setShowResults(true);
                beanshell.run();
            } catch (Exception e) {
                System.err.println("ERR: " + e.getMessage());
                System.err.println(">>>");
                e.printStackTrace();
                System.err.println("<<<");
            }
        }
    } else {
        File f = new File(System.getProperty(PROPERTY_SCRIPT));

        if (!f.exists()) {
            throw new FileNotFoundException("Script file not found: " + f.getAbsolutePath());
        }

        try {
            Interpreter beanshell = getInterpreter();

            beanshell.setExitOnEOF(true);
            beanshell.setShowResults(false);
            beanshell.eval(new InputStreamReader(new FileInputStream(f)));
        } catch (Exception e) {
            System.err.println("ERR: " + e.getMessage());
            System.err.println(">>>");
            e.printStackTrace();
            System.err.println("<<<");
        }
    }
}

From source file:monasca.common.dropwizard.AbstractResourceTest.java

/**
 * Returns a configuration object read in from the {@code fileName}.
 *//*w  w w.j  ava 2s.c o  m*/
protected <T extends Configuration> T getConfiguration(String filename, Class<T> configurationClass)
        throws Exception {
    final ConfigurationFactory<T> configurationFactory = new ConfigurationFactory<>(configurationClass,
            validator, objectMapper, "dw");
    if (filename != null) {
        final File file = new File(Resources.getResource(filename).getFile());
        if (!file.exists())
            throw new FileNotFoundException("File " + file + " not found");
        return configurationFactory.build(file);
    }

    return configurationFactory.build();
}

From source file:net.sf.jasperreports.engine.util.JRLoader.java

/**
 *
 *//*www . j  a v a  2  s . c  om*/
public static Object loadObject(JasperReportsContext jasperReportsContext, File file) throws JRException {
    if (!file.exists() || !file.isFile()) {
        throw new JRException(new FileNotFoundException(String.valueOf(file)));
    }

    Object obj = null;

    FileInputStream fis = null;
    ObjectInputStream ois = null;

    try {
        fis = new FileInputStream(file);
        BufferedInputStream bufferedIn = new BufferedInputStream(fis);
        ois = new ContextClassLoaderObjectInputStream(jasperReportsContext, bufferedIn);
        obj = ois.readObject();
    } catch (IOException e) {
        throw new JRException(EXCEPTION_MESSAGE_KEY_OBJECT_FROM_FILE_LOADING_ERROR, new Object[] { file }, e);
    } catch (ClassNotFoundException e) {
        throw new JRException(EXCEPTION_MESSAGE_KEY_CLASS_NOT_FOUND_FROM_FILE, new Object[] { file }, e);
    } finally {
        if (ois != null) {
            try {
                ois.close();
            } catch (IOException e) {
            }
        }

        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
            }
        }
    }

    return obj;
}

From source file:org.motechproject.mobile.imp.serivce.oxd.FormDefinitionServiceImpl.java

public List<File> getFileList(String directorySource) throws IOException {

    File directory = new ClassPathResource(directorySource).getFile();
    if (directory == null)
        throw new RuntimeException(new FileNotFoundException(" resource not found" + directorySource));

    if (!directory.exists())
        return Collections.emptyList();

    List<File> fileList = Arrays.asList(directory.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (name.endsWith(".xml"))
                return true;
            return false;
        }//from   www. ja v a 2s . c  o m
    }));
    Collections.sort(fileList, new Comparator<File>() {
        public int compare(File o1, File o2) {
            return o1.getName().compareToIgnoreCase(o2.getName());
        }
    });
    return fileList;
}