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.przyjaznyplan.utils.CsvConverter.java

public void open(String path) throws FileNotFoundException {

    path = Environment.getExternalStorageDirectory().toString() + "/" + path;
    if (!new File(path).exists()) {
        Log.i("NO FILE", path + " DOES NOT EXIST");
        throw new FileNotFoundException(" DOES NOT EXIST");
    }/*from www .  ja  va  2s  . co  m*/

    lines = new ArrayList<String[]>();
    try {
        reader = new CSVReader(new FileReader(path), SEPARATOR);
    } catch (FileNotFoundException e) {
        Log.e("CSV Reader EXCEPTION", e.getMessage());
    }
    String[] nextLine;

    try {
        while ((nextLine = reader.readNext()) != null) {

            lines.add(nextLine);

        }
    } catch (Exception e) {
        Log.e("CSV Reader EXCEPTION", e.getMessage());
    }

    rootFolder = new File(path).getParent();

}

From source file:net.slkdev.swagger.confluence.service.impl.SwaggerToAsciiDocServiceImpl.java

private static File getSchemaFile(final String swaggerSchemaPath)
        throws FileNotFoundException, URISyntaxException {
    // First we'll try to find the file directly
    File swaggerFile = new File(swaggerSchemaPath);

    // If we can't find it, we'll check the classpath
    if (!swaggerFile.exists()) {
        final URL swaggerSchemaURL = SwaggerToAsciiDocServiceImpl.class.getResource(swaggerSchemaPath);

        if (swaggerSchemaURL == null) {
            swaggerFile = null;/*from   w w w  . j a  v  a2 s . c  o  m*/
        } else {
            swaggerFile = new File(swaggerSchemaURL.toURI());
        }
    }

    if (swaggerFile == null || !swaggerFile.exists() || !swaggerFile.canRead()) {
        throw new FileNotFoundException(
                String.format("Unable to Locate Swagger Schema at Path <%s>", swaggerSchemaPath));
    }

    return swaggerFile;
}

From source file:com.cedarsoft.serialization.serializers.jackson.registry.DirBasedObjectsAccess.java

/**
 * Provides the ids/*from   w w  w.ja va2  s  .  c o m*/
 *
 * @return the ids
 *
 * @throws FileNotFoundException
 */
@Nonnull
@Override
public Set<? extends String> getIds() throws IOException {
    assert baseDir.exists();
    File[] dirs = baseDir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
    if (dirs == null) {
        throw new FileNotFoundException("Could not list dirs in " + baseDir.getAbsolutePath());
    }

    Set<String> ids = new HashSet<String>();
    for (File dir : dirs) {
        ids.add(dir.getName());
    }

    return ids;
}

From source file:org.opennms.tools.NotificationsGenerator.java

/**
 * Generate notifications./*from   ww  w .j ava 2s  . co m*/
 *
 * @param onmsHome the OpenNMS home directory
 * @param notificationsTemplate the notifications template
 * @throws Exception the exception
 */
public void generateNotifications(File onmsHome, File notificationsTemplate) throws Exception {
    File thresholdsFile = new File(onmsHome, "etc/thresholds.xml");
    if (!thresholdsFile.exists()) {
        throw new FileNotFoundException(thresholdsFile.getAbsolutePath());
    }
    if (!notificationsTemplate.exists()) {
        throw new FileNotFoundException(notificationsTemplate.getAbsolutePath());
    }

    ThresholdingConfig thresholdsConfig = CastorUtils.unmarshal(ThresholdingConfig.class,
            new FileSystemResource(thresholdsFile), true);

    Notifications notifications = CastorUtils.unmarshal(Notifications.class,
            new FileSystemResource(notificationsTemplate), true);
    notifications.getHeader().setCreated(EventConstants.formatToString(new Date()));

    notifications.getNotificationCollection()
            .addAll(eventProcessor.getNotifications(thresholdsConfig.getGroupCollection()));

    File notificationsFile = new File(onmsHome, "etc/notifications.xml");
    System.out.println("Generating " + notificationsFile);
    Marshaller m = new Marshaller(new FileWriter(notificationsFile));
    m.setSuppressNamespaces(false);
    m.marshal(notifications);
}

From source file:org.opennms.tools.EventsGenerator.java

/**
 * Generate threshold events./*  w  ww. ja va  2  s .c  o  m*/
 *
 * @param onmsHome the OpenNMS home directory
 * @throws Exception the exception
 */
