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);
}
}
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;
}
}
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);
}
}
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
}
}
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;
}
Aggregations