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:net.erdfelt.android.sdkfido.local.LocalAndroidPlatforms.java

/**
 * Attempt to find the local java sdk using the most common environment variables.
 * //w  ww.j av a 2s . c o  m
 * @return the local android java sdk directory
 * @throws IOException
 *             if unable to load the default local java sdk
 */
public static File findLocalJavaSdk() throws IOException {
    StringBuilder err = new StringBuilder();
    err.append("Unable to find the Local Android Java SDK Folder.");

    // Check Environment Variables First
    String envKeys[] = { "ANDROID_HOME", "ANDROID_SDK_ROOT" };
    for (String envKey : envKeys) {
        File sdkHome = getEnvironmentVariableDir(err, envKey);
        if (sdkHome == null) {
            continue; // skip, not found on that key
        }
        LocalAndroidPlatforms platforms = new LocalAndroidPlatforms(sdkHome);
        if (platforms.valid()) {
            return sdkHome;
        }
    }

    // Check Path for possible android.exe (or similar)
    List<String> searchBins = new ArrayList<String>();
    if (SystemUtils.IS_OS_WINDOWS) {
        searchBins.add("adb.exe");
        searchBins.add("emulator.exe");
        searchBins.add("android.exe");
    } else {
        searchBins.add("adb");
        searchBins.add("emulator");
        searchBins.add("android");
    }

    String pathParts[] = StringUtils.split(System.getenv("PATH"), File.pathSeparatorChar);
    for (String searchBin : searchBins) {
        err.append("\nSearched PATH for ").append(searchBin);
        for (String pathPart : pathParts) {
            File pathDir = new File(pathPart);
            LOG.fine("Searching Path: " + pathDir);
            File bin = new File(pathDir, searchBin);
            if (bin.exists() && bin.isFile() && bin.canExecute()) {
                File homeDir = bin.getParentFile().getParentFile();
                LOG.fine("Possible Home Dir: " + homeDir);
                LocalAndroidPlatforms platforms = new LocalAndroidPlatforms(homeDir);
                if (platforms.valid) {
                    return homeDir;
                }
            }
        }
        err.append(", not found.");
    }

    throw new FileNotFoundException(err.toString());
}

From source file:it.publisys.ims.discovery.job.EntityTasks.java

@Scheduled(fixedRate = 600000, initialDelay = 5000)
public void reloadEntities() {
    log.debug("Reload Entities");

    log.debug("ServletContext: " + servletContext);

    try {// ww w . j ava  2 s.c  om
        Resource resourceDir = new ClassPathResource(METADATA_DIR + "/" + GUARDS_DIR);

        if (!resourceDir.exists()) {
            throw new FileNotFoundException(
                    String.format("Directory dei Medatada non presente. [%s]", resourceDir));
        }

        List<File> files = loadMetadataXml(resourceDir.getFile());
        EntitiesDescriptorDocument entitiesDescriptorDocument = storeEntitiesFile(files);

        EntityDescriptorType[] entityDescriptorTypes = loadAndCacheEntities(entitiesDescriptorDocument);
        loadEntities(entityDescriptorTypes);

    } catch (FileNotFoundException fnfe) {
        log.warn(fnfe.getMessage(), fnfe);
    } catch (IOException ioe) {
        log.warn("Caricamento Metadata non riuscito.", ioe);
    }

}

From source file:fr.simon.marquis.secretcodes.util.ExportContentProvider.java

@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
    if (!CONTENT_URI.equals(uri)) {
        throw new FileNotFoundException(uri.getPath());
    }/*from  w  ww.  j  a v a2  s  .com*/

    ArrayList<SecretCode> secretCodes = Utils.getSecretCodes(getContext());

    deletePreviousData();
    saveJsonFile(secretCodes);
    saveImageFiles(secretCodes);
    saveZipFile();

    File zipFile = new File(getContext().getFilesDir(), ZIP_FILE_NAME);
    if (zipFile.exists()) {
        return ParcelFileDescriptor.open(zipFile, ParcelFileDescriptor.MODE_READ_ONLY);
    }
    throw new FileNotFoundException(uri.getPath());
}

From source file:org.cleverbus.admin.web.msg.MessageLogParser.java

/**
 * Gets lines from the log file which corresponds with specified correlation ID.
 *
 * @param correlationId the correlation ID
 * @param logDate which date to search log files for
 * @return log lines/*from www .j av a  2  s .  c o m*/
 * @throws IOException when error occurred during file reading
 */
