use of java.nio.file.attribute.BasicFileAttributes in project logging-log4j2 by apache.
the class DeletingVisitorTest method testVisitFileRelativizesAgainstBase.
@Test
public void testVisitFileRelativizesAgainstBase() throws IOException {
final PathCondition filter = new PathCondition() {
@Override
public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) {
final Path expected = Paths.get("relative");
assertEquals(expected, relativePath);
return true;
}
@Override
public void beforeFileTreeWalk() {
}
};
final Path base = Paths.get("/a/b/c");
final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(filter), false);
final Path child = Paths.get("/a/b/c/relative");
visitor.visitFile(child, null);
}
use of java.nio.file.attribute.BasicFileAttributes in project lucene-solr by apache.
the class CorePropertiesLocator method discover.
@Override
public List<CoreDescriptor> discover(final CoreContainer cc) {
logger.debug("Looking for core definitions underneath {}", rootDirectory);
final List<CoreDescriptor> cds = Lists.newArrayList();
try {
Set<FileVisitOption> options = new HashSet<>();
options.add(FileVisitOption.FOLLOW_LINKS);
final int maxDepth = 256;
Files.walkFileTree(this.rootDirectory, options, maxDepth, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.getFileName().toString().equals(PROPERTIES_FILENAME)) {
CoreDescriptor cd = buildCoreDescriptor(file, cc);
if (cd != null) {
logger.debug("Found core {} in {}", cd.getName(), cd.getInstanceDir());
cds.add(cd);
}
return FileVisitResult.SKIP_SIBLINGS;
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
// otherwise, log a warning and continue to try and load other cores
if (file.equals(rootDirectory)) {
logger.error("Error reading core root directory {}: {}", file, exc);
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error reading core root directory");
}
logger.warn("Error visiting {}: {}", file, exc);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Couldn't walk file tree under " + this.rootDirectory, e);
}
logger.info("Found {} core definitions underneath {}", cds.size(), rootDirectory);
if (cds.size() > 0) {
logger.info("Cores are: {}", cds.stream().map(CoreDescriptor::getName).collect(Collectors.toList()));
}
return cds;
}
use of java.nio.file.attribute.BasicFileAttributes in project lucene-solr by apache.
the class WindowsFS method getKey.
/**
* Returns file "key" (e.g. inode) for the specified path
*/
private Object getKey(Path existing) throws IOException {
BasicFileAttributeView view = Files.getFileAttributeView(existing, BasicFileAttributeView.class);
BasicFileAttributes attributes = view.readAttributes();
return attributes.fileKey();
}
use of java.nio.file.attribute.BasicFileAttributes in project intellij-community by JetBrains.
the class JrtHandler method createEntriesMap.
@NotNull
@Override
protected Map<String, EntryInfo> createEntriesMap() throws IOException {
Map<String, EntryInfo> map = ContainerUtil.newHashMap();
map.put("", createRootEntry());
Path root = getFileSystem().getPath("/modules");
if (!Files.exists(root))
throw new FileNotFoundException("JRT root missing");
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
process(dir, attrs);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
process(file, attrs);
return FileVisitResult.CONTINUE;
}
private void process(Path entry, BasicFileAttributes attrs) throws IOException {
int pathLength = entry.getNameCount();
if (pathLength > 1) {
Path relativePath = entry.subpath(1, pathLength);
String path = relativePath.toString();
if (!map.containsKey(path)) {
EntryInfo parent = map.get(pathLength > 2 ? relativePath.getParent().toString() : "");
if (parent == null)
throw new IOException("Out of order: " + entry);
String shortName = entry.getFileName().toString();
long modified = attrs.lastModifiedTime().toMillis();
map.put(path, new EntryInfo(shortName, attrs.isDirectory(), attrs.size(), modified, parent));
}
}
}
});
return map;
}
use of java.nio.file.attribute.BasicFileAttributes in project wildfly by wildfly.
the class JBeretSubsystemParsingTestCase method testLegacySubsystems.
@Test
public void testLegacySubsystems() throws Exception {
// Get a list of all the logging_x_x.xml files
final Pattern pattern = Pattern.compile("(.*-subsystem)_\\d+_\\d+\\.xml");
// Using the CP as that's the standardSubsystemTest will use to find the config file
final String cp = WildFlySecurityManager.getPropertyPrivileged("java.class.path", ".");
final String[] entries = cp.split(Pattern.quote(File.pathSeparator));
final List<String> configs = new ArrayList<>();
for (String entry : entries) {
final Path path = Paths.get(entry);
if (Files.isDirectory(path)) {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
final String name = file.getFileName().toString();
if (pattern.matcher(name).matches()) {
configs.add("/" + name);
}
return FileVisitResult.CONTINUE;
}
});
}
}
// The paths shouldn't be empty
Assert.assertFalse("No configs were found", configs.isEmpty());
for (String configId : configs) {
// Run the standard subsystem test, but don't compare the XML as it should never match
standardSubsystemTest(configId, false);
}
}
Aggregations