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:at.uni_salzburg.cs.ckgroup.apos.AposNtripCasterMock.java

/**
 * Initialize the NTRIP mock caster./*from   ww  w  .  jav  a2s. c  o  m*/
 * @throws FileNotFoundException 
 */
private void init(Properties props) throws FileNotFoundException {

    port = Integer.parseInt(props.getProperty(AposNtrip.PROP_PORT));
    String userName = props.getProperty(AposNtrip.PROP_USERNAME);
    String password = props.getProperty(AposNtrip.PROP_PASSWORD);
    String mountPoint = props.getProperty(AposNtrip.PROP_MOUNTPOINT);

    byte[] encodedPassword = (userName + ":" + password).getBytes();
    Base64 encoder = new Base64();
    basicAuthentication = encoder.encode(encodedPassword);

    expectedRequest = "GET /" + mountPoint + " HTTP/1.0";
    expectedUserAgent = "User-Agent: .*";
    expectedAuthorisation = "Authorization: Basic " + (new String(basicAuthentication));
    expectedLocation = props.getProperty(PROP_EXPECTED_LOCATION);

    System.out.println("AposNtripCasterMock: expectedRequest=" + expectedRequest);
    System.out.println("AposNtripCasterMock: expectedUserAgent=" + expectedUserAgent);
    System.out.println("AposNtripCasterMock: expectedAuthorisation=" + expectedAuthorisation);

    String fileName = props.getProperty(PROP_INPUT_DATA_FILE);
    URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);

    if (url == null)
        throw new FileNotFoundException(fileName);

    inputDataFile = new File(url.getFile());
}

From source file:com.netspective.commons.io.UriAddressableUniqueFileLocator.java

/**
 * Creates a new file resource locator that will use the specified directory
 * as the base directory for loading templates.
 *
 * @param baseDir the base directory for loading templates
 *///  w ww .ja v a  2  s  .  co m
public UriAddressableUniqueFileLocator(final String rootUrl, final File baseDir, final boolean cacheLocations)
        throws IOException {
    this.rootUrl = rootUrl;
    this.cacheLocations = cacheLocations;
    try {
        Object[] retval = (Object[]) AccessController.doPrivileged(new PrivilegedExceptionAction() {
            public Object run() throws IOException {
                if (!baseDir.exists()) {
                    throw new FileNotFoundException(baseDir + " does not exist.");
                }
                if (!baseDir.isDirectory()) {
                    throw new IOException(baseDir + " is not a directory.");
                }
                Object[] retval = new Object[2];
                retval[0] = baseDir.getCanonicalFile();
                retval[1] = ((File) retval[0]).getPath() + File.separatorChar;
                return retval;
            }
        });
        this.baseDir = (File) retval[0];
        this.canonicalPath = (String) retval[1];
    } catch (PrivilegedActionException e) {
        throw (IOException) e.getException();
    }
}

From source file:AIR.ResourceBundler.Console.ResourcesBuilder.java

private void writeFileInput(FileWriter sw, FileSetInput fileInput) throws IOException {
    FileSet fileSet = fileInput.getParent();

    if (StringUtils.isEmpty(fileInput.getPath())) {
        throw new FileNotFoundException("No file path defined for the input " + fileSet.getName());
    }//from   w w  w . j a  v  a 2s .c  o  m

    // get file info
    String filePath = Path.combine(_parentFolder, fileInput.getPath());
    filePath = filePath.replace('/', File.separatorChar);
    String fileName = Path.getFileName(fileInput.getPath());

    if (StringUtils.isEmpty(fileName)) {
        throw new IOException(String.format("Could not find the file name in the path \"%s\".", filePath));
    }

    // write out file header
    writeFileHeader(sw, filePath);
    writePrepend(sw, fileInput);

    // read input file
    try (BufferedReader sr = new BufferedReader(new FileReader(filePath))) {

        boolean compressed = false;

        // check if we can compress this resource group
        if (fileSet.isCompress()) {
            String fileExt = Path.getExtension(fileName).toLowerCase();

            // check if this file supports compression
            if ("js".equals(fileExt)) {
                compressJS(sw, sr, fileSet);
                compressed = true;
            }
        }

        // if no compression was performed then add the file as is
        if (!compressed) {
            String line;

            while ((line = sr.readLine()) != null) {
                sw.write(line + "\n");
            }
        }

        writeAppend(sw, fileInput);
        sw.write("\n");
    }
}

From source file:org.xmlactions.common.io.ResourceUtils.java

public static byte[] loadBinaryFile(String fileName) throws IOException {

    byte buffer[] = null;
    InputStream inputStream;//from ww  w.  j a  v  a  2  s.co  m
    if (new File(fileName).exists() == true) {
        inputStream = new FileInputStream(fileName);
    } else {
        // see if we can get it as a resource
        inputStream = ResourceUtils.getResourceURL(fileName).openStream();
    }
    if (inputStream != null) {
        try {
            buffer = readInputStream(inputStream);
        } finally {
            inputStream.close();
        }
    } else {

        throw new FileNotFoundException("File '" + fileName + "' does not exist");

    }
    return (buffer);
}

