Search in sources :

Example 96 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class RegexCopyFilter method initialize.

/**
   * Loads a list of filter patterns for use in shouldCopy.
   */
@Override
public void initialize() {
    BufferedReader reader = null;
    try {
        InputStream is = new FileInputStream(filtersFile);
        reader = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
        String line;
        while ((line = reader.readLine()) != null) {
            Pattern pattern = Pattern.compile(line);
            filters.add(pattern);
        }
    } catch (FileNotFoundException notFound) {
        LOG.error("Can't find filters file " + filtersFile);
    } catch (IOException cantRead) {
        LOG.error("An error occurred while attempting to read from " + filtersFile);
    } finally {
        IOUtils.cleanup(LOG, reader);
    }
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 97 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class StatePool method reloadState.

private boolean reloadState(Path stateFile, Configuration configuration) throws Exception {
    FileSystem fs = stateFile.getFileSystem(configuration);
    try (FSDataInputStream in = fs.open(stateFile)) {
        System.out.println("Reading state from " + stateFile.toString());
        read(in);
        return true;
    } catch (FileNotFoundException e) {
        System.out.println("No state information found for " + stateFile);
        return false;
    }
}
Also used : FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

Example 98 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class TestSwiftFileSystemExtendedContract method testOpenNonExistingFile.

@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testOpenNonExistingFile() throws IOException {
    final Path p = new Path("/test/testOpenNonExistingFile");
    //open it as a file, should get FileNotFoundException
    try {
        final FSDataInputStream in = fs.open(p);
        in.close();
        fail("didn't expect to get here");
    } catch (FileNotFoundException fnfe) {
        LOG.debug("Expected: " + fnfe, fnfe);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileNotFoundException(java.io.FileNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) Test(org.junit.Test)

Example 99 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class TestSwiftFileSystemDirectories method testNoStatusForMissingDirectories.

@Test(timeout = SWIFT_TEST_TIMEOUT)
public void testNoStatusForMissingDirectories() throws Throwable {
    Path missing = path("/test/testNoStatusForMissingDirectories");
    assertPathDoesNotExist("leftover?", missing);
    try {
        FileStatus[] statuses = fs.listStatus(missing);
        //not expected
        fail("Expected a FileNotFoundException, got the status " + statuses);
    } catch (FileNotFoundException expected) {
    //expected
    }
}
Also used : Path(org.apache.hadoop.fs.Path) SwiftFileStatus(org.apache.hadoop.fs.swift.snative.SwiftFileStatus) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 100 with FileNotFoundException

use of java.io.FileNotFoundException in project hadoop by apache.

the class TestProcfsBasedProcessTree method getPidFromPidFile.

/**
   * Get PID from a pid-file.
   * 
   * @param pidFileName
   *          Name of the pid-file.
   * @return the PID string read from the pid-file. Returns null if the
   *         pidFileName points to a non-existing file or if read fails from the
   *         file.
   */
public static String getPidFromPidFile(String pidFileName) {
    BufferedReader pidFile = null;
    FileReader fReader = null;
    String pid = null;
    try {
        fReader = new FileReader(pidFileName);
        pidFile = new BufferedReader(fReader);
    } catch (FileNotFoundException f) {
        LOG.debug("PidFile doesn't exist : " + pidFileName);
        return pid;
    }
    try {
        pid = pidFile.readLine();
    } catch (IOException i) {
        LOG.error("Failed to read from " + pidFileName);
    } finally {
        try {
            if (fReader != null) {
                fReader.close();
            }
            try {
                if (pidFile != null) {
                    pidFile.close();
                }
            } catch (IOException i) {
                LOG.warn("Error closing the stream " + pidFile);
            }
        } catch (IOException i) {
            LOG.warn("Error closing the stream " + fReader);
        }
    }
    return pid;
}
Also used : BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)3218 IOException (java.io.IOException)1836 File (java.io.File)1277 FileInputStream (java.io.FileInputStream)814 FileOutputStream (java.io.FileOutputStream)492 InputStream (java.io.InputStream)466 BufferedReader (java.io.BufferedReader)262 FileReader (java.io.FileReader)230 ArrayList (java.util.ArrayList)205 Path (org.apache.hadoop.fs.Path)202 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)189 InputStreamReader (java.io.InputStreamReader)171 Test (org.junit.Test)171 XmlPullParser (org.xmlpull.v1.XmlPullParser)166 BufferedInputStream (java.io.BufferedInputStream)138 ParcelFileDescriptor (android.os.ParcelFileDescriptor)131 Properties (java.util.Properties)120 URL (java.net.URL)119 FileStatus (org.apache.hadoop.fs.FileStatus)119 RandomAccessFile (java.io.RandomAccessFile)101