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.jeeframework.util.xml.XMLProperties.java

/**
 * Creates a new XMLPropertiesTest object.
 *
 * @param fileName the full path the file that properties should be read from
 *                 and written to./*  www .j a v  a2s  .  c om*/
 * @throws IOException if an error occurs loading the properties.
 */
public XMLProperties(String fileName) throws IOException {
    Assert.notNull(fileName, "fileName  must not be null");
    ClassLoader clToUse = ClassUtils.getDefaultClassLoader();
    URL url = clToUse.getResource(fileName);
    if (url == null) {
        throw new FileNotFoundException(fileName + "  not found  ");
    }
    InputStream is = null;
    try {
        URLConnection con = url.openConnection();
        con.setUseCaches(false);
        is = con.getInputStream();
        Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        buildDoc(reader);
    } finally {
        if (is != null) {
            is.close();
        }
    }

}

From source file:$.MessageLogParser.java

/**
     * Gets lines from the log file which corresponds with specified correlation ID.
     */*  w  w  w. j  a v  a 2 s .c  o m*/
     * @param correlationId the correlation ID
     * @param logDate which date to search log files for
     * @return log lines
     * @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:com.openkm.util.impexp.RepositoryImporter.java

/**
 * Import documents from filesystem into document repository.
 *///w w  w  . ja  v a  2s.  c  om
public static ImpExpStats importDocuments(String token, File fs, String fldPath, boolean metadata,
        boolean history, boolean uuid, Writer out, InfoDecorator deco)
        throws PathNotFoundException, ItemExistsException, AccessDeniedException, RepositoryException,
        FileNotFoundException, IOException, DatabaseException, ExtensionException, AutomationException {
    log.debug("importDocuments({}, {}, {}, {}, {}, {}, {}, {})",
            new Object[] { token, fs, fldPath, metadata, history, uuid, out, deco });
    ImpExpStats stats;

    try {
        FileLogger.info(BASE_NAME, "Start repository import from ''{0}'' to ''{1}''", fs.getPath(), fldPath);

        if (fs.exists()) {
            stats = importDocumentsHelper(token, fs, fldPath, metadata, history, uuid, out, deco);
        } else {
            throw new FileNotFoundException(fs.getPath());
        }

        FileLogger.info(BASE_NAME, "Repository import finalized");
    } catch (PathNotFoundException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "PathNotFoundException ''{0}''", e.getMessage());
        throw e;
    } catch (AccessDeniedException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "AccessDeniedException ''{0}''", e.getMessage());
        throw e;
    } catch (FileNotFoundException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "FileNotFoundException ''{0}''", e.getMessage());
        throw e;
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "RepositoryException ''{0}''", e.getMessage());
        throw e;
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "IOException ''{0}''", e.getMessage());
        throw e;
    } catch (DatabaseException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "DatabaseException ''{0}''", e.getMessage());
        throw e;
    }

    log.debug("importDocuments: {}", stats);
    return stats;
}

From source file:io.apiman.gateway.platforms.vertx3.components.ldap.LdapTestParent.java

public static void injectLdifFiles(String... ldifFiles) throws Exception {
    if (ldifFiles != null && ldifFiles.length > 0) {
        for (String ldifFile : ldifFiles) {
            InputStream is = null;
            try {
                is = LdapTestParent.class.getClassLoader().getResourceAsStream(ldifFile);
                if (is == null) {
                    throw new FileNotFoundException("LDIF file '" + ldifFile + "' not found.");
                } else {
                    try {
                        LdifReader ldifReader = new LdifReader(is);
                        for (LdifEntry entry : ldifReader) {
                            injectEntry(entry);
                        }//  w ww  .  ja  v  a2  s . c  o  m
                        ldifReader.close();
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
    }
}

From source file:com.ikon.util.impexp.RepositoryImporter.java

/**
 * Import documents from filesystem into document repository.
 *//*from w  w  w .ja va2  s  .c  om*/
public static ImpExpStats importDocuments(String token, File fs, String fldPath, String metadata,
        boolean history, boolean uuid, Writer out, InfoDecorator deco)
        throws PathNotFoundException, ItemExistsException, AccessDeniedException, RepositoryException,
        FileNotFoundException, IOException, DatabaseException, ExtensionException, AutomationException {
    log.debug("importDocuments({}, {}, {}, {}, {}, {}, {}, {})",
            new Object[] { token, fs, fldPath, metadata, history, uuid, out, deco });
    ImpExpStats stats;

    try {
        FileLogger.info(BASE_NAME, "Start repository import from ''{0}'' to ''{1}''", fs.getPath(), fldPath);

        if (fs.exists()) {
            stats = importDocumentsHelper(token, fs, fldPath, metadata, history, uuid, out, deco);
        } else {
            throw new FileNotFoundException(fs.getPath());
        }

        FileLogger.info(BASE_NAME, "Repository import finalized");
    } catch (PathNotFoundException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "PathNotFoundException ''{0}''", e.getMessage());
        throw e;
    } catch (AccessDeniedException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "AccessDeniedException ''{0}''", e.getMessage());
        throw e;
    } catch (FileNotFoundException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "FileNotFoundException ''{0}''", e.getMessage());
        throw e;
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "RepositoryException ''{0}''", e.getMessage());
        throw e;
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "IOException ''{0}''", e.getMessage());
        throw e;
    } catch (DatabaseException e) {
        log.error(e.getMessage(), e);
        FileLogger.error(BASE_NAME, "DatabaseException ''{0}''", e.getMessage());
        throw e;
    }

    log.debug("importDocuments: {}", stats);
    return stats;
}

