List of usage examples for java.nio.file FileVisitResult CONTINUE
FileVisitResult CONTINUE
To view the source code for java.nio.file FileVisitResult CONTINUE.
Click Source Link
From source file:com.marklogic.hub.RestAssetLoader.java
/** * FileVisitor method that loads the file into the modules database if the fileFilter accepts it. *///from ww w. j a va2s . co m @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) throws IOException { if (fileFilter.accept(path.toFile())) { Path relPath = currentAssetPath.relativize(path); String uri = "/" + relPath.toString().replace("\\", "/"); if (this.currentRootPath != null) { String name = this.currentRootPath.toFile().getName(); // A bit of a hack to support the special "root" directory. if (!"root".equals(name)) { uri = "/" + name + uri; } } uri = "/ext" + uri; loadFile(uri, path.toFile()); filesLoaded.add(path.toFile()); } return FileVisitResult.CONTINUE; }
From source file:net.mozq.picto.core.ProcessCore.java
public static void findFiles(ProcessCondition processCondition, Consumer<ProcessData> processDataSetter, BooleanSupplier processStopper) throws IOException { Set<FileVisitOption> fileVisitOptionSet; if (processCondition.isFollowLinks()) { fileVisitOptionSet = EnumSet.of(FileVisitOption.FOLLOW_LINKS); } else {/* ww w. j a va2s .c o m*/ fileVisitOptionSet = Collections.emptySet(); } Files.walkFileTree(processCondition.getSrcRootPath(), fileVisitOptionSet, processCondition.getDept(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (processStopper.getAsBoolean()) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.SKIP_SUBTREE; } if (processStopper.getAsBoolean()) { return FileVisitResult.TERMINATE; } if (!processCondition.getPathFilter().accept(file, attrs)) { return FileVisitResult.SKIP_SUBTREE; } Path rootRelativeSubPath = processCondition.getSrcRootPath().relativize(file.getParent()); ImageMetadata imageMetadata = getImageMetadata(file); Date baseDate; if (processCondition.isChangeFileCreationDate() || processCondition.isChangeFileModifiedDate() || processCondition.isChangeFileAccessDate() || processCondition.isChangeExifDate()) { baseDate = getBaseDate(processCondition, file, attrs, imageMetadata); } else { baseDate = null; } String destSubPathname = processCondition.getDestSubPathFormat().format(varName -> { try { switch (varName) { case "Now": return new Date(); case "ParentSubPath": return rootRelativeSubPath.toString(); case "FileName": return file.getFileName().toString(); case "BaseName": return FileUtilz.getBaseName(file.getFileName().toString()); case "Extension": return FileUtilz.getExt(file.getFileName().toString()); case "Size": return Long.valueOf(Files.size(file)); case "CreationDate": return (processCondition.isChangeFileCreationDate()) ? baseDate : new Date(attrs.creationTime().toMillis()); case "ModifiedDate": return (processCondition.isChangeFileModifiedDate()) ? baseDate : new Date(attrs.lastModifiedTime().toMillis()); case "AccessDate": return (processCondition.isChangeFileAccessDate()) ? baseDate : new Date(attrs.lastAccessTime().toMillis()); case "PhotoTakenDate": return (processCondition.isChangeExifDate()) ? baseDate : getPhotoTakenDate(file, imageMetadata); case "Width": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_WIDTH); case "Height": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_LENGTH); case "FNumber": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FNUMBER); case "Aperture": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE); case "MaxAperture": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_MAX_APERTURE_VALUE); case "ISO": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_ISO); case "FocalLength": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FOCAL_LENGTH); // ? case "FocalLength35mm": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FOCAL_LENGTH_IN_35MM_FORMAT); case "ShutterSpeed": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE); case "Exposure": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE); // case "ExposureTime": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_TIME); // case "ExposureMode": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_MODE); case "ExposureProgram": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_PROGRAM); case "Brightness": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE); case "WhiteBalance": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_WHITE_BALANCE_1); case "LightSource": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_LIGHT_SOURCE); case "Lens": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS); case "LensMake": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MAKE); case "LensModel": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MODEL); case "LensSerialNumber": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_SERIAL_NUMBER); case "Make": return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MAKE); case "Model": return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MODEL); case "SerialNumber": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SERIAL_NUMBER); case "Software": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SOFTWARE); case "ProcessingSoftware": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_PROCESSING_SOFTWARE); case "OwnerName": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_OWNER_NAME); case "CameraOwnerName": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_CAMERA_OWNER_NAME); case "GPSLat": return getEXIFGpsLat(imageMetadata); case "GPSLatDeg": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 0); case "GPSLatMin": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 1); case "GPSLatSec": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 2); case "GPSLatRef": return getEXIFStringValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); case "GPSLon": return getEXIFGpsLon(imageMetadata); case "GPSLonDeg": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 0); case "GPSLonMin": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 1); case "GPSLonSec": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 2); case "GPSLonRef": return getEXIFStringValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); case "GPSAlt": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE); case "GPSAltRef": return getEXIFIntValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE_REF); default: throw new PictoInvalidDestinationPathException(Messages .getString("message.warn.invalid.destSubPath.varName", varName)); } } catch (PictoException e) { throw e; } catch (Exception e) { throw new PictoInvalidDestinationPathException( Messages.getString("message.warn.invalid.destSubPath.pattern"), e); } }); Path destSubPath = processCondition.getDestRootPath().resolve(destSubPathname).normalize(); if (!destSubPath.startsWith(processCondition.getDestRootPath())) { throw new PictoInvalidDestinationPathException( Messages.getString("message.warn.invalid.destination.path", destSubPath)); } ProcessData processData = new ProcessData(); processData.setSrcPath(file); processData.setSrcFileAttributes(attrs); processData.setDestPath(destSubPath); processData.setBaseDate(baseDate); processDataSetter.accept(processData); return FileVisitResult.CONTINUE; } }); }
From source file:com.ibm.streamsx.topology.internal.context.remote.ZippedToolkitRemoteContext.java
private static void addAllToZippedArchive(Map<Path, String> starts, Path zipFilePath) throws IOException { try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(zipFilePath.toFile())) { for (Path start : starts.keySet()) { final String rootEntryName = starts.get(start); Files.walkFileTree(start, new SimpleFileVisitor<Path>() { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { // Skip pyc files. if (file.getFileName().toString().endsWith(".pyc")) return FileVisitResult.CONTINUE; String entryName = rootEntryName; String relativePath = start.relativize(file).toString(); // If empty, file is the start file. if (!relativePath.isEmpty()) { entryName = entryName + "/" + relativePath; }/*w ww .j ava 2 s .c om*/ // Zip uses forward slashes entryName = entryName.replace(File.separatorChar, '/'); ZipArchiveEntry entry = new ZipArchiveEntry(file.toFile(), entryName); if (Files.isExecutable(file)) entry.setUnixMode(0100770); else entry.setUnixMode(0100660); zos.putArchiveEntry(entry); Files.copy(file, zos); zos.closeArchiveEntry(); return FileVisitResult.CONTINUE; } public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { final String dirName = dir.getFileName().toString(); // Don't include pyc files or .toolkit if (dirName.equals("__pycache__")) return FileVisitResult.SKIP_SUBTREE; ZipArchiveEntry dirEntry = new ZipArchiveEntry(dir.toFile(), rootEntryName + "/" + start.relativize(dir).toString().replace(File.separatorChar, '/') + "/"); zos.putArchiveEntry(dirEntry); zos.closeArchiveEntry(); return FileVisitResult.CONTINUE; } }); } } }
From source file:company.gonapps.loghut.utils.FileUtils.java
@Override public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) throws IOException { paths.add(path);// w w w. jav a 2s. c om return FileVisitResult.CONTINUE; }
From source file:org.openhab.tools.analysis.checkstyle.PackageExportsNameCheck.java
/** * Filter and return the packages from the source directory. Only not excluded packages will be returned. * * @param sourcePath - The full path of the source directory * @return {@link Set } of {@link String }s with the package names. * @throws IOException if an I/O error is thrown while visiting files *///ww w . j av a 2 s. c om private Set<String> getFilteredPackagesFromSourceDirectory(Path sourcePath) throws IOException { Set<String> packages = new HashSet<>(); // No symbolic links are expected in the source directory if (Files.exists(sourcePath, LinkOption.NOFOLLOW_LINKS)) { Files.walkFileTree(sourcePath, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) { Path packageRelativePath = sourcePath.relativize(path.getParent()); String packageName = packageRelativePath.toString() .replaceAll(Matcher.quoteReplacement(File.separator), "."); if (!isExcluded(packageName)) { packages.add(packageName); } return FileVisitResult.CONTINUE; } }); } return packages; }
From source file:io.syndesis.project.converter.DefaultProjectGeneratorTest.java
@After public void tearDown() throws Exception { if (runtimeDir != null) { Files.walkFileTree(runtimeDir, new SimpleFileVisitor<Path>() { @Override/* w w w .j a v a2s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } }
From source file:org.apdplat.superword.tools.PdfParser.java
public static void parseZip(String zipFile) { long start = System.currentTimeMillis(); LOGGER.info("?ZIP" + zipFile); try (FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), WordClassifier.class.getClassLoader())) { for (Path path : fs.getRootDirectories()) { LOGGER.info("?" + path); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/* w w w. j a v a 2 s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { LOGGER.info("?" + file); // ? Path temp = Paths.get("target/it-software-domain-temp.pdf"); Files.copy(file, temp, StandardCopyOption.REPLACE_EXISTING); parseFile(temp.toFile().getAbsolutePath()); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?", e); } long cost = System.currentTimeMillis() - start; LOGGER.info("?" + cost + ""); }
From source file:org.apdplat.superword.tools.WordClassifierForYouDao.java
public static void parseZip(String zipFile) { LOGGER.info("?ZIP" + zipFile); try (FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), WordClassifierForYouDao.class.getClassLoader())) { for (Path path : fs.getRootDirectories()) { LOGGER.info("?" + path); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w w w .j av a2 s.co m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { LOGGER.info("?" + file); // ? Path temp = Paths.get("target/origin-html-temp.txt"); Files.copy(file, temp, StandardCopyOption.REPLACE_EXISTING); parseFile(temp.toFile().getAbsolutePath()); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?", e); } }
From source file:com.expedia.tesla.compiler.Util.java
/** * Expand glob file patterns to path strings. Any path element that is not a glob pattern will be keep as it is. * // w ww. j a va2 s . c o m * @param pathOrPatterns * glob patterns. * * @return * The expanded paths. * * @throws IOException * On IO errors. */ public static Collection<String> expandWildcard(Collection<String> pathOrPatterns) throws IOException { final List<String> files = new ArrayList<String>(); final List<PathMatcher> matchers = new ArrayList<PathMatcher>(); for (String pattern : pathOrPatterns) { if (pattern.contains("*") || pattern.contains("?")) { PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern); matchers.add(matcher); } else { files.add(pattern); } } if (!matchers.isEmpty()) { Files.walkFileTree(new File(System.getProperty("user.dir")).toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { for (PathMatcher matcher : matchers) { if (matcher.matches(file)) { files.add(file.toString()); } } return FileVisitResult.CONTINUE; } }); } return files; }
From source file:spdxedit.SpdxLogic.java
/** * Creates a new package with the specified license, name, comment, and root * path.//from w w w . j a va 2 s . c om * * @param pkgRootPath * The path from which the files will be included into the * package. If absent, creates a "remote" package, i.e. one * without files, just referencing a remote dependency. * @param name * @param omitHiddenFiles * @param declaredLicense * @param downloadLocation * @return */ public static SpdxPackage createSpdxPackageForPath(Optional<Path> pkgRootPath, AnyLicenseInfo declaredLicense, String name, String downloadLocation, final boolean omitHiddenFiles) { Objects.requireNonNull(pkgRootPath); try { SpdxPackage pkg = new SpdxPackage(name, declaredLicense, new AnyLicenseInfo[] {} /* Licences from files */, null /* Declared licenses */, declaredLicense, downloadLocation, new SpdxFile[] {} /* Files */, new SpdxPackageVerificationCode(null, new String[] {})); pkg.setLicenseInfosFromFiles(new AnyLicenseInfo[] { new SpdxNoAssertionLicense() }); pkg.setCopyrightText("NOASSERTION"); if (pkgRootPath.isPresent()) { // Add files in path List<SpdxFile> addedFiles = new LinkedList<>(); String baseUri = pkgRootPath.get().toUri().toString(); FileVisitor<Path> fileVisitor = new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (omitHiddenFiles && dir.getFileName().toString().startsWith(".")) { return FileVisitResult.SKIP_SUBTREE; } else return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { // Skip if omitHidden is set and this file is hidden. if (omitHiddenFiles && (file.getFileName().toString().startsWith(".") || Files.isHidden(file))) return FileVisitResult.CONTINUE; try { SpdxFile addedFile = newSpdxFile(file, baseUri); addedFiles.add(addedFile); } catch (InvalidSPDXAnalysisException e) { throw new RuntimeException(e); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { logger.error("Unable to add file ", file.toAbsolutePath().toString()); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }; Files.walkFileTree(pkgRootPath.get(), fileVisitor); SpdxFile[] files = addedFiles.stream().toArray(size -> new SpdxFile[size]); pkg.setFiles(files); recomputeVerificationCode(pkg); } else { //External package pkg.setFilesAnalyzed(false); pkg.setPackageVerificationCode(null); } return pkg; } catch (InvalidSPDXAnalysisException | IOException e) { throw new RuntimeException(e); } }