use of java.nio.file.DirectoryStream in project zxing by zxing.
the class HtmlAssetTranslator method translateOneLanguage.
private static void translateOneLanguage(Path assetsDir, String language, final Collection<String> filesToTranslate) throws IOException {
Path targetHtmlDir = assetsDir.resolve("html-" + language);
Files.createDirectories(targetHtmlDir);
Path englishHtmlDir = assetsDir.resolve("html-en");
String translationTextTranslated = StringsResourceTranslator.translateString("Translated by Google Translate.", language);
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) {
String name = entry.getFileName().toString();
return name.endsWith(".html") && (filesToTranslate.isEmpty() || filesToTranslate.contains(name));
}
};
try (DirectoryStream<Path> files = Files.newDirectoryStream(englishHtmlDir, filter)) {
for (Path sourceFile : files) {
translateOneFile(language, targetHtmlDir, sourceFile, translationTextTranslated);
}
}
}
use of java.nio.file.DirectoryStream in project zxing by zxing.
the class HtmlAssetTranslator method parseLanguagesToTranslate.
private static Collection<String> parseLanguagesToTranslate(Path assetsDir, CharSequence languageArg) throws IOException {
if ("all".equals(languageArg)) {
Collection<String> languages = new ArrayList<>();
DirectoryStream.Filter<Path> fileFilter = new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) {
String fileName = entry.getFileName().toString();
return Files.isDirectory(entry) && !Files.isSymbolicLink(entry) && fileName.startsWith("html-") && !"html-en".equals(fileName);
}
};
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(assetsDir, fileFilter)) {
for (Path languageDir : dirs) {
languages.add(languageDir.getFileName().toString().substring(5));
}
}
return languages;
} else {
return Arrays.asList(COMMA.split(languageArg));
}
}
use of java.nio.file.DirectoryStream in project zxing by zxing.
the class StringsResourceTranslator method main.
public static void main(String[] args) throws IOException {
Path resDir = Paths.get(args[0]);
Path valueDir = resDir.resolve("values");
Path stringsFile = valueDir.resolve("strings.xml");
Collection<String> forceRetranslation = Arrays.asList(args).subList(1, args.length);
DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) {
return Files.isDirectory(entry) && !Files.isSymbolicLink(entry) && VALUES_DIR_PATTERN.matcher(entry.getFileName().toString()).matches();
}
};
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(resDir, filter)) {
for (Path dir : dirs) {
translate(stringsFile, dir.resolve("strings.xml"), forceRetranslation);
}
}
}
use of java.nio.file.DirectoryStream in project graylog2-server by Graylog2.
the class KeyUtil method loadCertificates.
@VisibleForTesting
protected static void loadCertificates(KeyStore trustStore, File certFile, CertificateFactory cf) throws CertificateException, KeyStoreException, IOException {
if (certFile.isFile()) {
try (FileInputStream fis = new FileInputStream(certFile)) {
final Collection<? extends Certificate> certificates = cf.generateCertificates(fis);
int i = 0;
for (Certificate cert : certificates) {
final String alias = certFile.getAbsolutePath() + "_" + i;
trustStore.setCertificateEntry(alias, cert);
i++;
LOG.debug("Added certificate with alias {} to trust store: {}", alias, cert);
}
}
} else if (certFile.isDirectory()) {
try (DirectoryStream<Path> ds = Files.newDirectoryStream(certFile.toPath())) {
for (Path f : ds) {
loadCertificates(trustStore, f.toFile(), cf);
}
}
}
}
use of java.nio.file.DirectoryStream in project karaf by apache.
the class UriCompleter method maven.
private void maven(Session session, CommandLine commandLine, List<Candidate> candidates) {
String repo = System.getProperty("user.home") + "/.m2/repository";
String buffer = commandLine.getCursorArgument();
String mvn = buffer.substring("mvn:".length(), commandLine.getArgumentPosition());
String rem = "";
try {
String[] parts = mvn.split("/");
if (parts.length == 0 || parts.length == 1 && !mvn.endsWith("/")) {
String known = "";
String group = "";
String[] dirs = parts.length > 0 ? parts[0].split("\\.") : new String[] { "" };
if (parts.length > 0 && parts[0].endsWith(".")) {
for (String dir : dirs) {
known += dir + "/";
group += dir + ".";
}
} else {
for (int i = 0; i < dirs.length - 1; i++) {
known += dirs[i] + "/";
group += dirs[i] + ".";
}
rem = dirs[dirs.length - 1];
}
Path rep = Paths.get(repo);
Path dir = rep.resolve(known);
try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
for (Path path : paths) {
if (Files.isDirectory(path)) {
String name = path.getFileName().toString();
candidates.add(new Candidate("mvn:" + group + name, false));
}
}
}
rem = group + rem;
} else if (parts.length == 1 || parts.length == 2 && !mvn.endsWith("/")) {
rem = parts.length > 1 ? parts[1] : "";
Path dir = Paths.get(repo + "/" + parts[0].replace(".", "/"));
try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
for (Path path : paths) {
if (Files.isDirectory(path)) {
String name = path.getFileName().toString();
candidates.add(new Candidate("mvn:" + parts[0] + "/" + name, false));
}
}
}
} else if (parts.length == 2 || parts.length == 3 && !mvn.endsWith("/")) {
rem = parts.length > 2 ? parts[2] : "";
Path dir = Paths.get(repo + "/" + parts[0].replace(".", "/") + "/" + parts[1]);
try (DirectoryStream<Path> paths = Files.newDirectoryStream(dir, rem + "*")) {
for (Path path : paths) {
if (Files.isDirectory(path)) {
String name = path.getFileName().toString();
candidates.add(new Candidate("mvn:" + parts[0] + "/" + parts[1] + "/" + name, true));
}
}
}
}
} catch (Exception e) {
// Ignore
}
}
Aggregations