public void updateDirectory() throws IOException { List<Path> contents = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(directory, "*.info")) { stream.forEach(contents::add); } files.keySet().retainAll(contents); contents.removeAll(files.keySet()); contents.forEach(p -> files.put(p, new IGTFInfoFile(p))); taStatus.clear(); taPolicies.clear(); files.values().stream() .map(IGTFInfoFile::get) .flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty()) .forEach(this::addPrincipals); }
public Optional<IGTFInfo> get() { if (System.currentTimeMillis() - lastChecked > CHECK_THRESHOLD) { lastChecked = System.currentTimeMillis(); policy = null; try { FileTime fileLastModified = Files.getLastModifiedTime(file); if (lastModified == null || fileLastModified.compareTo(lastModified) > 0) { policy = read(file, type); lastModified = fileLastModified; } } catch (IOException | ParserException e) { LOG.warn("{}: {}", file.getFileName(), e.getMessage()); } } return Optional.ofNullable(policy); }
private static Collection<LogicalLine> readLines(Path path) throws IOException { List<LogicalLine> lines = new ArrayList<>(); StringBuilder sb = null; int lineIndex = 0; int startOfLine = -1; for (String line : Files.readAllLines(path)) { lineIndex++; if (line.endsWith("\\")) { if (sb == null) { sb = new StringBuilder(); startOfLine = lineIndex; } sb.append(line.substring(0, line.length()-1)); } else { String logicalLine = trim(sb == null ? line : sb.append(line).toString()); if (!logicalLine.isEmpty()) { lines.add(new LogicalLine(logicalLine, sb == null ? lineIndex : startOfLine)); } sb = null; } } if (sb != null) { String logicalLine = trim(sb.toString()); if (!logicalLine.isEmpty()) { lines.add(new LogicalLine(logicalLine, startOfLine)); } } return lines; }
builder.setFilename(path.getFileName().toString()); for (LogicalLine line : readLines(path)) { try { List<String> items = Splitter.on('=').limit(2).trimResults().splitToList(line.getValue());