public void generateThresholdEvents(File onmsHome) throws Exception {
    File thresholdsFile = new File(onmsHome, "etc/thresholds.xml");
    if (!thresholdsFile.exists()) {
        throw new FileNotFoundException(thresholdsFile.getAbsolutePath());
    }
    ThresholdingConfig thresholdsConfig = CastorUtils.unmarshal(ThresholdingConfig.class,
            new FileSystemResource(thresholdsFile), true);

    File graphTemplatesFile = new File(onmsHome, "etc/snmp-graph.properties");
    if (!graphTemplatesFile.exists()) {
        throw new FileNotFoundException(graphTemplatesFile.getAbsolutePath());
    }
    PropertiesGraphDao graphDao = new PropertiesGraphDao();
    graphDao.loadProperties("performance", new FileSystemResource(graphTemplatesFile));

    Events events = eventProcessor.getEvents(thresholdsConfig.getGroupCollection(),
            graphDao.getAllPrefabGraphs());
    File eventFile = new File(onmsHome, "etc/events/" + EVENTS_FILENAME);
    System.out.println("Generating " + eventFile);
    JaxbUtils.marshal(events, new FileWriter(eventFile));
}

From source file:com.cloudera.recordservice.tests.ClusterConfiguration.java

public ClusterConfiguration(String hostname, String username, String password)
        throws MalformedURLException, JSONException, IOException {
    rand_ = new Random();
    hostname_ = hostname;//w  ww  .jav a  2  s . c  om
    username_ = username;
    password_ = password;
    urlBase_ = "http://" + hostname + ":" + cmPort_ + "/api/" + apiVersionString_ + "/";
    if (!getClusterConfPath()) {
        throw new FileNotFoundException("Unable to access the cluster's cm web api");
    }
}

From source file:maspack.fileutil.SafeFileUtils.java

/**
 * Moves a file.//from w ww  .java  2s  .  co m
 * <p>
 * When the destination file is on another file system, do a
 * "copy and delete".
 * 
 * @param srcFile
 * the file to be moved
 * @param destFile
 * the destination file
 * @throws NullPointerException
 * if source or destination is {@code null}
 * @throws IOException
 * if source or destination is invalid
 * @throws IOException
 * if an IO error occurs moving the file
 * @since 1.4
 */
public static void moveFile(File srcFile, File destFile, int options) throws IOException {

    if (srcFile == null) {
        throw new NullPointerException("Source must not be null");
    }
    if (destFile == null) {
        throw new NullPointerException("Destination must not be null");
    }
    if (!srcFile.exists()) {
        throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
    }
    if (srcFile.isDirectory()) {
        throw new IOException("Source '" + srcFile + "' is a directory");
    }
    if (destFile.isDirectory()) {
        throw new IOException("Destination '" + destFile + "' is a directory");
    }

    if (destFile.exists()) {
        destFile.delete(); // try to delete destination before move
    }

    boolean rename = srcFile.renameTo(destFile);
    if (!rename) {
        copyFile(srcFile, destFile, options);
        if (!srcFile.delete()) {
            deleteQuietly(destFile);
            throw new IOException(
                    "Failed to delete original file '" + srcFile + "' after copy to '" + destFile + "'");
        }
    }
}

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

@Override
public TemplateSource sourceAt(final String location) throws IOException {
    for (TemplateLoader delegate : delegates) {
        try {//from ww  w. j av a2s.  co  m
            return delegate.sourceAt(location);
        } catch (IOException ex) {
            // try next loader in the chain.
            logger.trace("Unable to resolve: {}, trying next loader in the chain.", location);
        }
    }
    throw new FileNotFoundException(location);
}

From source file:com.opengamma.integration.server.copier.ServerDatabasePopulator.java

public void run() throws Exception {
    Resource res = ResourceUtils.createResource(_configFile);
    Properties props = new Properties();
    try (InputStream in = res.getInputStream()) {
        if (in == null) {
            throw new FileNotFoundException(_configFile);
        }//from  w w w  . ja  v  a 2  s  . c  o  m
        props.load(in);
    }
    _populatorTool.run(ResourceUtils.toResourceLocator(res), ToolContext.class);
}

From source file:org.apache.james.container.spring.filesystem.FileSystemImpl.java

/**
 * @see org.apache.james.filesystem.api.FileSystem#getFile(String)
 *//*w  ww.jav  a  2  s  .  c o  m*/
public File getFile(String fileURL) throws FileNotFoundException {
    try {
        return resourceLoader.getResource(fileURL).getFile();
    } catch (IOException e) {
        throw new FileNotFoundException(e.getMessage());
    }
}