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.oprisnik.semdroid.config.XmlConfig.java

public XmlConfig(File file) throws BadConfigException, FileNotFoundException {
    try {/*from ww  w.j av a2 s.co  m*/
        if (!file.exists()) {
            throw new FileNotFoundException("File not found " + file);
        }
        mConfiguration = new XMLConfiguration(file);
        // we could also use the XPath engine
        // for example for tables/table[@name='users']/fields/name
        //            mConfiguration.setExpressionEngine(new XPathExpressionEngine());
        mFile = file;
    } catch (ConfigurationException e) {
        throw new BadConfigException(e.getMessage());
    }
}

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

@Override
public File getBasedir() throws FileNotFoundException {
    try {//from   w w w . j a va 2 s  .  co  m
        return loader.getResource(".").getFile();
    } catch (IOException e) {
        throw new FileNotFoundException("Could not access basedirectory");
    }
}

From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.AbstractImporter.java

/**
 * Checks whether the given path exists in the file system.
 * If checkIsDir is set to <code>true</code> the given path have to represent a directory.
 * //from ww  w. j a v a  2s  .c  om
 * @param modelPath the path to the file to check
 * @param checkIsDir check, that the given path have to be a directory. If the check should not be performed,
 *  set to <code>false</code>.
 * @return the {@link File} of the given path.
 * @throws FileNotFoundException if the given path does not exists and if enabled the given path is not a directory.
 */
protected File checkModelPath(String modelPath, boolean checkIsDir) throws FileNotFoundException {
    File rootDir = new File(modelPath);

    if (!rootDir.exists()) {
        throw new FileNotFoundException("given path " + modelPath + " does not exist on file system.");
    }

    if (checkIsDir && !rootDir.isDirectory()) {
        throw new FileNotFoundException("given path " + modelPath + " is not a directory.");
    }

    return rootDir;
}

From source file:io.adeptj.runtime.websocket.ServerLogsTailerListener.java

@Override
public void fileNotFound() {
    this.session.getAsyncRemote().sendText(new FileNotFoundException(this.logFile.toString()).toString());
}

From source file:com.dcsquare.fileauthplugin.utility.properties.FileAuthConfiguration.java

/**
 * Init is responsible for loading all properties of fileAuthConfiguration.properties
 *
 * @param pathname absolute path of the fileAuthConfiguration.properties
 * @throws ConfigurationException thrown if there is any problem with creating the credential file.
 * @throws IOException            is thrown when fileAuthConfiguration.properties is not found.
 *//*w w  w  .  j  av  a 2  s .c o  m*/
public void init(String pathname) throws ConfigurationException, IOException {
    final File configFile = new File(pathname);

    if (!configFile.exists() || !configFile.isFile()) {
        throw new FileNotFoundException("Configuration file not found");
    }
    propertiesConfiguration = new PropertiesConfiguration(configFile);

    credentialFileName = propertiesConfiguration.getString("filename");

    final File credentialFile = new File(configFile.getParent(), credentialFileName);

    if (!credentialFile.exists()) {
        credentialFile.createNewFile();
        LOG.warning("Credential file not found, new one created in " + credentialFile.getAbsolutePath());
    }

    isHashed = propertiesConfiguration.getBoolean("passwordHashing.enabled", true);
    iterations = propertiesConfiguration.getInt("passwordHashing.iterations", 1000000);
    algorithm = propertiesConfiguration.getString("passwordHashing.algorithm", "SHA-512");
    separationChar = propertiesConfiguration.getString("passwordHashingSalt.separationChar", "$");
    isSalted = propertiesConfiguration.getBoolean("passwordHashingSalt.enabled", true);
    isFirst = propertiesConfiguration.getBoolean("passwordHashingSalt.isFirst", true);
}

From source file:com.semperos.screwdriver.js.LessSource.java

/**
 * Constructs a new <code>LessSource</code>.
 * <p>/*w  ww  .ja  v  a 2  s .  co m*/
 * This will read the metadata and content of the LESS source, and will automatically resolve the imports.
 * </p>
 *
 * @param file The <code>File</code> reference to the LESS source to read.
 * @throws FileNotFoundException If the LESS source (or one of its imports) could not be found.
 * @throws IOException If the LESS source cannot be read.
 */
public LessSource(File file) throws FileNotFoundException, IOException {
    if (file == null) {
        throw new IllegalArgumentException("File must not be null.");
    }
    if (!file.exists()) {
        throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found.");
    }
    this.file = file;
    this.content = this.normalizedContent = FileUtils.readFileToString(file);
    resolveImports();
}

From source file:com.asakusafw.runtime.flow.join.JoinResource.java

@Override
public void setup(JobContext context) throws IOException, InterruptedException {
    if (LOG.isDebugEnabled()) {
        LOG.debug(MessageFormat.format("Building join-table from \"{0}\" on distributed cache", //$NON-NLS-1$
                getCacheName()));//w  w  w . ja v a2s.c  o  m
    }
    try (StageResourceDriver driver = new StageResourceDriver(context)) {
        List<Path> paths = driver.findCache(getCacheName());
        if (paths.isEmpty()) {
            throw new FileNotFoundException(
                    MessageFormat.format("Missing resource \"{0}\" in distributed cache", getCacheName()));
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(MessageFormat.format("Building join table \"{0}\" using \"{1}\"", //$NON-NLS-1$
                    getCacheName(), paths));
        }
        try {
            table = createTable(driver, paths);
        } catch (IOException e) {
            throw new IOException(
                    MessageFormat.format("Failed to build a join table from \"{0}\"", getCacheName()), e);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(MessageFormat.format("Built join-table from \"{0}\"", //$NON-NLS-1$
                    getCacheName()));
        }
    }
}

From source file:com.jcalvopinam.core.Unzipping.java

private static void joinAndUnzipFile(File inputFile, CustomFile customFile) throws IOException {

    ZipInputStream is = null;/*from   w w w  . jav  a 2  s.  c o  m*/
    File path = inputFile.getParentFile();

    List<InputStream> fileInputStream = new ArrayList<>();
    for (String fileName : path.list()) {
        if (fileName.startsWith(customFile.getFileName()) && fileName.endsWith(Extensions.ZIP.getExtension())) {
            fileInputStream.add(new FileInputStream(String.format("%s%s", customFile.getPath(), fileName)));
            System.out.println(String.format("File found: %s", fileName));
        }
    }

    if (fileInputStream.size() > 0) {
        String fileNameOutput = String.format("%s%s", customFile.getPath(), customFile.getFileName());
        OutputStream os = new BufferedOutputStream(new FileOutputStream(fileNameOutput));
        try {
            System.out.println("Please wait while the files are joined: ");

            ZipEntry ze;
            for (InputStream inputStream : fileInputStream) {
                is = new ZipInputStream(inputStream);
                ze = is.getNextEntry();
                customFile.setFileName(String.format("%s_%s", REBUILT, ze.getName()));

                byte[] buffer = new byte[CustomFile.BYTE_SIZE];

                for (int readBytes; (readBytes = is.read(buffer, 0, CustomFile.BYTE_SIZE)) > -1;) {
                    os.write(buffer, 0, readBytes);
                    System.out.print(".");
                }
            }
        } finally {
            os.flush();
            os.close();
            is.close();
            renameFinalFile(customFile, fileNameOutput);
        }
    } else {
        throw new FileNotFoundException("Error: The file not exist!");
    }
    System.out.println("\nEnded process!");
}

From source file:net.sf.eclipsecs.core.config.configtypes.ProjectConfigurationType.java

/**
 * {@inheritDoc}//from   w ww. j  a  v  a2s . c  om
 */
protected URL resolveLocation(ICheckConfiguration checkConfiguration) throws IOException {
    IResource configFileResource = ResourcesPlugin.getWorkspace().getRoot()
            .findMember(checkConfiguration.getLocation());

    if (configFileResource != null) {
        return configFileResource.getLocation().toFile().toURI().toURL();
    } else {
        throw new FileNotFoundException(
                NLS.bind(Messages.ProjectConfigurationType_msgFileNotFound, checkConfiguration.getLocation()));
    }
}

From source file:consultor.CSVLoader.java

/**
 * Parse CSV file using OpenCSV library and load in 
 * given database table. /*from  www . ja  va2 s. c o  m*/
 * @param csvFile Input CSV file
 * @param tableName Database table name to import data
 * @param truncateBeforeLoad Truncate the table before inserting 
 *          new records.
 * @throws Exception
 */
public void loadCSV(String csvFile, String tableName, boolean truncateBeforeLoad) throws Exception {

    CSVReader csvReader = null;
    if (null == this.connection) {
        throw new Exception("Not a valid connection.");
    }
    try {

        csvReader = new CSVReader(new FileReader(csvFile), this.seprator);

    } catch (Exception e) {
        e.printStackTrace();
        throw new Exception("Error occured while executing file. " + e.getMessage());
    }

    String[] headerRow = csvReader.readNext();

    if (null == headerRow) {
        throw new FileNotFoundException(
                "No columns defined in given CSV file." + "Please check the CSV file format.");
    }

    String questionmarks = StringUtils.repeat("?,", headerRow.length);
    questionmarks = (String) questionmarks.subSequence(0, questionmarks.length() - 1);

    String query = SQL_INSERT.replaceFirst(TABLE_REGEX, tableName);
    query = query.replaceFirst(KEYS_REGEX, StringUtils.join(headerRow, ","));
    query = query.replaceFirst(VALUES_REGEX, questionmarks);

    System.out.println("Query: " + query);

    String[] nextLine;
    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = this.connection;
        con.setAutoCommit(false);
        ps = con.prepareStatement(query);

        if (truncateBeforeLoad) {
            //delete data from table before loading csv
            con.createStatement().execute("DELETE FROM " + tableName);
        }

        final int batchSize = 1000;
        int count = 0;
        Date date = null;
        while ((nextLine = csvReader.readNext()) != null) {

            if (null != nextLine) {
                int index = 1;
                for (String string : nextLine) {
                    date = DateUtil.convertToDate(string);
                    if (null != date) {
                        ps.setDate(index++, new java.sql.Date(date.getTime()));
                    } else {
                        ps.setString(index++, string);
                    }
                }
                ps.addBatch();
            }
            if (++count % batchSize == 0) {
                ps.executeBatch();
            }
        }
        ps.executeBatch(); // insert remaining records
        con.commit();
    } catch (Exception e) {
        con.rollback();
        e.printStackTrace();
        throw new Exception("Error occured while loading data from file to database." + e.getMessage());
    } finally {
        if (null != ps)
            ps.close();
        if (null != con)
            con.close();

        csvReader.close();
    }
}