List of usage examples for java.nio.file LinkOption NOFOLLOW_LINKS
LinkOption NOFOLLOW_LINKS
To view the source code for java.nio.file LinkOption NOFOLLOW_LINKS.
Click Source Link
From source file:com.jvms.i18neditor.Editor.java
public void importResources(Path dir) { if (!closeCurrentSession()) { return;/*from w ww .j a v a 2 s . com*/ } if (Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) { reset(); resourcesDir = dir; } else { showError(MessageBundle.get("resources.open.error.multiple")); return; } try { Files.walk(resourcesDir, 1).filter(path -> Resources.isResource(path)).forEach(path -> { try { Resource resource = Resources.read(path); setupResource(resource); } catch (Exception e) { e.printStackTrace(); showError(MessageBundle.get("resources.open.error.single", path.toString())); } }); List<String> recentDirs = settings.getListProperty("history"); recentDirs.remove(resourcesDir); recentDirs.add(resourcesDir.toString()); if (recentDirs.size() > 5) { recentDirs.remove(0); } settings.setProperty("history", recentDirs); editorMenu.setRecentItems(Lists.reverse(recentDirs)); Map<String, String> keys = Maps.newTreeMap(); resources.forEach(resource -> keys.putAll(resource.getTranslations())); List<String> keyList = Lists.newArrayList(keys.keySet()); translationTree.setModel(new TranslationTreeModel(keyList)); updateUI(); } catch (IOException e) { e.printStackTrace(); showError(MessageBundle.get("resources.open.error.multiple")); } }
From source file:de.jwi.jfm.FileWrapper.java
public String getAttributes() throws IOException { FileSystem fileSystem = FileSystems.getDefault(); Set<String> fileSystemViews = fileSystem.supportedFileAttributeViews(); File file = getFile();/* w ww . ja v a2 s. c o m*/ Path p = file.toPath(); try { if (fileSystemViews.contains("posix")) { Set<PosixFilePermission> posixFilePermissions = Files.getPosixFilePermissions(p, LinkOption.NOFOLLOW_LINKS); PosixFileAttributes attrs = Files.getFileAttributeView(p, PosixFileAttributeView.class) .readAttributes(); String owner = attrs.owner().toString(); String group = attrs.group().toString(); String permissions = PosixFilePermissions.toString(attrs.permissions()); String res = String.format("%s %s %s", permissions, owner, group); return res; } else if (fileSystemViews.contains("dos")) { StringWriter sw = new StringWriter(); DosFileAttributeView attributeView = Files.getFileAttributeView(p, DosFileAttributeView.class); DosFileAttributes dosFileAttributes = null; dosFileAttributes = attributeView.readAttributes(); if (dosFileAttributes.isArchive()) { sw.append('A'); } if (dosFileAttributes.isHidden()) { sw.append('H'); } if (dosFileAttributes.isReadOnly()) { sw.append('R'); } if (dosFileAttributes.isSystem()) { sw.append('S'); } return sw.toString(); } } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:com.cyc.corpus.nlmpaper.AIMedOpenAccessPaper.java
private Optional<AIMedArticle> get() { if (paper != null) { return Optional.of(paper); }/* w ww . j a v a 2 s . c o m*/ try { Optional<Path> xmlpath = getPaperPath(); if (xmlpath.isPresent()) { Path destinationD = Paths.get(basedir, "AIMedOpenAccess", "XML"); if (Files.notExists(destinationD, LinkOption.NOFOLLOW_LINKS)) { Files.createDirectory(destinationD); } Path extractTo = Paths.get(basedir, "AIMedOpenAccess", "XML", xmlpath.get().getFileName().toString()); Files.copy(xmlpath.get(), extractTo, StandardCopyOption.REPLACE_EXISTING); // specify the location and name of xml file to be read File xmlFile = extractTo.toFile(); String articleString = FileUtils.readFileToString(xmlFile).trim(); paper = new AIMedArticle(articleString); return Optional.of(paper); } } catch (IOException ex) { LOG.log(Level.SEVERE, ex.getMessage(), ex); return Optional.empty(); } return Optional.empty(); }
From source file:org.zxg.hotupdate.HotUpdateClassLoader.java
@Override public void fileModified(Path path) { try {//from www . j ava2s .com if (Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS)) { synchronized (this) { loadClassFromFile(relativePathToClassName(classesRootDirPath.relativize(path).toString())); } } } catch (IOException ioe) { ioe.printStackTrace(); } }
From source file:org.sakuli.datamodel.helper.TestSuiteHelperTest.java
@Test public void testNotModifyFiles() throws Exception { Path path = Paths.get("temp-testsuite.suite"); try {/*from w ww .ja v a 2 s .c om*/ String source = "line1\r\nbla\r\n"; FileUtils.writeStringToFile(path.toFile(), source); FileTime beforeTimeStamp = Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS); Thread.sleep(1100); String result = TestSuiteHelper.prepareTestSuiteFile(path); assertEquals(source, result); FileTime afterTimeStamp = Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS); assertEquals(beforeTimeStamp, afterTimeStamp); } finally { Files.deleteIfExists(path); } }
From source file:com.ejie.uda.jsonI18nEditor.Editor.java
public void importResources(Path dir) { Stream<Path> filter; try {// w w w . j a v a 2 s. c o m if (!closeCurrentSession()) { return; } if (Files.isDirectory(dir, LinkOption.NOFOLLOW_LINKS)) { reset(); resourcesDir = dir; filter = Files.walk(resourcesDir, 1).filter(path -> Resources.isResource(path)); } else { reset(); // Se ha arrastrado un fichero de 18n individual, se debe de obtener los recursos relacionados con el bundle al que pertenece. Pattern.matches(BUNDLE_REGEX, dir.getFileName().toString()); Pattern regex = Pattern.compile(BUNDLE_REGEX); resourcesDir = dir.getParent(); inputFile = dir; Matcher regexMatcher = regex.matcher(dir.getFileName().toString()); if (regexMatcher.find()) { this.bundle = regexMatcher.group(1); filter = Files.walk(resourcesDir, 1).filter(path -> Resources.isResource(path, this.bundle)); } else { showError(MessageBundle.get("resources.open.error.multiple")); return; } // Pattern.matches("BUNDLE_REGEX", dir.getFileName().toString()); // showError(MessageBundle.get("resources.open.error.multiple")); // return; } filter.forEach(path -> { try { Resource resource = Resources.read(path); setupResource(resource); } catch (Exception e) { e.printStackTrace(); showError(MessageBundle.get("resources.open.error.single", path.toString())); } }); List<String> recentDirs = settings.getListProperty("history"); recentDirs.remove(dir); recentDirs.add(dir.toString()); if (recentDirs.size() > 5) { recentDirs.remove(0); } settings.setProperty("history", recentDirs); editorMenu.setRecentItems(Lists.reverse(recentDirs)); Map<String, String> keys = Maps.newTreeMap(); resources.forEach(resource -> keys.putAll(resource.getTranslations())); // resources.forEach(resource -> { // // // // }); List<String> keyList = Lists.newArrayList(keys.keySet()); translationTree.setModel(new TranslationTreeModel(keyList)); updateUI(); // for (String key : keyList) { // boolean anyEmpty = false; // // for (Resource resource : resources) { // if (StringUtils.isBlank(resource.getTranslation(key))){ // anyEmpty = true; // } // } // // TranslationTreeModel model = (TranslationTreeModel) translationTree.getModel(); // TranslationTreeNode node = model.getNodeByKey(key); // // node // } // keyList.stream().filter(key -> { // // resources.stream().filter(resource -> { // return StringUtils.isNotBlank(resource.getTranslation(key)); // }); // return true; // }); } catch (IOException e) { e.printStackTrace(); showError(MessageBundle.get("resources.open.error.multiple")); } }
From source file:VOBackupFile.java
/** * Wrapper for metadata of backuped file. * * @param file backuped file/*from w w w. j av a 2 s . c o m*/ */ public VOBackupFile(File file) { this.path = file.getAbsolutePath(); this.directory = file.isDirectory(); this.symLink = Files.isSymbolicLink(file.toPath()); this.size = ((file.isDirectory() || symLink) ? 0 : file.length()); this.modify = new Date(file.lastModified()); if (symLink) { try { symlinkTarget = Files.readSymbolicLink(file.toPath()).toString(); } catch (IOException e) { e.printStackTrace(); //TODO Lebeda - oetit do logu } } else { // advanced attributes try { owner = Files.getOwner(file.toPath(), LinkOption.NOFOLLOW_LINKS).getName(); if (Files.getFileStore(file.toPath()).supportsFileAttributeView(DosFileAttributeView.class)) { dosAttr = Boolean.TRUE; final DosFileAttributes dosFileAttributes = Files.readAttributes(file.toPath(), DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS); dosArchive = dosFileAttributes.isArchive(); dosHidden = dosFileAttributes.isHidden(); dosSystem = dosFileAttributes.isSystem(); dosReadOnly = dosFileAttributes.isReadOnly(); } else { dosAttr = Boolean.FALSE; } if (Files.getFileStore(file.toPath()).supportsFileAttributeView(PosixFileAttributeView.class)) { posixAttr = Boolean.TRUE; final PosixFileAttributes posixFileAttributes = Files.readAttributes(file.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS); posixGroup = posixFileAttributes.group().getName(); posixPermitions = PosixFilePermissions.toString(posixFileAttributes.permissions()); } else { posixAttr = Boolean.FALSE; } } catch (IOException e) { e.printStackTrace(); //Todo implementovat } } }
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 *///from w w w.j a va 2 s. co m 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:org.apache.pulsar.io.file.FileSourceConfig.java
public void validate() { if (StringUtils.isBlank(inputDirectory)) { throw new IllegalArgumentException("Required property not set."); } else if (Files.notExists(Paths.get(inputDirectory), LinkOption.NOFOLLOW_LINKS)) { throw new IllegalArgumentException("Specified input directory does not exist"); } else if (!Files.isReadable(Paths.get(inputDirectory))) { throw new IllegalArgumentException("Specified input directory is not readable"); } else if (Optional.ofNullable(keepFile).orElse(false) && !Files.isWritable(Paths.get(inputDirectory))) { throw new IllegalArgumentException("You have requested the consumed files to be deleted, but the " + "source directory is not writeable."); }/*from w w w . jav a 2s . c om*/ if (StringUtils.isNotBlank(fileFilter)) { try { Pattern.compile(fileFilter); } catch (final PatternSyntaxException psEx) { throw new IllegalArgumentException("Invalid Regex pattern provided for fileFilter"); } } if (minimumFileAge != null && Math.signum(minimumFileAge) < 0) { throw new IllegalArgumentException("The property minimumFileAge must be non-negative"); } if (maximumFileAge != null && Math.signum(maximumFileAge) < 0) { throw new IllegalArgumentException("The property maximumFileAge must be non-negative"); } if (minimumSize != null && Math.signum(minimumSize) < 0) { throw new IllegalArgumentException("The property minimumSize must be non-negative"); } if (maximumSize != null && Math.signum(maximumSize) < 0) { throw new IllegalArgumentException("The property maximumSize must be non-negative"); } if (pollingInterval != null && pollingInterval <= 0) { throw new IllegalArgumentException("The property pollingInterval must be greater than zero"); } if (numWorkers != null && numWorkers <= 0) { throw new IllegalArgumentException("The property numWorkers must be greater than zero"); } }
From source file:org.codice.ddf.configuration.migration.ExportMigrationEntryImpl.java
/** * Instantiates a new migration entry given a migratable context and path. * * <p><i>Note:</i> In this version of the constructor, the path is either absolute or assumed to * be relative to ${ddf.home}. It will also be automatically relativized to ${ddf.home}. * * @param context the migration context associated with this entry * @param path the path for this entry//from www . j ava2 s .c o m * @throws IllegalArgumentException if <code>context</code> or <code>path</code> is <code>null * </code> */ protected ExportMigrationEntryImpl(ExportMigrationContextImpl context, Path path) { Validate.notNull(context, "invalid null context"); Validate.notNull(path, "invalid null path"); Path apath; Exception aerror; try { // make sure it is resolved against ddf.home and not the current working directory apath = AccessUtils.doPrivileged(() -> { final Path p = context.getPathUtils().resolveAgainstDDFHome(path) .toRealPath(LinkOption.NOFOLLOW_LINKS); this.isFile = p.toFile().isFile(); return p; }); aerror = null; } catch (IOException e) { apath = path; this.isFile = true; // since we can't find an absolute path on disk, we got to assume it's a file // remember the error in case the migratable attempts to store the file from disk later // instead of providing its own data aerror = e; } this.context = context; this.absolutePath = apath; this.absolutePathError = aerror; this.path = context.getPathUtils().relativizeFromDDFHome(apath); this.file = apath.toFile(); // we keep the entry name in Unix style based on our convention this.name = FilenameUtils.separatorsToUnix(this.path.toString()); }