static void resolveConfig(Environment env, final Settings.Builder settingsBuilder) { try { Files.walkFileTree(env.configFile(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String fileName = file.getFileName().toString(); if (fileName.startsWith("logging.")) { for (String allowedSuffix : ALLOWED_SUFFIXES) { if (fileName.endsWith(allowedSuffix)) { loadConfig(file, settingsBuilder); break; } } } return FileVisitResult.CONTINUE; } }); } catch (IOException ioe) { throw new ElasticsearchException("Failed to load logging configuration", ioe); } }
private static List<Path> resolvePaths(List<Path> inputDirs, List<InputFile> inputFiles) throws IOException { List<Path> ret = new ArrayList<>(inputFiles.size()); for (InputFile inputFile : inputFiles) { boolean found = false; for (Path inputDir : inputDirs) { try (Stream<Path> matches = Files.find(inputDir, Integer.MAX_VALUE, (path, attr) -> inputFile.equals(path), FileVisitOption.FOLLOW_LINKS)) { Path file = matches.findFirst().orElse(null); if (file != null) { ret.add(file); found = true; break; } } catch (UncheckedIOException e) { throw e.getCause(); } } if (!found) throw new IOException("can't find input "+inputFile.getFileName()); } return ret; }
@Override @NonNull public Iterable<JavaFileObject> getFiles( @NonNull String folderName, @NullAllowed final ClassPath.Entry entry, @NullAllowed final Set<JavaFileObject.Kind> kinds, @NullAllowed final JavaFileFilterImplementation filter, final boolean recursive) throws IOException { if (separator != FileObjects.NBFS_SEPARATOR_CHAR) { folderName = folderName.replace(FileObjects.NBFS_SEPARATOR_CHAR, separator); } final Path target = root.resolve(folderName); final List<JavaFileObject> res = new ArrayList<>(); try (final Stream<Path> s = recursive ? Files.walk(target, FileVisitOption.FOLLOW_LINKS) : Files.list(target)) { s.filter((p)->{ return (kinds == null || kinds.contains(FileObjects.getKind(FileObjects.getExtension(p.getFileName().toString())))) && Files.isRegularFile(p); }) .forEach((p)->{res.add(FileObjects.pathFileObject(p, root, rootURI, null));}); } return Collections.unmodifiableCollection(res); }
private void setImages(Path path, ImageCompletionExercise exercise, Boolean dryRun) throws BuenOjoDataSetException{ try { Set<SatelliteImage> images = new HashSet<>(maxImages); List<Path> imageList = Files.walk(path, 1, FileVisitOption.FOLLOW_LINKS).filter(p-> { return BuenOjoFileUtils.contentType(p).isPresent() && !BuenOjoFileUtils.contentType(p).get().equals("text/csv") && !isPlaceholderImage(p); }).collect(Collectors.toList()); for (Path imagePath : imageList) { String fileName = FilenameUtils.removeExtension(imagePath.getFileName().toString()); Path csvPath = path.resolve(fileName + FilenameUtils.EXTENSION_SEPARATOR+ BuenOjoFileUtils.CSV_EXTENSION); SatelliteImage image = satelliteImageFactory.imageFromFile(BuenOjoFileUtils.multipartFile(imagePath), BuenOjoFileUtils.multipartFile(csvPath), dryRun); images.add(image); } exercise.setSatelliteImages(new HashSet<>(satelliteImageRepository.save(images))); } catch (BuenOjoCSVParserException | InvalidSatelliteImageType | BuenOjoFileException | IOException | BuenOjoInconsistencyException e) { throw new BuenOjoDataSetException(e.getMessage()); } }
private void loadExercisePhotos(ExerciseDataSetDTO dto, Boolean dryRun) throws IOException, BuenOjoDataSetException, BuenOjoFileException, BuenOjoInconsistencyException { Path picturesPath = Paths.get(dto.getPath(), picturesDir); ArrayList<PhotoLocationImage> pImages = new ArrayList<>(); for (Path path : Files.walk(picturesPath, 1, FileVisitOption.FOLLOW_LINKS).collect(Collectors.toList())) { Optional<String> contentType = BuenOjoFileUtils.contentType(path); if (contentType.isPresent()) { ImageResource img = imageResourceService.createImageResource(null, BuenOjoFileUtils.multipartFile(path), dryRun); PhotoLocationImage pImg = PhotoLocationImage.fromImageResource(img); pImages.add(pImg); } } photoLocationImageRepository.save(pImages); }
private ElasticsearchTestServer(Builder builder) { if (builder.cleanDataDir) { try { Path rootPath = Paths.get(builder.dataDirectory); if (Files.exists(rootPath)) { Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } } catch (IOException e) { e.printStackTrace(); } } Settings settings = Settings.builder() .put("client.transport.ignore_cluster_name", true) .put("transport.type", "netty4") .put("http.type", "netty4") .put("http.enabled", "true") .put("http.port", builder.httpPort) .put("path.home", builder.dataDirectory) .put("transport.tcp.port", builder.transportPort) .build(); this.node = new MyNode(settings, Arrays.asList(Netty4Plugin.class)); }
public Set<Path> getMapFolders(final Logger logger) throws IOException { final Set<Path> mapFolders = new HashSet<>(); for(Path root : getRootPaths()) { int depth = "".equals(root.toString()) ? 0 : Iterables.size(root); Files.walkFileTree(getPath().resolve(root), ImmutableSet.of(FileVisitOption.FOLLOW_LINKS), maxDepth - depth, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if(!isExcluded(dir)) { if(MapFolder.isMapFolder(dir)) { mapFolders.add(dir); } return FileVisitResult.CONTINUE; } else { logger.fine("Skipping excluded path " + dir); return FileVisitResult.SKIP_SUBTREE; } } }); } return mapFolders; }
public static long countFiles(Path file) { if( !Files.exists(file, LinkOption.NOFOLLOW_LINKS) ) { return 0; } try { CountingVisitor visitor = new CountingVisitor(); Files.walkFileTree(file, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, visitor); return visitor.getCount(); } catch( Exception e ) { throw new RuntimeException("Error counting files for " + file.toString(), e); } }
private void validateFileSystemLoopException(Path start, Path... causes) { try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) { try { int count = s.mapToInt(p -> 1).reduce(0, Integer::sum); fail("Should got FileSystemLoopException, but got " + count + "elements."); } catch (UncheckedIOException uioe) { IOException ioe = uioe.getCause(); if (ioe instanceof FileSystemLoopException) { FileSystemLoopException fsle = (FileSystemLoopException) ioe; boolean match = false; for (Path cause: causes) { if (fsle.getFile().equals(cause.toString())) { match = true; break; } } assertTrue(match); } else { fail("Unexpected UncheckedIOException cause " + ioe.toString()); } } } catch(IOException ex) { fail("Unexpected IOException " + ex); } }
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException { this.archivePath = archivePath; if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) { Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue); FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider(); Assert.checkNonNull(jarFSProvider, "should have been caught before!"); this.fileSystem = jarFSProvider.newFileSystem(archivePath, env); } else { this.fileSystem = FileSystems.newFileSystem(archivePath, null); } packages = new HashMap<>(); for (Path root : fileSystem.getRootDirectories()) { Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { if (isValid(dir.getFileName())) { packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir); return FileVisitResult.CONTINUE; } else { return FileVisitResult.SKIP_SUBTREE; } } }); } }
EurostagDDB(List<Path> ddbDirs) throws IOException { for (Path ddbDir : ddbDirs) { ddbDir = readSymbolicLink(ddbDir); if (!Files.exists(ddbDir) && !Files.isDirectory(ddbDir)) { throw new IllegalArgumentException(ddbDir + " must exist and be a dir"); } Files.walkFileTree(ddbDir, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String fileName = file.getFileName().toString(); Path tmpfile = readSymbolicLink(file); if (Files.isDirectory(tmpfile)) { Files.walkFileTree(tmpfile, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, this); } else if (Files.isRegularFile(tmpfile) && fileName.endsWith(".tg")) { String key = fileName.substring(0, fileName.length() - 3); if (generators.containsKey(key)) { LOGGER.warn("the processing has detected that the file {} is present in {} and {}", fileName, tmpfile, generators.get(key)); } generators.put(key, tmpfile); } return super.visitFile(file, attrs); } }); } }
private static String listDerivateContentAsJson(MCRDerivate derObj, String path, int depth, UriInfo info) throws IOException { StringWriter sw = new StringWriter(); MCRPath root = MCRPath.getPath(derObj.getId().toString(), "/"); root = MCRPath.toMCRPath(root.resolve(path)); if (depth == -1) { depth = Integer.MAX_VALUE; } if (root != null) { JsonWriter writer = new JsonWriter(sw); Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), depth, new MCRJSONFileVisitor(writer, derObj.getOwnerID(), derObj.getId(), info)); writer.close(); } return sw.toString(); }
/** * Returns the latest version subfolder of the specified module folder. * * @param modFolder module folder to look latest version subfolder in * @return the latest version subfolder of the specified module folder or <code>null</code> if the specified module folder contains no folders that are * valid version strings * @throws IOException if scanning the specified module folder throws an {@link IOException} */ public static Path getLatestVersionSubfolder( final Path modFolder ) throws IOException { // Holders because "final" is needed to be accessible from visitFile() // (I store the path too because version folder name is ambiguous (e.g. "1.0" and "1.0.0") final Holder< Path > latestVersionPath = new Holder<>(); final Holder< VersionBean > latestVersion = new Holder<>(); Files.walkFileTree( modFolder, Collections.< FileVisitOption > emptySet(), 1, new SimpleFileVisitor< Path >() { @Override public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException { if ( !attrs.isDirectory() ) return FileVisitResult.CONTINUE; final VersionBean version = VersionBean.fromString( file.getFileName().toString() ); if ( version != null ) if ( latestVersion.value == null || version.compareTo( latestVersion.value ) > 0 ) { latestVersion.value = version; latestVersionPath.value = file; } return FileVisitResult.CONTINUE; } } ); return latestVersionPath.value; }
/** * Returns the release file for the specified name prefix * * @param folder folder in which to search * @param prefix file name prefix whose release file to return (the beginning of the file name) * @return the release file for the specified name prefix * @throws IOException if any error occurs during searching for the release file */ private static Path getReleaseFile( final Path folder, final String prefix ) throws IOException { final AtomicReference< Path > result = new AtomicReference<>(); Files.walkFileTree( folder, Collections.< FileVisitOption > emptySet(), 1, new SimpleFileVisitor< Path >() { @Override public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException { if ( attrs.isDirectory() ) return FileVisitResult.CONTINUE; if ( file.getFileName().toString().startsWith( prefix ) ) { result.set( file ); return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } } ); return result.get(); }
/** * Corrects the specified balance data pack. * * @param webExportFolder base web export folder * @param outFolder output folder * @throws Exception if any error occurs */ private static void correctBDPack( final Path webExportFolder, final Path outFolder ) throws Exception { Files.createDirectories( outFolder.resolve( "enUS" ) ); // First copy strings Files.copy( webExportFolder.resolve( "enUS/S2Strings.xml" ), outFolder.resolve( "enUS/S2Strings.xml" ) ); Files.walkFileTree( webExportFolder, Collections.< FileVisitOption > emptySet(), 1, new SimpleFileVisitor< Path >() { @Override public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException { if ( attrs.isDirectory() ) return FileVisitResult.CONTINUE; processFile( file, outFolder ); return FileVisitResult.CONTINUE; }; } ); }
/** * Creates a balance data pack. * * @param webExportFolder base web export folder * @param outFile output file * @throws Exception if any error occurs */ public static void createBDPack( final Path webExportFolder, final Path outFile ) throws Exception { try ( final GZIPOutputStream out = new GZIPOutputStream( Files.newOutputStream( outFile ) ) ) { // First add the SC2 strings addFile( out, webExportFolder.resolve( "enUS/S2Strings.xml" ) ); Files.walkFileTree( webExportFolder, Collections.< FileVisitOption > emptySet(), 1, new SimpleFileVisitor< Path >() { @Override public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException { if ( attrs.isDirectory() ) return FileVisitResult.CONTINUE; addFile( out, file ); return FileVisitResult.CONTINUE; }; } ); } }
/** * Counts the SC2 replay files in the specified folder (non-recursive). * * @param folder folder in which to count * @return the number of SC2 replay files in the specified folder; -1 if the specified path exists but is not a folder or if some error occurs */ public static int countReplays( final Path folder ) { if ( !Files.exists( folder ) ) return 0; if ( !Files.isDirectory( folder ) ) return -1; final Int count = new Int(); try { Files.walkFileTree( folder, Collections.< FileVisitOption > emptySet(), 1, new SimpleFileVisitor< Path >() { @Override public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException { if ( !attrs.isDirectory() && hasRepExt( file ) ) count.value++; return FileVisitResult.CONTINUE; } } ); } catch ( final IOException ie ) { Env.LOGGER.error( "Failed to count replays in folder: " + folder, ie ); return -1; } return count.value; }
@Nonnull private Collection<FileResult> getFileResults(final Log log, final Path dir) { Collection<FileResult> allFiles = new ArrayList<>(); FileVisitor<Path> fileVisitor = new GetEncodingsFileVisitor( log, this.getIncludeRegex() != null ? this.getIncludeRegex() : INCLUDE_REGEX_DEFAULT, this.getExcludeRegex() != null ? this.getExcludeRegex() : EXCLUDE_REGEX_DEFAULT, allFiles ); try { Set<FileVisitOption> visitOptions = new LinkedHashSet<>(); visitOptions.add(FileVisitOption.FOLLOW_LINKS); Files.walkFileTree(dir, visitOptions, Integer.MAX_VALUE, fileVisitor ); } catch (Exception e) { log.error(e.getCause() + e.getMessage()); } return allFiles; }
/** * Delete a file or directory * * @param file {@link File} representing file or directory * @throws IOException */ public static void deleteFileOrDirectory(File file) throws IOException { if (file.exists()) { if (file.isDirectory()) { Path rootPath = Paths.get(file.getAbsolutePath()); Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS) .sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } else { file.delete(); } } else { throw new RuntimeException("File or directory does not exist"); } }
/** * Adds revving suffix to all filenames beneath a folder. * * <p>Adds revving suffix to all filenames beneath a folder, recursing into subfolders. * Only js and css files are revved. * * @param suffix the suffix to add to all filenames. * @param startFolder the folder at root of tree within which to suffix files * @param logger a CloudwatchLogs logger. * @throws IOException */ public static void appendRevvingSuffix(String suffix, Path startFolder, LambdaLogger logger) throws IOException { Files .walk(startFolder, FileVisitOption.FOLLOW_LINKS) .filter(Files::isRegularFile) .forEach(path -> { File file = path.toFile(); if (file.isDirectory()) { return; } String absolutePath = file.getAbsolutePath(); String fileExtension = FilenameUtils.getExtension(absolutePath); if (!fileExtension.equals("js") && !fileExtension.equals("css")) { // We rev only js and css return; } String suffixedName = FilenameUtils.getBaseName(absolutePath) + "_" + suffix + "." + fileExtension; File suffixedFile = new File(file.getParentFile(), suffixedName); file.renameTo(suffixedFile); logger.log("Appended suffix to file: " + absolutePath + ", giving: " + suffixedFile.getAbsolutePath()); }); }
protected List<File> findCaseFiles() throws IOException { List<File> caseFiles = new ArrayList<>(); List<PathMatcher> inMatchers = getIncludeMatchers(); List<PathMatcher> exMatchers = getExcludeMatchers(); Files.walkFileTree(Paths.get(getAssetRoot().getPath()), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { Path p = Paths.get(getAssetPath(path.toFile())); if (matches(inMatchers, p) && !matches(exMatchers, p)) { caseFiles.add(p.toFile()); } return FileVisitResult.CONTINUE; } }); return caseFiles; }
/** {@inheritDoc} */ @Override protected void createBackup() throws InterruptedException, IOException { SimpleDateFormat rfc8601Formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH_mm_ss'Z'"); rfc8601Formatter.setTimeZone(TimeZone.getTimeZone("UTC")); snapshotOutput = Paths.get(config.getBackupOutputDir(), rfc8601Formatter.format(new Date())); if (Files.exists(snapshotOutput)) { throw new FileAlreadyExistsException("Backup output directory already exists: " + snapshotOutput.toString()); } Files.createDirectories(snapshotOutput); backupExcludes = new ArrayList<>(Arrays.asList(config.getBackupExcludes())); for (String file : config.getBackupIncludes()) { Files.walkFileTree(Paths.get(file), EnumSet.allOf(FileVisitOption.class), Integer.MAX_VALUE, new SnapshotVisitor()); } }
public static void copyRecursively(final Path source, final Path destination, final CopyOption... copyOptions) throws IOException { final Set<CopyOption> copyOptionsSet = new HashSet<>( Arrays.asList(copyOptions)); if (!isDirectory(source)) throw new FileNotFoundException("Not a directory: " + source); if (isDirectory(destination) && !copyOptionsSet.contains(REPLACE_EXISTING)) throw new FileAlreadyExistsException(destination.toString()); Path destinationParent = destination.getParent(); if (destinationParent != null && !isDirectory(destinationParent)) throw new FileNotFoundException("Not a directory: " + destinationParent); RecursiveCopyFileVisitor visitor = new RecursiveCopyFileVisitor( destination, copyOptionsSet, source); Set<FileVisitOption> walkOptions = noneOf(FileVisitOption.class); if (!copyOptionsSet.contains(NOFOLLOW_LINKS)) walkOptions = EnumSet.of(FOLLOW_LINKS); walkFileTree(source, walkOptions, MAX_VALUE, visitor); }
/** * Returns logical name of the first found GWT module. * * @param folder path to folder that contains project sources * @return GWT module logical name * @throws java.io.IOException if an I/O error is thrown while finding GWT module descriptor * @throws IllegalArgumentException if GWT module descriptor not found */ public static String detectGwtModuleLogicalName(Path folder) throws IOException { final String resourcesDir = folder.toString(); Finder finder = new Finder("*" + GWT_MODULE_XML_SUFFIX); Files.walkFileTree(folder, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, finder); if (finder.getFirstMatchedFile() == null) { throw new IllegalArgumentException("GWT module descriptor (*.gwt.xml) not found."); } String filePath = finder.getFirstMatchedFile().toString(); filePath = filePath.substring( filePath.indexOf(resourcesDir) + resourcesDir.length() + 1, filePath.length() - GWT_MODULE_XML_SUFFIX.length()); return filePath.replace(File.separatorChar, '.'); }
protected static List<Music> findMusic() throws IOException { final List<Music> musics = new ArrayList<>(); try (final Stream<Path> pathStream = Files.walk(Paths.get(MP3_PATH), FileVisitOption.FOLLOW_LINKS)) { pathStream .filter((p) -> !p.toFile().isDirectory() && p.toFile().getAbsolutePath().endsWith(MP3_EXTENSION)) .forEach(new Consumer<Path>() { @Override public void accept(Path t) { musics.add( new Music(Long.parseLong( Integer.toString( musics.size() ) ), t) ); } }); } catch (final IOException e) { e.printStackTrace(); } return musics; }
@Override JSONStreamAware processRequest(HttpServletRequest req) { JSONObject response = new JSONObject(); if (!Files.isReadable(PLUGINS_HOME)) { return JSONResponses.fileNotFound(PLUGINS_HOME.toString()); } PluginDirListing pluginDirListing = new PluginDirListing(); try { Files.walkFileTree(PLUGINS_HOME, EnumSet.noneOf(FileVisitOption.class), 2, pluginDirListing); } catch (IOException e) { return JSONResponses.fileNotFound(e.getMessage()); } JSONArray plugins = new JSONArray(); pluginDirListing.getDirectories().forEach(dir -> plugins.add(Paths.get(dir.toString()).getFileName().toString())); response.put("plugins", plugins); return response; }
private int countFilesInTree(final File file) { final ArrayList<Path> toProcess = new ArrayList<>(); rVal = 0; EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); try { Files.walkFileTree(file.toPath(), opts, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile( Path dirPath, BasicFileAttributes attributes ) throws IOException { rVal++; return FileVisitResult.CONTINUE; } }); } catch (Exception ex) { } return rVal; }
@NonNull public Set<ValidationError> execute(@NonNull final Path basePath) throws IOException { // Init Context ... Context.getInstance(basePath); // Process rules ... final Stream<Path> filesToProgress = Files.walk(basePath, FileVisitOption.FOLLOW_LINKS).map(path -> basePath.relativize(path)) .filter(childPath -> !exclusions.stream().anyMatch(exc -> childPath.toString().startsWith(exc))); final Set<Set<ValidationError>> result = filesToProgress.map(relativePath -> { logger.debug("Processing file -> '{}' '{}'", basePath, relativePath); // Filter rules ... final Stream<Rule> filteredRules = rules.stream().filter(rule -> rule.accepts(basePath, relativePath)); // Apply rules .. return filteredRules.map(rule -> rule.verify(basePath, relativePath)).collect(Collectors.toSet()); }).filter(set -> !set.isEmpty()).flatMap(Collection::stream).collect(Collectors.toSet()); final Stream<ValidationError> errors = result.stream().flatMap(Collection::stream); // Filter ignored errors .... return errors.filter(e -> ignore.get(e.getUUID()) == null).collect(Collectors.toSet()); }
/** * Clean the {@code TARGET_GENERATED_TEST_SOURCES_FOLDER folder} before running the test. * * @throws IOException in case of problem when cleaning the directories */ private void cleanGeneratedSources() throws IOException { if (TARGET_GENERATED_TEST_SOURCES_FOLDER.exists()) { if (TARGET_GENERATED_TEST_SOURCES_FOLDER.isFile()) { TARGET_GENERATED_TEST_SOURCES_FOLDER.delete(); Files.createDirectory(TARGET_GENERATED_TEST_SOURCES_FOLDER.toPath()); } else { Files .walk(TARGET_GENERATED_TEST_SOURCES_FOLDER.toPath(), Integer.MAX_VALUE, FileVisitOption.FOLLOW_LINKS) .filter(p -> !p.toFile().equals(TARGET_GENERATED_TEST_SOURCES_FOLDER)) .forEach(p -> p.toFile().delete()); } } else { Files.createDirectory(TARGET_GENERATED_TEST_SOURCES_FOLDER.toPath()); } }
private void init() throws IOException { logFile = new File(MemeUtils.getLogDir(), getOutputFileName() + ".log"); log("=========="); log("Starting..."); morePointsX = new float[150000000]; morePointsY = new float[150000000]; if (outputFile == null) { outputFile = new File(MemeUtils.getOutputDataDir(), getOutputFileName() + ".csv"); } if (rawWosDataDir == null) { rawWosDataDir = new File(MemeUtils.getRawDataDir(), wosFolder); } writer = new BufferedWriter(new FileWriter(outputFile)); walkFileTreeOptions = new HashSet<FileVisitOption>(); walkFileTreeOptions.add(FileVisitOption.FOLLOW_LINKS); random = new Random(0); }
private void init() { logFile = new File(MemeUtils.getLogDir(), "prepare-pmc.log"); log("=========="); log("Starting..."); idMap = new HashMap<String,String>(); titles = new HashMap<String,String>(); dates = new HashMap<String,String>(); abstracts = new HashMap<String,String>(); references = new HashMap<String,List<String>>(); progress = 0; idMissing = 0; duplicateIds = 0; titleMissing = 0; abstractMissing = 0; refNotFound = 0; dateMissing = 0; walkFileTreeOptions = new HashSet<FileVisitOption>(); walkFileTreeOptions.add(FileVisitOption.FOLLOW_LINKS); }
public SqlCreatorBySqlFilesDir(String sqlFilesDir) { sqlFilePaths = new ArrayList<>(); try { Files.walkFileTree(FileSystems.getDefault().getPath(sqlFilesDir), EnumSet.noneOf(FileVisitOption.class), 1, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (path.toString().toLowerCase().endsWith(".sql")) { sqlFilePaths.add(path); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { throw new RuntimeException(e); } }
@Test public void testIterate1 () throws IOException { final Path p = Paths.get ("pom.xml").toRealPath (); final Path aStartPath = p.getParent (); assertNotNull (aStartPath); final int nNames = aStartPath.getNameCount (); Files.walkFileTree (aStartPath, EnumSet.noneOf (FileVisitOption.class), 2, new SimpleFileVisitor <Path> () { @Override public FileVisitResult visitFile (final Path aCurFile, final BasicFileAttributes attrs) throws IOException { s_aLogger.info (aCurFile.subpath (nNames, aCurFile.getNameCount ()).toString ()); return FileVisitResult.CONTINUE; } }); s_aLogger.info (PathHelper.getDirectoryContent (aStartPath).toString ()); }