From source file:eu.planets_project.tb.impl.services.ServiceRegistryManager.java

/**
 * Takes a given http URI and extracts the page's content which is returned as String
 * @param uri//from  w w  w.  ja v a  2s  .  c  om
 * @return
 * @throws FileNotFoundException
 * @throws IOException
 */
@Deprecated
private static String readUrlContents(URI uri) throws FileNotFoundException, IOException {

    InputStream in = null;
    try {
        if (!uri.getScheme().equals("http")) {
            throw new FileNotFoundException("URI schema " + uri.getScheme() + " not supported");
        }
        in = uri.toURL().openStream();
        boolean eof = false;
        String content = "";
        StringBuffer sb = new StringBuffer();
        while (!eof) {
            int byteValue = in.read();
            if (byteValue != -1) {
                char b = (char) byteValue;
                sb.append(b);
            } else {
                eof = true;
            }
        }
        content = sb.toString();
        if (content != null) {
            //now return the services WSDL content
            return content;
        } else {
            throw new FileNotFoundException("extracted content is null");
        }
    } finally {
        in.close();
    }
}

From source file:libepg.ts.reader.Reader2.java

/**
 * ?TS?????/*from   w w w .j a v  a2  s  .c o  m*/
 * ?1??????????1??????
 *
 * @author normal
 * @param TSFile ?
 * @param readLimit ??<br>
 * ????????????????<br>
 * @throws java.io.FileNotFoundException ??????????
 */
public Reader2(File TSFile, Long readLimit) throws FileNotFoundException {
    this.TSFile = new File(TSFile.getAbsolutePath());
    if (this.TSFile.isFile() == false) {
        throw new FileNotFoundException("TS?????");
    }
    this.readLimit = readLimit;
    if (this.readLimit != null) {
        if (this.readLimit < 0) {
            throw new IllegalArgumentException("????0??");
        }
        LOG.info("???" + this.readLimit
                + "???????");
    } else {
        LOG.info("??????????");
    }
}

From source file:com.opengamma.integration.server.copier.ServerDatabaseCreator.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);
        }//  w  w w. ja  va  2s  .  co  m
        props.load(in);
    }

    // create main database
    s_logger.info("Creating main database...");
    DbTool dbTool = new DbTool();
    dbTool.setJdbcUrl(Objects.requireNonNull(props.getProperty(KEY_SHARED_URL)));
    dbTool.setUser(props.getProperty(KEY_SHARED_USER_NAME, ""));
    dbTool.setPassword(props.getProperty(KEY_SHARED_PASSWORD, ""));
    dbTool.setCatalog(CATALOG); // ignored, as it is parsed from the url
    dbTool.setCreate(true);
    dbTool.setDrop(true);
    dbTool.setCreateTables(true);
    dbTool.execute();

    // create user database
    s_logger.info("Creating user database...");
    DbTool dbToolUser = new DbTool();
    dbToolUser.setJdbcUrl(Objects.requireNonNull(props.getProperty(KEY_USERFINANCIAL_URL)));
    dbToolUser.setUser(props.getProperty(KEY_USERFINANCIAL_USER_NAME, ""));
    dbToolUser.setPassword(props.getProperty(KEY_USERFINANCIAL_PASSWORD, ""));
    dbToolUser.setCatalog(CATALOG); // ignored, as it is parsed from the url
    dbToolUser.setCreate(true);
    dbToolUser.setDrop(true);
    dbToolUser.setCreateTables(true);
    dbToolUser.execute();

    // populate the database
    s_logger.info("Populating main database...");
    ServerDatabasePopulator populator = new ServerDatabasePopulator(_configFile,
            new DatabasePopulatorTool(_serverUrl));
    populator.run();
    s_logger.info("Successfully created server databases");
}

From source file:com.conwet.silbops.TestEnvironment.java

public File findWar(String filename) throws FileNotFoundException {

    FileFilter warFile = new WildcardFileFilter(filename);
    File dir = new File("target/lib/");
    File[] files = dir.listFiles(warFile);

    if (files.length == 0) {

        throw new FileNotFoundException("Unable to find file " + filename + " in " + dir.getAbsolutePath());
    }//from www.java2 s.c  o m

    return files[0];
}

From source file:hudson.util.CompressedFile.java

/**
 * Reads the contents of a file./*from w w  w. j  a v  a  2  s.co m*/
 */
public InputStream read() throws IOException {
    if (file.exists())
        try {
            return Files.newInputStream(file.toPath());
        } catch (InvalidPathException e) {
            throw new IOException(e);
        }

    // check if the compressed file exists
    if (gz.exists())
        try {
            return new GZIPInputStream(Files.newInputStream(gz.toPath()));
        } catch (InvalidPathException e) {
            throw new IOException(e);
        }

    // no such file
    throw new FileNotFoundException(file.getName());
}