use of org.uberfire.java.nio.IOException in project kie-wb-common by kiegroup.
the class VFSRegistryHelperTest method testReadEntriesWithError.
@Test
public void testReadEntriesWithError() throws Exception {
prepareReadEntries();
// make an arbitrary path reading to fail.
int failingIndex = 5;
when(marshaller.unmarshal(entries.get(failingIndex).getContent())).thenThrow(new IOException(ERROR_MESSAGE));
expectedException.expectMessage(ERROR_MESSAGE);
registryHelper.readEntries(rootPath, filter);
for (int i = 0; i < failingIndex; i++) {
verify(registryHelper, times(1));
}
}
use of org.uberfire.java.nio.IOException in project kie-wb-common by kiegroup.
the class FileUtils method scan.
private Collection<ScanResult> scan(IOService ioService, Path rootPath, final Collection<String> fileTypes, final boolean recursiveScan, final Map<Path, Path> scannedCache) throws IOException {
final Collection<ScanResult> results = new ArrayList<ScanResult>();
final List<Path> childDirectories = new ArrayList<Path>();
if (rootPath != null) {
if (Files.isDirectory(rootPath) && !scannedCache.containsKey(rootPath)) {
scannedCache.put(rootPath, rootPath);
final DirectoryStream<Path> foundFiles = ioService.newDirectoryStream(rootPath, new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(final Path entry) throws IOException {
boolean include = false;
if (Files.isDirectory(entry) && recursiveScan) {
// use this check iteration to additionally remember child directories
childDirectories.add(entry);
} else {
if (fileTypes == null) {
include = true;
} else {
include = isFromType(entry, fileTypes);
}
}
return include;
}
});
if (foundFiles != null) {
for (Path acceptedFile : foundFiles) {
results.add(new ScanResult(acceptedFile));
}
}
// finally
if (recursiveScan) {
for (Path child : childDirectories) {
results.addAll(scan(ioService, child, fileTypes, recursiveScan, scannedCache));
}
}
}
}
return results;
}
Aggregations