From source file:com.moss.posixfifosockets.PosixFifoSocket.java

public static void createFifo(File path) throws IOException {
    if (path.exists()) {
        throw new IOException("File already exists: " + path.getAbsolutePath());
    }//from w  w w.j  ava  2  s  .  c  o m
    if (!path.getParentFile().exists()) {
        throw new FileNotFoundException(path.getParent());
    }
    try {
        if (path.exists()) {
            throw new RuntimeException("Path really does exist: " + path.getAbsolutePath());
        }

        final Process p = Runtime.getRuntime().exec("mkfifo " + path.getAbsolutePath());
        int result = p.waitFor();
        if (result != 0) {

            String stdOut = read(p.getInputStream());
            String stdErr = read(p.getErrorStream());
            throw new IOException("Error creating fifo at " + path.getAbsolutePath() + ": Received error code "
                    + result + ", STDOUT: " + stdOut + ", STDERR: " + stdErr);
        } else if (!path.exists()) {
            throw new RuntimeException("mkfifo didn't do its job: " + path.getAbsolutePath());
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.exzogeni.dk.http.cache.DiscCacheStore.java

@NonNull
@Override//w  w w  .j  a  va  2 s  .  c om
public InputStream update(@NonNull URI uri, @NonNull Map<String, List<String>> headers, long maxAge)
        throws IOException {
    final File cacheFile = new File(mCacheDir, Digest.getInstance().hash(uri.toString()));
    final File metaFile = new File(mCacheDir, "." + cacheFile.getName());
    if (cacheFile.exists() && metaFile.exists()) {
        saveMetaFile(metaFile, getMetaHeaders(headers), maxAge);
        return new AtomicFile(cacheFile).openRead();
    }
    throw new FileNotFoundException(cacheFile.getAbsolutePath());
}

From source file:com.yahoo.ycsb.bulk.hbase.RangePartitioner.java

private synchronized Text[] getCutPoints() throws IOException {
    if (cutPointArray == null) {
        String cutFileName = conf.get(CUTFILE_KEY);
        Path[] cf = DistributedCache.getLocalCacheFiles(conf);

        if (cf != null) {
            for (Path path : cf) {
                if (path.toUri().getPath().endsWith(cutFileName.substring(cutFileName.lastIndexOf('/')))) {
                    TreeSet<Text> cutPoints = new TreeSet<Text>();
                    Scanner in = new Scanner(new BufferedReader(new FileReader(path.toString())));
                    try {
                        while (in.hasNextLine())
                            cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes())));
                    } finally {
                        in.close();//from  ww w.ja va 2 s.co m
                    }
                    cutPointArray = cutPoints.toArray(new Text[cutPoints.size()]);
                    break;
                }
            }
        }
        if (cutPointArray == null)
            throw new FileNotFoundException(cutFileName + " not found in distributed cache");
    }
    return cutPointArray;
}

From source file:com.pactera.edg.am.metamanager.extractor.adapter.extract.db.impl.DbFromFileExtractServiceImpl.java

private Catalog getCatalog(String filePath) throws FileNotFoundException {
    File file = new File(filePath);
    if (!file.exists()) {
        throw new FileNotFoundException("?DB??:" + filePath);
    }//from  w w w .  j  av  a  2 s .  c o  m
    return getCatalog(new FileInputStream(file));
}

From source file:com.jeeframework.util.classes.ResourceUtils.java

/**
 * Resolve the given resource location to a <code>java.net.URL</code>.
 * <p>Does not check whether the URL actually exists; simply returns
 * the URL that the given location would correspond to.
 * @param resourceLocation the resource location to resolve: either a
 * "classpath:" pseudo URL, a "file:" URL, or a plain file path
 * @return a corresponding URL object/*from w w  w.  j  av  a2  s .  c om*/
 * @throws FileNotFoundException if the resource cannot be resolved to a URL
 */
public static URL getURL(String resourceLocation) throws FileNotFoundException {
    Assert.notNull(resourceLocation, "Resource location must not be null");
    if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) {
        String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length());
        URL url = ClassUtils.getDefaultClassLoader().getResource(path);
        if (url == null) {
            String description = "class path resource [" + path + "]";
            throw new FileNotFoundException(
                    description + " cannot be resolved to URL because it does not exist");
        }
        return url;
    }
    try {
        // try URL
        return new URL(resourceLocation);
    } catch (MalformedURLException ex) {
        // no URL -> treat as file path
        try {
            return new File(resourceLocation).toURI().toURL();
        } catch (MalformedURLException ex2) {
            throw new FileNotFoundException("Resource location [" + resourceLocation
                    + "] is neither a URL not a well-formed file path");
        }
    }
}