List<String> getLogLines(String correlationId, Date logDate) throws IOException {
    File logFolder = new File(logFolderPath);
    if (!logFolder.exists() || !logFolder.canRead()) {
        throw new FileNotFoundException("there is no readable log folder - " + logFolderPath);
    }

    final String logDateFormatted = fileFormat.format(logDate);

    // filter log files for current date
    IOFileFilter nameFilter = new IOFileFilter() {
        @Override
        public boolean accept(File file) {
            return logNameFilter.accept(file) && (StringUtils.contains(file.getName(), logDateFormatted)
                    || file.getName().endsWith(BASE_FILE_EXTENSION));
        }

        @Override
        public boolean accept(File dir, String name) {
            return StringUtils.contains(name, logDateFormatted) || name.endsWith(BASE_FILE_EXTENSION);

        }
    };

    List<File> logFiles = new ArrayList<File>(FileUtils.listFiles(logFolder, nameFilter, null));
    Collections.sort(logFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);

    // go through all log files
    List<String> logLines = new ArrayList<String>();
    for (File logFile : logFiles) {
        logLines.addAll(getLogLines(logFile, correlationId));
    }

    return logLines;
}

From source file:eu.scape_project.archiventory.container.TestContainer.java

/**
 * Create temporary files for the test container
 *
 * @param resourcePath Resource path//w  ww .j  a v a 2 s .c  om
 * @return temporary file
 * @throws FileNotFoundException
 * @throws IOException
 */
private File createTempTestFile(String resourcePath) throws FileNotFoundException, IOException {
    InputStream testFileStream = TestContainer.class.getResourceAsStream(resourcePath);
    if (testFileStream == null) {
        throw new FileNotFoundException(resourcePath);
    }
    String filePath = extractDirectoryName + File.separator + resourcePath;
    File tmpTestFile = new File(filePath);
    Files.createParentDirs(tmpTestFile);
    tmpTestFile.deleteOnExit();
    FileOutputStream fos = new FileOutputStream(tmpTestFile);
    IOUtils.copy(testFileStream, fos);
    fos.close();
    return tmpTestFile;
}

From source file:com.athena.dolly.console.module.core.DollyConfig.java

/**
 * <pre>// ww  w.j a va2 s.  com
 * System Property ? classpath?  ? ?? .
 * </pre>
 * @return
 * @throws ConfigurationException
 */
private Properties loadConfigFile() throws ConfigurationException {
    InputStream configResource = null;

    try {
        String configFile = System.getProperty(CONFIG_FILE);

        if (configFile != null && !"".equals(configFile)) {
            configResource = new BufferedInputStream(new FileInputStream(configFile));
        } else {
            configResource = Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIG_FILE);
        }

        if (configResource == null) {
            throw new FileNotFoundException("Could not locate " + CONFIG_FILE
                    + " in the classpath or System Poroperty(-Ddolly.properties=Full Qualified File Name) path.");
        }

        Properties config = new Properties();
        config.load(configResource);

        configResource.close();

        return config;
    } catch (IOException e) {
        throw new ConfigurationException("Could not load the configuration file (" + CONFIG_FILE + "). "
                + "Please make sure it exists at the root of the classpath or System Poroperty(-Ddolly.properties=Full Qualified File Name) path.",
                e);
    }
}

From source file:nl.knaw.dans.common.lang.spring.FileBasedPropertyPlaceholderConfigurer.java

public FileBasedPropertyPlaceholderConfigurer(final String resourcePath) throws FileNotFoundException {
    final List<File> locationsToTry = new LinkedList<File>();
    final String filename = System.getProperty("user.name") + ".properties";
    locationsToTry.add(new File(resourcePath, filename));
    locationsToTry.add(new File(resourcePath, DEFAULT_RESOURCE_PATH + "/" + filename));
    locationsToTry.add(new File(resourcePath, DEFAULT_PROPERTIES_FILE));
    locationsToTry.add(new File(resourcePath, DEFAULT_RESOURCE_PATH + "/" + DEFAULT_PROPERTIES_FILE));
    for (final File file : locationsToTry) {
        if (file.exists()) {
            logger.info("Found application properties at " + file.getAbsolutePath());
            setLocation(new FileSystemResource(file));
            return;
        }//from  ww  w  . j a va 2s . c o m
    }
    throw new FileNotFoundException(
            String.format("No properties file found; tried: %s", locationsToTry.toString()));
}

