java.nio.file.LinkOption Java Examples

The following examples show how to use java.nio.file.LinkOption. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuditMessage.java    From deprecated-security-advanced-modules with Apache License 2.0 6 votes vote down vote up
public void addFileInfos(Map<String, Path> paths) {
    if (paths != null && !paths.isEmpty()) {
        List<Object> infos = new ArrayList<>();
        for(Entry<String, Path> path: paths.entrySet()) {

            try {
                if(Files.isReadable(path.getValue())) {
                    final String chcksm = DigestUtils.sha256Hex(Files.readAllBytes(path.getValue()));
                    FileTime lm = Files.getLastModifiedTime(path.getValue(), LinkOption.NOFOLLOW_LINKS);
                    Map<String, Object> innerInfos = new HashMap<>();
                    innerInfos.put("sha256", chcksm);
                    innerInfos.put("last_modified", formatTime(lm.toMillis()));
                    innerInfos.put("key", path.getKey());
                    innerInfos.put("path", path.getValue().toAbsolutePath().toString());
                    infos.add(innerInfos);
                }
            } catch (Throwable e) {
                //ignore non readable files
            }
        }
        auditInfo.put(COMPLIANCE_FILE_INFOS, infos);
    }
}
 
Example #2
Source File: BundleFileSystemProvider.java    From incubator-taverna-language with Apache License 2.0 6 votes vote down vote up
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path,
		Class<V> type, LinkOption... options) {
	BundleFileSystem fs = (BundleFileSystem) path.getFileSystem();
	if (path.toAbsolutePath().equals(fs.getRootDirectory())) {
		// Bug in ZipFS, it will fall over as there is no entry for /
		//
		// Instead we'll just give a view of the source (e.g. the zipfile
		// itself).
		// Modifying its times is a bit futile since they are likely to be
		// overriden when closing, but this avoids a NullPointerException
		// in Files.setTimes().
		return Files.getFileAttributeView(fs.getSource(), type, options);
	}
	return origProvider(path).getFileAttributeView(fs.unwrap(path), type,
			options);
}
 
Example #3
Source File: HaloUtils.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 获取文件创建时间
 *
 * @param srcPath 文件绝对路径
 *
 * @return 时间
 */
public static Date getCreateTime(String srcPath) {
    final Path path = Paths.get(srcPath);
    final BasicFileAttributeView basicview = Files.getFileAttributeView(path, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
    BasicFileAttributes attr;
    try {
        attr = basicview.readAttributes();
        final Date createDate = new Date(attr.creationTime().toMillis());
        return createDate;
    } catch (Exception e) {
        e.printStackTrace();
    }
    final Calendar cal = Calendar.getInstance();
    cal.set(1970, 0, 1, 0, 0, 0);
    return cal.getTime();
}
 
Example #4
Source File: SymbolicLinkHelper.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the last modified time for a symbolic link.
 *
 * Note: symbolic links are not followed (NOFOLLOW_LINKS LinkOption)
 *
 * @param link the path to the symbolic link
 * @return last modified time of the symbolic link
 */
public static long getLastModifiedTime(String link) {
  if (nonNull(link)) {
    try {
      Path linkPath = Paths.get(link);
      if (nonNull(linkPath)) {
        FileTime fileTimeObject = Files.getLastModifiedTime(linkPath, LinkOption.NOFOLLOW_LINKS);
        if (nonNull(fileTimeObject)) {
          return fileTimeObject.toMillis();
        }
      }
    // p4ic4idea: Do not catch throwable unless you're really careful
    //} catch (Throwable thr) {
    } catch (Exception thr) {
      Log.error("Unexpected exception invoking method: %s", thr.getLocalizedMessage());
      Log.exception(thr);
    }
  }
  return 0L;
}
 
Example #5
Source File: Main.java    From Java-Coding-Problems with MIT License 6 votes vote down vote up
public static void main(String[] args) throws IOException {

        Path path = Paths.get("/learning/packt", "JavaModernChallenge.pdf");

        String pathToString = path.toString();
        System.out.println("Path to String: " + pathToString);

        URI pathToURI = path.toUri();
        System.out.println("Path to URI: " + pathToURI);

        Path pathToAbsolutePath = path.toAbsolutePath();
        System.out.println("Path to absolute path: " + pathToAbsolutePath);

        Path path2 = Paths.get("/learning/books/../PACKT/./", "JavaModernChallenge.pdf");
        Path realPath = path2.toRealPath(LinkOption.NOFOLLOW_LINKS);
        System.out.println("Path to 'real' path: " + realPath);

        File pathToFile = path.toFile();
        Path fileToPath = pathToFile.toPath();
        System.out.println("Path to file name: " + pathToFile.getName());
        System.out.println("File to path: " + fileToPath);
    }
 
Example #6
Source File: DefaultOpenDistroSecurityKeyStore.java    From deprecated-security-ssl with Apache License 2.0 6 votes vote down vote up
private static void checkPath(String keystoreFilePath, String fileNameLogOnly) {

        if (keystoreFilePath == null || keystoreFilePath.length() == 0) {
            throw new ElasticsearchException("Empty file path for " + fileNameLogOnly);
        }

        if (Files.isDirectory(Paths.get(keystoreFilePath), LinkOption.NOFOLLOW_LINKS)) {
            throw new ElasticsearchException(
                    "Is a directory: " + keystoreFilePath + " Expected a file for " + fileNameLogOnly);
        }

        if (!Files.isReadable(Paths.get(keystoreFilePath))) {
            throw new ElasticsearchException("Unable to read " + keystoreFilePath + " (" + Paths.get(keystoreFilePath)
                    + "). Please make sure this files exists and is readable regarding to permissions. Property: "
                    + fileNameLogOnly);
        }
    }
 
Example #7
Source File: WatchmanFileWatcher.java    From mirror with Apache License 2.0 6 votes vote down vote up
private void readSymlinkTarget(Update.Builder ub) {
  try {
    Path path = ourRoot.resolve(ub.getPath());
    Path symlink = Files.readSymbolicLink(path);
    String targetPath;
    if (symlink.isAbsolute()) {
      targetPath = path.getParent().normalize().relativize(symlink.normalize()).toString();
    } else {
      // the symlink is already relative, so we can leave it alone, e.g. foo.txt
      targetPath = symlink.toString();
    }
    ub.setSymlink(targetPath);
    // Ensure our modtime is of the symlink itself (I'm not actually
    // sure which modtime watchman sends back, but this is safest).
    ub.setModTime(Files.getLastModifiedTime(path, LinkOption.NOFOLLOW_LINKS).toMillis());
  } catch (IOException e) {
    // ignore as the file probably disappeared
    log.debug("Exception reading symlink, assumed stale", e);
  }
}
 
Example #8
Source File: PathFileObject.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean isNameCompatible(String simpleName, Kind kind) {
    simpleName.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String sn = simpleName + kind.extension;
    String pn = path.getFileName().toString();
    if (pn.equals(sn)) {
        return true;
    }
    if (pn.equalsIgnoreCase(sn)) {
        try {
            // allow for Windows
            return path.toRealPath(LinkOption.NOFOLLOW_LINKS).getFileName().toString().equals(sn);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example #9
Source File: MigrationService.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
private String getM3model(MavenLibrary lib) throws Exception {
	// TODO CHECK HERE
	Artifact v1 = downloader.downloadArtifactTo(
			new DefaultArtifact(
					String.format("%s:%s:%s", lib.getGroupid(), lib.getArtifactid(), lib.getVersion())),
			mavenRepoPath);
	lib.setArtifact(v1);
	String libM3 = lib.getArtifact().getFile().getAbsolutePath() + ".m3";
	if (!Files.exists(Paths.get(libM3), new LinkOption[] { LinkOption.NOFOLLOW_LINKS })) {
		String libJar = lib.getArtifact().getFile().getAbsolutePath();
		boolean bLib1 = maracas.storeM3(libJar, libM3);
		logger.info("Lib1 store: " + bLib1);
		if (!bLib1) {
			logger.error("error computing {} m3 model", lib.getCoordinate());
			throw new Exception();
		}
	}
	return libM3;
}
 
Example #10
Source File: PasswordFile.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Create password file to be written with access permissions to read
 * and write by user only.
 * <p/>
 * @return Value of <code>true</code> if new file was created
 *         or <code>false</code> otherwise
 */
private boolean createFilePosix() {
    final String METHOD = "createFilePosix";
    boolean success = false;
    try {
        if (Files.notExists(file, new LinkOption[0])) {
            Files.createFile(file, PosixFilePermissions
                    .asFileAttribute(CREATE_FILE_PERMISSIONS));
            success = true;
        } else {
            Files.setPosixFilePermissions(file, CREATE_FILE_PERMISSIONS);
            LOGGER.log(Level.INFO, METHOD, "exists", file.toString());
        }
    } catch (UnsupportedOperationException uoe) {
        LOGGER.log(Level.INFO, METHOD, "unsupported", file.toString());
    } catch (FileAlreadyExistsException faee) {
        LOGGER.log(Level.INFO, METHOD, "exists", file.toString());
    } catch (IOException ioe) {
        LOGGER.log(Level.INFO, METHOD, "ioException", ioe);
    }
    return success;
}
 
Example #11
Source File: SFTPFileSystemTest.java    From sftp-fs with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadAttributesFileNoFollowLinks() throws IOException {
    Path foo = addFile("/foo");
    setContents(foo, new byte[1024]);

    PosixFileAttributes attributes = fileSystem.readAttributes(createPath("/foo"), LinkOption.NOFOLLOW_LINKS);

    assertEquals(Files.size(foo), attributes.size());
    assertNotNull(attributes.owner().getName());
    assertNotNull(attributes.group().getName());
    assertNotNull(attributes.permissions());
    assertFalse(attributes.isDirectory());
    assertTrue(attributes.isRegularFile());
    assertFalse(attributes.isSymbolicLink());
    assertFalse(attributes.isOther());
}
 
Example #12
Source File: RecursiveDeleteOnExitHook.java    From SonarPet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    // NOTE: Iterate backwards so last added is first deleted
    // For some reason this is important (see JDK DeleteOnExitHook(
    for (int i = toDelete.size() - 1; i >= 0; i--) {
        Path target = toDelete.get(i);
        try {
            if (Files.isDirectory(target, LinkOption.NOFOLLOW_LINKS)) {
                Files.walkFileTree(target, new RecursiveDirectoryDeleter());
            } else {
                Files.deleteIfExists(target);
            }
        } catch (IOException e) {
            //noinspection UseOfSystemOutOrSystemErr - VM is shutting down
            System.err.println("Unable to delete " + toDelete + ": " + e);
        }
    }
}
 
Example #13
Source File: SymbolicLinkHelper.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the last modified time for a symbolic link.
 *
 * Note: symbolic links are not followed (NOFOLLOW_LINKS LinkOption)
 *
 * @param link the path to the symbolic link
 * @return last modified time of the symbolic link
 */
public static long getLastModifiedTime(String link) {
  if (nonNull(link)) {
    try {
      Path linkPath = Paths.get(link);
      if (nonNull(linkPath)) {
        FileTime fileTimeObject = Files.getLastModifiedTime(linkPath, LinkOption.NOFOLLOW_LINKS);
        if (nonNull(fileTimeObject)) {
          return fileTimeObject.toMillis();
        }
      }
    } catch (Throwable thr) {
      Log.error("Unexpected exception invoking method: %s", thr.getLocalizedMessage());
      Log.exception(thr);
    }
  }
  return 0L;
}
 
Example #14
Source File: FileUtils.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("try")
private static boolean hasClassFile(
    final String path, final Set<File> sourceRoots, final File out) throws IOException {

  try (TelemetryUtils.ScopedSpan scope =
      TelemetryUtils.startScopedSpan("FileUtils.hasClassFile")) {
    TelemetryUtils.ScopedSpan.addAnnotation(
        TelemetryUtils.annotationBuilder()
            .put("sourceRoot", sourceRoots.toString())
            .put("out", out.getPath())
            .build("args"));
    final String outPath = out.getCanonicalPath();
    for (final File rootFile : sourceRoots) {
      final String root = rootFile.getCanonicalPath();
      if (path.startsWith(root)) {
        final String src = path.substring(root.length());
        final String classFile = StringUtils.replace(src, JAVA_EXT, CLASS_EXT);
        final Path p = Paths.get(outPath, classFile);
        return Files.exists(p, LinkOption.NOFOLLOW_LINKS);
      }
    }
    return false;
  }
}
 
Example #15
Source File: FileUtils.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("try")
public static Optional<File> getClassFile(
    String path, final Set<File> sourceRoots, final File out) throws IOException {

  try (TelemetryUtils.ScopedSpan scope =
      TelemetryUtils.startScopedSpan("FileUtils.getClassFile")) {
    TelemetryUtils.ScopedSpan.addAnnotation(
        TelemetryUtils.annotationBuilder()
            .put("sourceRoot", sourceRoots.toString())
            .put("out", out.getPath())
            .build("args"));
    String outPath = out.getCanonicalPath();
    for (File rootFile : sourceRoots) {
      final String root = rootFile.getCanonicalPath();
      if (path.startsWith(root)) {
        final String src = path.substring(root.length());
        final String classFile = StringUtils.replace(src, JAVA_EXT, CLASS_EXT);
        final Path p = Paths.get(outPath, classFile);
        if (Files.exists(p, LinkOption.NOFOLLOW_LINKS)) {
          return Optional.of(p.toFile());
        }
      }
    }
    return Optional.empty();
  }
}
 
Example #16
Source File: SFTPFileSystemTest.java    From sftp-fs with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadAttributesSymLinkToDirectoryFollowLinks() throws IOException {
    Path foo = addDirectory("/foo");
    addSymLink("/bar", foo);

    PosixFileAttributes attributes = fileSystem.readAttributes(createPath("/bar"));

    long sizeOfFoo = Files.readAttributes(foo, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS).size();

    // on Windows, foo and bar have the same sizes
    assertEquals(sizeOfFoo, attributes.size());
    assertNotNull(attributes.owner().getName());
    assertNotNull(attributes.group().getName());
    assertNotNull(attributes.permissions());
    assertTrue(attributes.isDirectory());
    assertFalse(attributes.isRegularFile());
    assertFalse(attributes.isSymbolicLink());
    assertFalse(attributes.isOther());
}
 
Example #17
Source File: PollingWatchService.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
PollingWatchKey(Path dir, PollingWatchService watcher, Object fileKey)
    throws IOException
{
    super(dir, watcher);
    this.fileKey = fileKey;
    this.valid = true;
    this.tickCount = 0;
    this.entries = new HashMap<Path,CacheEntry>();

    // get the initial entries in the directory
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for (Path entry: stream) {
            // don't follow links
            long lastModified =
                Files.getLastModifiedTime(entry, LinkOption.NOFOLLOW_LINKS).toMillis();
            entries.put(entry.getFileName(), new CacheEntry(lastModified, tickCount));
        }
    } catch (DirectoryIteratorException e) {
        throw e.getCause();
    }
}
 
Example #18
Source File: FileProviderClasspath.java    From baratine with GNU General Public License v2.0 6 votes vote down vote up
@Override
public <A extends BasicFileAttributes> A readAttributes(Path path,
                                                        Class<A> type,
                                                        LinkOption... options)
                                                            throws IOException
{
  URL url = getURL(path);
  
  if (url == null) {
    throw new FileNotFoundException(L.l("{0} does not exist", path));
  }
  
  if (! type.equals(BasicFileAttributes.class)) {
    throw new UnsupportedOperationException(type.getName());
  }
  
  PathBase pathBase = (PathBase) path;
  
  return (A) new BasicFileAttributesImpl(pathBase.path(), url);
}
 
Example #19
Source File: FileUtilsTestWindows.java    From zip4j with Apache License 2.0 6 votes vote down vote up
private DosFileAttributeView mockDosFileAttributeView(Path path, boolean fileExists, DosFileAttributes dosFileAttributes) throws IOException {
  FileSystemProvider fileSystemProvider = mock(FileSystemProvider.class);
  FileSystem fileSystem = mock(FileSystem.class);
  DosFileAttributeView dosFileAttributeView = mock(DosFileAttributeView.class);

  when(fileSystemProvider.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS)).thenReturn(dosFileAttributes);
  when(path.getFileSystem()).thenReturn(fileSystem);
  when(fileSystemProvider.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS))
      .thenReturn(dosFileAttributeView);
  when(path.getFileSystem().provider()).thenReturn(fileSystemProvider);

  if (!fileExists) {
    doThrow(new IOException()).when(fileSystemProvider).checkAccess(path);
  }

  return dosFileAttributeView;
}
 
Example #20
Source File: BaseTestSupport.java    From termd with Apache License 2.0 5 votes vote down vote up
public static Path assertHierarchyTargetFolderExists(Path folder, LinkOption... options) throws IOException {
    if (Files.exists(folder, options)) {
        assertTrue("Target is an existing file instead of a folder: " + folder, Files.isDirectory(folder, options));
    } else {
        Files.createDirectories(folder);
    }

    return folder;
}
 
Example #21
Source File: CopyMoveVisitor.java    From copybara with Apache License 2.0 5 votes vote down vote up
CopyMoveVisitor(Path before, Path after, @Nullable PathMatcher pathMatcher, boolean overwrite, boolean isCopy) {
  this.before = before;
  this.after = after;
  this.pathMatcher = pathMatcher;
  this.isCopy = isCopy;
  if (overwrite) {
    moveMode = new CopyOption[]{LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING};
  } else {
    moveMode = new CopyOption[]{LinkOption.NOFOLLOW_LINKS};
  }
}
 
Example #22
Source File: FaultyFileSystem.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Object> readAttributes(Path file, String attributes, LinkOption... options)
    throws IOException
{
    triggerEx(file, "readAttributes");
    return Files.readAttributes(unwrap(file), attributes, options);
}
 
Example #23
Source File: CustomLauncherTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static String[] getLauncher() throws IOException {
    String platform = getPlatform();
    if (platform == null) {
        return null;
    }

    String launcher = TEST_SRC + File.separator + platform + "-" + ARCH +
                      File.separator + "launcher";

    final FileSystem FS = FileSystems.getDefault();
    Path launcherPath = FS.getPath(launcher);

    final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
                                Files.isReadable(launcherPath);
    if (!hasLauncher) {
        System.out.println("Launcher [" + launcher + "] does not exist. Skipping the test.");
        return null;
    }

    // It is impossible to store an executable file in the source control
    // We need to copy the launcher to the working directory
    // and set the executable flag
    Path localLauncherPath = FS.getPath(WORK_DIR, "launcher");
    Files.copy(launcherPath, localLauncherPath,
               StandardCopyOption.REPLACE_EXISTING,
               StandardCopyOption.COPY_ATTRIBUTES);
    if (!Files.isExecutable(localLauncherPath)) {
        Set<PosixFilePermission> perms = new HashSet<>(
            Files.getPosixFilePermissions(
                localLauncherPath,
                LinkOption.NOFOLLOW_LINKS
            )
        );
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        Files.setPosixFilePermissions(localLauncherPath, perms);
    }
    return new String[] {launcher, localLauncherPath.toAbsolutePath().toString()};
}
 
Example #24
Source File: FaultyFileSystem.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path file,
                                                            Class<V> type,
                                                            LinkOption... options)
{
    return Files.getFileAttributeView(unwrap(file), type, options);
}
 
Example #25
Source File: FaultyFileSystem.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String,Object> readAttributes(Path file, String attributes, LinkOption... options)
    throws IOException
{
    triggerEx(file, "readAttributes");
    return Files.readAttributes(unwrap(file), attributes, options);
}
 
Example #26
Source File: CustomLauncherTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String[] getLauncher() throws IOException {
    String platform = getPlatform();
    if (platform == null) {
        return null;
    }

    String launcher = TEST_SRC + File.separator + platform + "-" + ARCH +
                      File.separator + "launcher";

    final FileSystem FS = FileSystems.getDefault();
    Path launcherPath = FS.getPath(launcher);

    final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
                                Files.isReadable(launcherPath);
    if (!hasLauncher) {
        System.out.println("Launcher [" + launcher + "] does not exist. Skipping the test.");
        return null;
    }

    // It is impossible to store an executable file in the source control
    // We need to copy the launcher to the working directory
    // and set the executable flag
    Path localLauncherPath = FS.getPath(WORK_DIR, "launcher");
    Files.copy(launcherPath, localLauncherPath,
               StandardCopyOption.REPLACE_EXISTING,
               StandardCopyOption.COPY_ATTRIBUTES);
    if (!Files.isExecutable(localLauncherPath)) {
        Set<PosixFilePermission> perms = new HashSet<>(
            Files.getPosixFilePermissions(
                localLauncherPath,
                LinkOption.NOFOLLOW_LINKS
            )
        );
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        Files.setPosixFilePermissions(localLauncherPath, perms);
    }
    return new String[] {launcher, localLauncherPath.toAbsolutePath().toString()};
}
 
Example #27
Source File: FileSystemWatcher.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
private static void handleEvent(final WatchKeyHolder watchKeys, final WatchKey key)
    throws IOException {
  for (final WatchEvent<?> event : key.pollEvents()) {
    if (event.kind() == StandardWatchEventKinds.OVERFLOW) {
      continue;
    }

    final WatchEvent<Path> watchEvent = cast(event);
    Path path = watchKeys.get(key);
    if (path == null) {
      continue;
    }

    path = path.resolve(watchEvent.context());
    if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
      if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
        watchKeys.register(path);
      }
    } else {
      // Dispatch
      FileEvent fe = toEvent(watchEvent, path);
      if (fe != null) {
        Executor.getInstance().getEventBus().post(fe);
      }
    }
  }
}
 
Example #28
Source File: MCRFileSystemProvider.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options)
    throws IOException {
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(path);
    MCRStoredNode node = MCRFileSystemUtils.resolvePath(mcrPath);
    //must support BasicFileAttributeView
    if (type == BasicFileAttributes.class || type == MCRFileAttributes.class) {
        return (A) MCRBasicFileAttributeViewImpl.readAttributes(node);
    }
    return null;
}
 
Example #29
Source File: SessionContext.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public void loadSession() {

    if (Files.exists(propPath, LinkOption.NOFOLLOW_LINKS)) {
      try (InputStream is = Files.newInputStream(propPath, StandardOpenOption.READ)) {
        props.load(is);
      } catch (IOException ex) {
        logger.error(ex.getMessage(), ex);
      }
    }
  }
 
Example #30
Source File: DirectoryTools.java    From openjdk-systemtest with Apache License 2.0 5 votes vote down vote up
public static Path createTemporaryDirectory(Path directory) throws FileAlreadyExistsException, IOException{	
	// Create a path under the root
	Path qualifiedPath = directoryRoot.resolve(directory);
	
	// Check that it doesn't already exist
	if (Files.exists(qualifiedPath, LinkOption.NOFOLLOW_LINKS)) {
		throw new FileAlreadyExistsException(qualifiedPath.toString() + " already exists");
	}
	
	// Create the directory structure (creates missing parental directories)
	Files.createDirectories(qualifiedPath);	
	return qualifiedPath;	
}