Search in sources :

Example 1 with DirectoryStream

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);
        }
    }
}
Also used : Path(java.nio.file.Path) DirectoryStream(java.nio.file.DirectoryStream)

Example 2 with DirectoryStream

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));
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) DirectoryStream(java.nio.file.DirectoryStream)

Example 3 with DirectoryStream

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);
        }
    }
}
Also used : Path(java.nio.file.Path) DirectoryStream(java.nio.file.DirectoryStream)

Example 4 with DirectoryStream

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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) DirectoryStream(java.nio.file.DirectoryStream) FileInputStream(java.io.FileInputStream) Certificate(java.security.cert.Certificate) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with DirectoryStream

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
    }
}
Also used : Path(java.nio.file.Path) Candidate(org.apache.karaf.shell.api.console.Candidate) DirectoryStream(java.nio.file.DirectoryStream)

Aggregations

DirectoryStream (java.nio.file.DirectoryStream)15 Path (java.nio.file.Path)15 IOException (java.io.IOException)7 List (java.util.List)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Files (java.nio.file.Files)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 FileInputStream (java.io.FileInputStream)2 Paths (java.nio.file.Paths)2 Collections (java.util.Collections)2 Objects (java.util.Objects)2 Properties (java.util.Properties)2 Logger (org.slf4j.Logger)2 Pair (com.facebook.buck.model.Pair)1 DirectoryCleaner (com.facebook.buck.util.DirectoryCleaner)1 DirectoryCleanerArgs (com.facebook.buck.util.DirectoryCleanerArgs)1 Escaper (com.facebook.buck.util.Escaper)1