From source file:ml.dmlc.xgboost4j.java.NativeLibLoader.java

/**
 * Create a temp file that copies the resource from current JAR archive
 * <p/>/*from   ww  w  .ja  va2s .  c  om*/
 * The file from JAR is copied into system temp file.
 * The temporary file is deleted after exiting.
 * Method uses String as filename because the pathname is "abstract", not system-dependent.
 * <p/>
 * The restrictions of {@link File#createTempFile(java.lang.String, java.lang.String)} apply to
 * {@code path}.
 * @param path Path to the resources in the jar
 * @return The created temp file.
 * @throws IOException
 * @throws IllegalArgumentException
 */
static String createTempFileFromResource(String path) throws IOException, IllegalArgumentException {
    // Obtain filename from path
    if (!path.startsWith("/")) {
        throw new IllegalArgumentException("The path has to be absolute (start with '/').");
    }

    String[] parts = path.split("/");
    String filename = (parts.length > 1) ? parts[parts.length - 1] : null;

    // Split filename to prexif and suffix (extension)
    String prefix = "";
    String suffix = null;
    if (filename != null) {
        parts = filename.split("\\.", 2);
        prefix = parts[0];
        suffix = (parts.length > 1) ? "." + parts[parts.length - 1] : null; // Thanks, davs! :-)
    }

    // Check if the filename is okay
    if (filename == null || prefix.length() < 3) {
        throw new IllegalArgumentException("The filename has to be at least 3 characters long.");
    }
    // Prepare temporary file
    File temp = File.createTempFile(prefix, suffix);
    temp.deleteOnExit();

    if (!temp.exists()) {
        throw new FileNotFoundException("File " + temp.getAbsolutePath() + " does not exist.");
    }

    // Prepare buffer for data copying
    byte[] buffer = new byte[1024];
    int readBytes;

    // Open and check input stream
    InputStream is = NativeLibLoader.class.getResourceAsStream(path);
    if (is == null) {
        throw new FileNotFoundException("File " + path + " was not found inside JAR.");
    }

    // Open output stream and copy data between source file in JAR and the temporary file
    OutputStream os = new FileOutputStream(temp);
    try {
        while ((readBytes = is.read(buffer)) != -1) {
            os.write(buffer, 0, readBytes);
        }
    } finally {
        // If read/write fails, close streams safely before throwing an exception
        os.close();
        is.close();
    }
    return temp.getAbsolutePath();
}

From source file:com.spotify.annoy.jni.base.AnnoyIndexImpl.java

AnnoyIndexImpl load(String filename) throws FileNotFoundException {
    if (Files.notExists(Paths.get(filename))) {
        throw new FileNotFoundException("Cannot find annoy index: " + filename);
    }/*from w ww.  j  av  a 2s  .  c  om*/
    cppLoad(this.cppPtr, filename);
    return this;
}

From source file:ca.simplegames.micro.viewers.mustache.MustacheViewRenderer.java

@Override
public long render(String path, Repository repository, MicroContext context, Writer out)
        throws FileNotFoundException, ViewException {

    if (repository != null && out != null) {

        try {/* w w  w.j  a  va 2  s .  c o  m*/
            Mustache mustache;
            String key = repository.getName() + KEY_SEP + path;

            StringWriter sw = new StringWriter();
            StringReader source = new StringReader(repository.read(path));
            if (mustaches != null) {
                Element mustacheElement = (Element) mustaches.get(key);
                if (mustacheElement == null) {
                    mustache = mf.compile(source, key);
                    mustaches.put(key, new Element(NAME, mustache));
                } else {
                    mustache = (Mustache) mustacheElement.getObjectValue();
                }
            } else {
                mustache = mf.compile(source, key);
            }

            if (!CollectionUtils.isEmpty(context.getMap())) {
                mustache.execute(sw, context.getMap());
            }

            return IO.copy(new StringReader(sw.toString()), out);

        } catch (FileNotFoundException e) {
            throw new FileNotFoundException(String.format("%s not found.", path));
        } catch (Exception e) {
            throw new ViewException(e.getMessage());
        }
    }
    return 0;
}