All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.beijunyi.parallelgit.filesystem.io.GfsFileAttributes Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.beijunyi.parallelgit.filesystem.io;

import java.io.IOException;
import java.nio.file.attribute.*;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static com.beijunyi.parallelgit.filesystem.io.GfsFileAttributeView.*;

public abstract class GfsFileAttributes {

  public static class Basic implements BasicFileAttributes {

    private final FileTime lastModifiedTime;
    private final FileTime lastAccessTime;
    private final FileTime creationTime;
    private final boolean isRegularFile;
    private final boolean isDirectory;
    private final boolean isSymbolicLink;
    private final boolean isOther;
    private final long size;
    private final Object fileKey;

    private Basic(@Nonnull Map attributes) {
      lastModifiedTime = (FileTime) attributes.get(LAST_MODIFIED_TIME_NAME);
      lastAccessTime = (FileTime) attributes.get(LAST_ACCESS_TIME_NAME);
      creationTime = (FileTime) attributes.get(CREATION_TIME_NAME);
      isRegularFile = (boolean) attributes.get(IS_REGULAR_FILE_NAME);
      isDirectory = (boolean) attributes.get(IS_DIRECTORY_NAME);
      isSymbolicLink = (boolean) attributes.get(IS_SYMBOLIC_LINK_NAME);
      isOther = (boolean) attributes.get(IS_OTHER_NAME);
      size = (long) attributes.get(SIZE_NAME);
      fileKey = attributes.get(FILE_KEY_NAME);
    }

    Basic(@Nonnull GfsFileAttributeView view) throws IOException {
      this(view.readAttributes(BASIC_KEYS));
    }

    @Nonnull
    @Override
    public FileTime lastModifiedTime() {
      return lastModifiedTime;
    }

    @Nonnull
    @Override
    public FileTime lastAccessTime() {
      return lastAccessTime;
    }

    @Nonnull
    @Override
    public FileTime creationTime() {
      return creationTime;
    }

    @Override
    public boolean isRegularFile() {
      return isRegularFile;
    }

    @Override
    public boolean isDirectory() {
      return isDirectory;
    }

    @Override
    public boolean isSymbolicLink() {
      return isSymbolicLink;
    }

    @Override
    public boolean isOther() {
      return isOther;
    }

    @Override
    public long size() {
      return size;
    }

    @Nullable
    @Override
    public Object fileKey() {
      return fileKey;
    }
  }

  public static class Posix extends Basic implements PosixFileAttributes {

    private final UserPrincipal owner;
    private final GroupPrincipal group;
    private final Set permissions;

    @SuppressWarnings("unchecked")
    private Posix(@Nonnull Map attributes) {
      super(attributes);
      owner = (UserPrincipal) attributes.get(GfsFileAttributeView.Posix.OWNER_NAME);
      group = (GroupPrincipal) attributes.get(GfsFileAttributeView.Posix.GROUP_NAME);
      permissions = (Set) attributes.get(GfsFileAttributeView.Posix.PERMISSIONS_NAME);
    }

    Posix(@Nonnull GfsFileAttributeView view) throws IOException {
      this(view.readAttributes(POSIX_KEYS));
    }

    @Override
    public UserPrincipal owner() {
      return owner;
    }

    @Override
    public GroupPrincipal group() {
      return group;
    }

    @Override
    public Set permissions() {
      return permissions;
    }

  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy