Java 8 BasicFileAttributes - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 BasicFileAttributes class.

This code example shows how to use the following methods:creationTime, isDirectory, isOther, isRegularFile, isSymbolicLink
  private final boolean isRegularFile;
  private final boolean isSymbolicLink;
  private final long size;
 
  public FilePropsImpl(BasicFileAttributes attrs) {
    creationTime = attrs.creationTime().toMillis();
    lastModifiedTime = attrs.lastModifiedTime().toMillis();
    lastAccessTime = attrs.lastAccessTime().toMillis();
    isDirectory = attrs.isDirectory();
    isOther = attrs.isOther();
    isRegularFile = attrs.isRegularFile();
    isSymbolicLink = attrs.isSymbolicLink();
    size = attrs.size();
  } 
 
  @Override 
  public long creationTime() { 
    return creationTime;
  } 
 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:fileKey
   * Returns file "key" (e.g. inode) for the specified path  
   */ 
  private Object getKey(Path existing) throws IOException {
    BasicFileAttributeView view = Files.getFileAttributeView(existing, BasicFileAttributeView.class);
    BasicFileAttributes attributes = view.readAttributes();
    return attributes.fileKey();
  } 
 
  @Override 
  protected void onOpen(Path path, Object stream) throws IOException {
    Object key = getKey(path);
    synchronized (openFiles) { 
      Integer v = openFiles.get(key); 
      if (v != null) { 
        v = Integer.valueOf(v.intValue()+1); 
        openFiles.put(key, v); 
      } else { 
        openFiles.put(key, Integer.valueOf(1)); 
      } 
    } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:lastModifiedTime, size
	private int size;
	private MetaData metaData;
	 
	public File(Path path, BasicFileAttributes attr) {
		this(path.getParent().toString(), path.getFileName().toString(),
		new DateTime(attr.lastModifiedTime().toMillis()), (int) attr.size());
	} 
	 
	public File(String directory, String filename, DateTime modified, int size) {
		this.directory = directory;
		this.filename = filename;
		this.modified = modified;
		this.size = size;
	} 
 
	public String getDirectory() {
		return directory;
	} 
 
	public void setDirectory(String directory) {
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:lastModifiedTime, size
 
import com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent; 
import com.github.hakko.musiccabinet.domain.model.library.File; 
import com.github.hakko.musiccabinet.log.Logger; 
 
public class LibraryScanner extends SimpleFileVisitor<Path> {
 
	private static final Logger LOG = Logger.getLogger(LibraryScanner.class); 
 
	private Map<Path, DirectoryContent> map = new HashMap<>();
	 
	private PollableChannel libraryPresenceChannel;
	 
    public LibraryScanner(PollableChannel libraryPresenceChannel) {
		this.libraryPresenceChannel = libraryPresenceChannel;
	} 
 
	@Override 
    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
    	DirectoryContent parentContent = map.get(dir.getParent());

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:creationTime, fileKey, lastAccessTime, lastModifiedTime
 
    assertThat(view).isNotNull();
    assertThat(view.name()).isEqualTo("basic");
 
    BasicFileAttributes attrs = view.readAttributes();
    assertThat(attrs.fileKey()).isEqualTo(0);
 
    FileTime time = attrs.creationTime();
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(time);
 
    view.setTimes(null, null, null);
 
    attrs = view.readAttributes();
    assertThat(attrs.creationTime()).isEqualTo(time);
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(time);
 
    view.setTimes(FileTime.fromMillis(0L), null, null);
 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isDirectory
    return attr.size();
  } 
 
  @Override 
  public boolean isDirectory() { 
    return attr.isDirectory();
  } 
 
  @Override 
  public String getPath() {
    // no microsnot 
    return StringUtil2.replace(path.toString(), '\\', "/");
  } 
 
  @Override 
  public String getName() {
    return path.getFileName().toString();
  } 
 
  @Override 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isRegularFile
            Path startFrom = Paths.get(from.substring(0, idx));
            final String name = from.substring(idx + "**/".length());
            Files.walkFileTree(startFrom, new SimpleFileVisitor<Path>() {
                @Override 
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { 
                    if (attrs.isRegularFile() && file.endsWith(name)) { 
                        convert(file, file.getParent().resolve(to)); 
                        converted.add(file); 
                    } 
                    return CONTINUE; 
                } 
            }); 
        } else { 
            Path fromPath = Paths.get(from);
            Path toPath = Paths.get(to);
 
            convert(fromPath, toPath); 
            converted.add(fromPath); 
        } 
        return converted; 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:creationTime, lastAccessTime, lastModifiedTime
This code example shows how to use the following methods:fileKey, owner
 
    assertThat(view.name()).isEqualTo("posix");
    assertThat(view.getOwner()).isEqualTo(createUserPrincipal("user"));
 
    PosixFileAttributes attrs = view.readAttributes();
    assertThat(attrs.fileKey()).isEqualTo(0);
    assertThat(attrs.owner()).isEqualTo(createUserPrincipal("user"));
    assertThat(attrs.group()).isEqualTo(createGroupPrincipal("group"));
    assertThat(attrs.permissions()).isEqualTo(PosixFilePermissions.fromString("rw-r--r--"));
 
    view.setOwner(createUserPrincipal("root"));
    assertThat(view.getOwner()).isEqualTo(createUserPrincipal("root"));
    assertThat(file.getAttribute("owner", "owner")).isEqualTo(createUserPrincipal("root")); 
 
    view.setGroup(createGroupPrincipal("root"));
    assertThat(view.readAttributes().group()).isEqualTo(createGroupPrincipal("root"));
    assertThat(file.getAttribute("posix", "group")).isEqualTo(createGroupPrincipal("root")); 
 
    view.setPermissions(PosixFilePermissions.fromString("rwx------"));
    assertThat(view.readAttributes().permissions()).isEqualTo(
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:fileKey
		checkNotNull(pDir);
		checkNotNull(pAttrs);
		final WatchKey key = pDir.register(mWatcher, ENTRY_CREATE, ENTRY_DELETE,
				ENTRY_MODIFY);
		mKeys.put(key, pDir);
		if (mIdentifiers.get(pAttrs.fileKey()) == null) {
			mIdentifiers.put(pAttrs.fileKey(), new ArrayList<Path>());
		} 
		mIdentifiers.get(pAttrs.fileKey()).add(pDir);
		return FileVisitResult.CONTINUE;
	} 
 
	/** 
	 * Get mapping of {@link WatchService} to {@link Path} (for deletes). 
	 *  
	 * @return map instance 
	 */ 
	public Map<WatchKey, Path> getKeys() {
		return mKeys;
	} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 BasicFileAttributes Methods: