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:org.jboss.windup.WindupMetaEngine.java

/**
 * <p>// w  w  w . j  a v  a 2s. c  o m
 * Gets the meta information for a single given file.
 * </p>
 * 
 * @param file
 *            {@link File} to get meta information for
 * 
 * @return {@link FileMeta} for the given {@link File}
 * 
 * @throws IOException
 *             this can happen when doing file operations
 */
public FileMeta getFileMeta(File file) throws IOException {
    FileMeta meta = null;

    if (!settings.isSource()) {
        throw new RuntimeException("Windup Engine must be set to source mode to process single files.");
    }

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

    if (!file.isFile()) {
        throw new FileNotFoundException("Given path does not reference a file: " + file);
    }

    meta = fileInterrogationEngine.process(file);

    return meta;
}

From source file:jetbrick.template.JetEngineFactoryBean.java

private void check(File file) throws Exception {
    // ??/*  w  ww  . j a  v  a  2s  .co  m*/
    if (file.exists() && file.isDirectory()) {
        String msg = "config file exists but it is a directory.";
        throw new FileNotFoundException(msg);
    }
}

From source file:org.openxdata.test.BaseContextSensitiveTest.java

private static URL getInitalDatasetURL() throws FileNotFoundException {
    URL file = ClassLoader.getSystemResource(INITIAL_XML_DATASET_LOCATION);
    if (file == null) {
        throw new FileNotFoundException(
                "Unable to find '" + INITIAL_XML_DATASET_LOCATION + "' in the classpath");
    }//  w  w  w .j  ava2  s . c  om
    return file;
}

From source file:com.microsoft.azure.management.datalake.store.uploader.DataLakeStoreUploader.java

/**
 * Validates the parameters.//  ww  w  . j ava 2  s . co m
 *
 * @throws FileNotFoundException Could not find input file
 * @throws IllegalArgumentException Null or empty account name, stream path should not end with a '/' or the thread count is out of range.
 */
private void validateParameters() throws FileNotFoundException, IllegalArgumentException {
    if (!(new File(this.getParameters().getInputFilePath()).exists())) {
        throw new FileNotFoundException(
                "Could not find input file: " + this.getParameters().getInputFilePath());
    }

    if (this.getParameters().getTargetStreamPath() == null
            || StringUtils.isEmpty(this.getParameters().getTargetStreamPath())) {
        throw new IllegalArgumentException("Null or empty Target Stream path");
    }

    if (this.getParameters().getTargetStreamPath().endsWith("/")) {
        throw new IllegalArgumentException("Invalid TargetStreamPath, a stream path should not end with /");
    }

    if (this.getParameters().getAccountName() == null
            || StringUtils.isEmpty(this.getParameters().getAccountName())) {
        throw new IllegalArgumentException("Null or empty Account Name");
    }

    if (this.getParameters().getThreadCount() < 1
            || this.getParameters().getThreadCount() > MAX_ALLOWED_THREADS) {
        throw new IllegalArgumentException(
                MessageFormat.format("ThreadCount must be at least 1 and at most {0}", MAX_ALLOWED_THREADS));
    }
}

From source file:com.ms.commons.test.common.FileUtil.java

public static void copyDirectory(File srcDir, File destDir, boolean preserveFileDate, FileFilter filter)
        throws IOException {
    if (srcDir == null) {
        throw new NullPointerException("Source must not be null");
    }//from w ww  .ja va2  s  . c  o m
    if (destDir == null) {
        throw new NullPointerException("Destination must not be null");
    }
    if (srcDir.exists() == false) {
        throw new FileNotFoundException("Source '" + srcDir + "' does not exist");
    }
    if (srcDir.isDirectory() == false) {
        throw new IOException("Source '" + srcDir + "' exists but is not a directory");
    }
    if (srcDir.getCanonicalPath().equals(destDir.getCanonicalPath())) {
        throw new IOException("Source '" + srcDir + "' and destination '" + destDir + "' are the same");
    }
    doCopyDirectory(srcDir, destDir, preserveFileDate, filter);
}

From source file:com.ca.dvs.app.dvs_servlet.misc.FileUtil.java

/**
 * Given a folder, return the main RAML file
 * <p>/*from  w  w  w  .ja  va  2  s.  co  m*/
 * @param folder the folder containing a multi-part RAML
 * @param targetName the desired RAML file to find in the folder
 * @return the targetName file if found, or the first RAML file found
 * @throws FileNotFoundException if no RAML files are found in the folder
 */
public static File selectRamlFile(File folder, String targetName) throws FileNotFoundException {

    File selectedFile = null;

    File[] ramlFiles = RamlUtil.getRamlFiles(folder);

    if (null != ramlFiles && ramlFiles.length > 0) {

        for (File f : ramlFiles) {
            if (f.getName().equalsIgnoreCase(targetName) && f.canRead()) {
                selectedFile = f;
                break;
            }
        }

        // If none of the raml files match the base name of the uploaded file, use the first one found
        if (null == selectedFile) {
            selectedFile = ramlFiles[0];
        }
    } else {

        String msg = String.format("No RAML files found in folder - %s", folder.getAbsolutePath());
        log.error(msg);
        throw new FileNotFoundException(msg);
    }

    return selectedFile;
}

From source file:com.microsoft.azure.management.datalake.store.uploader.SingleSegmentUploader.java

/**
 * Uploads the portion of the InputFilePath to the given TargetStreamPath, starting at the given StartOffset.
 * The segment is further divided into equally-sized blocks which are uploaded in sequence.
 * Each such block is attempted a certain number of times; if after that it still cannot be uploaded, the entire segment is aborted (in which case no cleanup is performed on the server).
 *
 * @throws Exception if there is any failure during the upload
 *//*from   ww  w  .j  a  v  a 2 s .c o  m*/
public void upload() throws Exception {
    File fileInfo = new File(metadata.getInputFilePath());
    if (!(fileInfo.exists())) {
        throw new FileNotFoundException("Unable to locate input file: " + metadata.getInputFilePath());
    }

    //open up a reader from the input file, seek to the appropriate offset
    try (RandomAccessFile inputStream = openInputStream()) {
        long endPosition = segmentMetadata.getOffset() + segmentMetadata.getLength();
        if (endPosition > fileInfo.length()) {
            throw new IllegalArgumentException("StartOffset+UploadLength is beyond the end of the input file");
        }

        uploadSegmentContents(inputStream, endPosition);

        verifyUploadedStream();
        //any exceptions are (re)thrown to be handled by the caller; we do not handle retries or other recovery techniques here
    }
}

From source file:com.sshtools.daemon.vfs.VirtualFileSystem.java

private static String getNFSHomeDirectory() throws FileNotFoundException {
    try {/*ww w  . ja va  2s.  c o  m*/

        if (Thread.currentThread() instanceof SshThread && SshThread.hasUserContext()) {
            NativeAuthenticationProvider nap = NativeAuthenticationProvider.getInstance();

            return nap.getHomeDirectory(SshThread.getCurrentThreadUser());
        } else {
            throw new FileNotFoundException("There is no user logged in");
        }
    } catch (IOException e) {
        throw new FileNotFoundException(e.getMessage());
    }

}

From source file:edu.cmu.tetrad.cli.util.Args.java

public static Path getPathDir(String dir, boolean required) throws FileNotFoundException {
    Path path = Paths.get(dir);

    if (Files.exists(path)) {
        if (!Files.isDirectory(path)) {
            throw new FileNotFoundException(String.format("'%s' is not a directory.\n", dir));
        }//from   www . j a  va2  s  .  c om
    } else {
        if (required) {
            throw new FileNotFoundException(String.format("Directory '%s' does not exist.\n", dir));
        }
    }

    return path;
}

From source file:com.twosigma.beaker.mimetype.MIMEContainer.java

protected static byte[] getBytes(Object data) throws IOException {
    byte[] bytes;
    if (isValidURL(data.toString())) {
        bytes = ByteStreams.toByteArray((new URL(data.toString()).openStream()));
    } else if (exists(data.toString())) {
        File imgFile = new File(data.toString());
        bytes = Files.toByteArray(imgFile);
    } else {//w  w  w. java  2 s .com
        throw new FileNotFoundException(data.toString() + " doesn't exist. ");
    }
    return bytes;
}