return name.endsWith(extension);
}
});
if (files == null) {
throw new PersistenceException(String.format(
"Configured %s directory (%s) does not appear to be readable!", dirType, dir));
}
/*
* If file list isn't empty, try opening the first file in the list to make sure it
* is readable. If the first file is readable, then it is likely that the rest will
* be readable as well.
*/
if (files.length > 0) {
try {
FileInputStream file = new FileInputStream(files[0]);
file.read();
} catch (IOException e) {
throw new PersistenceException(
String.format(
"Failed to read '%s' in configured %s directory '%s'. "
+ "The directory's contents do not appear to be readable.",
dirType, files[0].getName(), dir),
e);
}
}
// Make sure the dir is writable.
try {
File tmp = File.createTempFile("tempInitialization", ".temp", baseDir);
FileOutputStream stream = new FileOutputStream(tmp);
stream.write(new byte[]{'H','e','l','l','o'});
stream.close();
tmp.delete();
} catch (IOException e) {
throw new PersistenceException(String.format(
"Configured %s directory (%s) does not appear to be writable!", dirType, dir), e);
}
}