Java 类java.nio.file.attribute.BasicFileAttributeView 实例源码

项目:jmt    文件:TemplatePanel.java   
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    if (columnIndex == 0) {
        return templates[rowIndex].getName();
    } else if (columnIndex == 1) {
        return templates[rowIndex].getVersion();
    } else if (columnIndex == 2) {
        return templates[rowIndex].getShortDescription();
    } else if (columnIndex == 3) {
        Path temPath = Paths.get(templates[rowIndex].getFile().getAbsolutePath());
        try {
            BasicFileAttributes view = Files.getFileAttributeView(temPath, BasicFileAttributeView.class).readAttributes();
            FileTime creationTime = view.creationTime();
            DateFormat df = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
            String cTime = df.format(creationTime.toMillis());
            return cTime;
        } catch (IOException e) {
            return "--";
        }
    } else {
        return null;
    }
}
项目:mycore    文件:MCRFileSystemProvider.java   
@SuppressWarnings("unchecked")
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
    MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(path);
    if (type == null) {
        throw new NullPointerException();
    }
    //must support BasicFileAttributeView
    if (type == BasicFileAttributeView.class) {
        return (V) new BasicFileAttributeViewImpl(mcrPath);
    }
    if (type == MCRMD5AttributeView.class) {
        return (V) new MD5FileAttributeViewImpl(mcrPath);
    }
    return null;
}
项目:mycore    文件:MCRDirectoryStream.java   
@SuppressWarnings("unchecked")
@Override
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
    if (path != null) {
        MCRPath file = checkRelativePath(path);
        if (file.getNameCount() != 1) {
            throw new InvalidPathException(path.toString(), "'path' must have one name component.");
        }
    }
    checkClosed();
    if (type == null) {
        throw new NullPointerException();
    }
    //must support BasicFileAttributeView
    if (type == BasicFileAttributeView.class) {
        return (V) new BasicFileAttributeViewImpl(this, path);
    }
    if (type == MCRMD5AttributeView.class) {
        return (V) new MD5FileAttributeViewImpl(this, path);
    }
    return null;
}
项目:incubator-taverna-language    文件:RecursiveCopyFileVisitor.java   
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
        throws IOException {
    try {
        if (copyOptionsSet.contains(COPY_ATTRIBUTES)) {
            /*
             * Copy file times. Inspired by
             * java.nio.file.CopyMoveHelper.copyToForeignTarget()
             */
            BasicFileAttributes attrs = readAttributes(dir,
                    BasicFileAttributes.class, linkOptions);
            BasicFileAttributeView view = getFileAttributeView(
                    toDestination(dir), BasicFileAttributeView.class,
                    linkOptions);
            view.setTimes(attrs.lastModifiedTime(), attrs.lastAccessTime(),
                    attrs.creationTime());
        }
        return CONTINUE;
    } catch (IOException ex) {
        return visitFileFailed(dir, ex);
    }
}
项目:ignite    文件:LocalIgfsSecondaryFileSystem.java   
/** {@inheritDoc} */
@Override public void setTimes(IgfsPath path, long modificationTime, long accessTime) throws IgniteException {
    Path p = fileForPath(path).toPath();

    if (!Files.exists(p))
        throw new IgfsPathNotFoundException("Failed to set times (path not found): " + path);

    try {
        Files.getFileAttributeView(p, BasicFileAttributeView.class)
            .setTimes(
                (modificationTime >= 0) ? FileTime.from(modificationTime, TimeUnit.MILLISECONDS) : null,
                (accessTime >= 0) ? FileTime.from(accessTime, TimeUnit.MILLISECONDS) : null,
                null);
    }
    catch (IOException e) {
        throw new IgniteException("Failed to set times for path: " + path, e);
    }
}
项目:ignite    文件:LocalFileSystemUtils.java   
/**
 * Get POSIX attributes for file.
 *
 * @param file File.
 * @return BasicFileAttributes.
 */
@Nullable public static BasicFileAttributes basicAttributes(File file) {
    BasicFileAttributes attrs = null;

    try {
        BasicFileAttributeView view = Files.getFileAttributeView(file.toPath(), BasicFileAttributeView.class);

        if (view != null)
            attrs = view.readAttributes();
    }
    catch (IOException e) {
        throw new IgfsException("Failed to read basic file attributes: " + file.getAbsolutePath(), e);
    }

    return attrs;
}
项目:tinyMediaManager    文件:FSTest.java   
private Set<String> getSupportedFileAttributes(FileStore fs) {
  Set<String> attrs = new HashSet<String>();
  if (fs.supportsFileAttributeView(AclFileAttributeView.class)) {
    attrs.add("acl");
  }
  if (fs.supportsFileAttributeView(BasicFileAttributeView.class)) {
    attrs.add("basic");
  }
  if (fs.supportsFileAttributeView(FileOwnerAttributeView.class)) {
    attrs.add("owner");
  }
  if (fs.supportsFileAttributeView(UserDefinedFileAttributeView.class)) {
    attrs.add("user");
  }
  if (fs.supportsFileAttributeView(DosFileAttributeView.class)) {
    attrs.add("dos");
  }
  if (fs.supportsFileAttributeView(PosixFileAttributeView.class)) {
    attrs.add("posix");
  }
  if (fs.supportsFileAttributeView(FileAttributeView.class)) {
    attrs.add("file");
  }
  return attrs;
}
项目:ephemeralfs    文件:AttributeLookup.java   
public boolean supportsFileAttributeView(
        Class<? extends FileAttributeView> type) {

    String name = "notFound";
    if(type == BasicFileAttributeView.class) {
        name = "basic";
    } else if(type == DosFileAttributeView.class) {
        name = "dos";
    } else if(type == PosixFileAttributeView.class) {
        name = "posix";
    } else if(type == FileOwnerAttributeView.class) {
        name = "owner";
    }

    return  attributeSets.containsKey(name);
}
项目:ephemeralfs    文件:BasicFileAttributesTest.java   
@Test
public void testSetLastModifiedTimeAfterMove() throws Exception {
    Path path = root.resolve("test");
    Files.createFile(path);
    BasicFileAttributeView view = Files.getFileAttributeView(path, BasicFileAttributeView.class);

    Path movedTo = root.resolve("test2");
    Files.move(path, movedTo);
    long newModified = roundToSeconds(System.currentTimeMillis()) - 10000;

    try {
        view.setTimes(FileTime.fromMillis(newModified), null, null);
        fail();
    } catch (NoSuchFileException e) {
        //pass
    }

}
项目:ephemeralfs    文件:DirectoryWalkTest.java   
@Test
public void testGetAttributesThenMoveFile() throws Exception {
    long start = System.currentTimeMillis();
    Path parent = root.resolve("test");
    Files.createFile(parent);
    BasicFileAttributeView attributes = Files.getFileAttributeView(parent, BasicFileAttributeView.class);
    assertTrue(attributes.readAttributes().creationTime().toMillis() > start - 6000);
    Files.move(parent, parent.resolveSibling("test2"));
    try
    {
        attributes.readAttributes();
        fail();
    } catch(NoSuchFileException e) {
        //pass
    }

}
项目:kurento-module-creator    文件:PathTemplateLoader.java   
@Override
public long getLastModified(final Object templateSource) {

  Path templateAsPath = (Path) templateSource;
  BasicFileAttributeView basicView = Files.getFileAttributeView(templateAsPath,
      BasicFileAttributeView.class);

  // This attribute view is perhaps not available in this system
  if (basicView != null) {

    BasicFileAttributes basic;
    try {
      basic = basicView.readAttributes();
    } catch (IOException e) {
      return -1;
    }

    return basic.lastModifiedTime().toMillis();

  } else {
    return -1;
  }
}
项目:eightyfs    文件:EightyProvider.java   
@Override
public
@Nullable
DirectoryStream<Path> newDirectoryStream( @Nullable Path dirArg, @Nullable DirectoryStream.Filter<? super Path> filter ) throws IOException {
    EightyPath nnDir = checkProvider( dirArg );
    EightyPath dir = toRealPath( nnDir );

    if( !Files.exists( dir ) ) {
        throw new NoSuchFileException( "dir " + dir + " does not exist" );
    }

    // todo set time now or after close ?
    FileTime now = FileTime.from( Clock.systemUTC().instant() );

    if( !dir._getFileSystem().isReadOnly() ) {
        Files.getFileAttributeView( dirArg, BasicFileAttributeView.class ).setTimes( null, now, null );
    }

    // todo: test for throw

    return dir._getFileSystem().addClosable( new EightyDirectoryStream(
            dirArg,
            dir._getFileSystem().get80().newDirectoryStream( dir ),
            _n1( filter ) ) );
}
项目:eightyfs    文件:EightyProvider.java   
@Override
public void createDirectory( @Nullable Path dirArg, @Nullable FileAttribute<?>... attrs ) throws IOException {
    EightyFS eighty = checkProviderAndGet80( dirArg );
    EightyPath dir = toRealPathEx( (EightyPath) _n0( dirArg ), NOFOLLOW_LINKS );

    if( existsEx( dir, NOFOLLOW_LINKS ) ) {
        throw new FileAlreadyExistsException( dir.toString() );
    }

    // an absolute path (toRealPath) that does not exist has a parent
    EightyPath parent = childGetParent( dir );

    if( !Files.isDirectory( parent ) ) {
        throw new NoSuchFileException( parent.toString() );
    }

    throwIfPathIsNotAccessible( dir );

    eighty.createDirectory( dir, _nargs( attrs ) );

    FileTime now = FileTime.from( Clock.systemUTC().instant() );
    Files.getFileAttributeView( parent, BasicFileAttributeView.class ).setTimes( now, now, null );

    parent._getFileSystem().signal( dir, StandardWatchEventKinds.ENTRY_CREATE );
}
项目:eightyfs    文件:RWAttributesBuilder.java   
public RWAttributesBuilder addBasic() {
    attributes( "basic", BasicFileAttributeView.class, BasicFileAttributes.class ).
            attribute( LAST_MODIFIED_TIME_NAME,
                       BasicFileAttributes::lastModifiedTime,
                       u( ( ( view, val ) -> view.setTimes( (FileTime) val, null, null ) ) ) ).
            attribute( LAST_ACCESS_TIME_NAME,
                       BasicFileAttributes::lastAccessTime,
                       u( ( view, val ) -> view.setTimes( null, (FileTime) val, null ) ) ).
            attribute( SIZE_NAME, BasicFileAttributes::size ).
            attribute( CREATION_TIME_NAME, BasicFileAttributes::creationTime,
                       u( ( view, val ) -> view.setTimes( null, null, (FileTime) val ) ) ).
            attribute( FILE_KEY_NAME, BasicFileAttributes::fileKey ).
            attribute( IS_DIRECTORY_NAME, BasicFileAttributes::isDirectory ).
            attribute( IS_REGULAR_FILE_NAME, BasicFileAttributes::isRegularFile ).
            attribute( IS_OTHER_NAME, BasicFileAttributes::isOther ).
            attribute( IS_SYMBOLIC_LINK_NAME, BasicFileAttributes::isSymbolicLink )
    ;

    return this;
}
项目:jsr203-hadoop    文件:TestFileStore.java   
@Test
public void testFileStore() throws URISyntaxException, IOException {
  URI uri = clusterUri.resolve("/tmp/testFileStore");
  Path path = Paths.get(uri);
  if (Files.exists(path))
    Files.delete(path);
  assertFalse(Files.exists(path));
  Files.createFile(path);
  assertTrue(Files.exists(path));
  FileStore st = Files.getFileStore(path);
  assertNotNull(st);
  Assert.assertNotNull(st.name());
  Assert.assertNotNull(st.type());

  Assert.assertFalse(st.isReadOnly());

  Assert.assertNotEquals(0, st.getTotalSpace());
  Assert.assertNotEquals(0, st.getUnallocatedSpace());
  Assert.assertNotEquals(0, st.getUsableSpace());

  Assert
      .assertTrue(st.supportsFileAttributeView(BasicFileAttributeView.class));
  Assert.assertTrue(st.supportsFileAttributeView("basic"));

  st.getAttribute("test");
}
项目:jsr203-hadoop    文件:TestFileStore.java   
/**
 * Test: File and FileStore attributes
 */
@Test
public void testFileStoreAttributes() throws URISyntaxException, IOException {
  URI uri = clusterUri.resolve("/tmp/testFileStore");
  Path path = Paths.get(uri);
  if (Files.exists(path))
    Files.delete(path);
  assertFalse(Files.exists(path));
  Files.createFile(path);
  assertTrue(Files.exists(path));
  FileStore store1 = Files.getFileStore(path);
  assertNotNull(store1);
  assertTrue(store1.supportsFileAttributeView("basic"));
  assertTrue(store1.supportsFileAttributeView(BasicFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("posix") == store1
      .supportsFileAttributeView(PosixFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("dos") == store1
      .supportsFileAttributeView(DosFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("acl") == store1
      .supportsFileAttributeView(AclFileAttributeView.class));
  assertTrue(store1.supportsFileAttributeView("user") == store1
      .supportsFileAttributeView(UserDefinedFileAttributeView.class));
}
项目:jsr203-hadoop    文件:TestFiles.java   
/**
 * Test 'basic' file view support.
 * 
 * @throws IOException
 */
@Test
public void testGetBasicFileAttributeView() throws IOException {
  Path rootPath = Paths.get(clusterUri);

  assertTrue(rootPath.getFileSystem().supportedFileAttributeViews()
      .contains("basic"));

  // Get root view
  BasicFileAttributeView view = Files.getFileAttributeView(rootPath,
      BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);

  assertNotNull(view);
  assertNotNull(view.readAttributes());
  assertNotNull(view.readAttributes().lastModifiedTime());
}
项目:niotest    文件:Tests06Attributes.java   
@Test
@Category( Attributes.class )
public void testGetLastModifiedAllMethodsDeliverSame() throws IOException {

    Path path = getFile();

    FileTime last0 = Files.getLastModifiedTime( path );
    FileTime last1 = FS.provider().readAttributes( path, BasicFileAttributes.class ).lastModifiedTime();
    FileTime last2 = (FileTime) FS.provider().readAttributes( path, "basic:lastModifiedTime" ).get( "lastModifiedTime" );
    FileTime last3 = FS.provider().getFileAttributeView( path, BasicFileAttributeView.class ).readAttributes().lastModifiedTime();

    assertThat( last0 ).isEqualTo( last1 );
    assertThat( last1 ).isEqualTo( last2 );
    assertThat( last2 ).isEqualTo( last3 );
    assertThat( last3 ).isEqualTo( last0 );
}
项目:wildfly-core    文件:PathUtil.java   
private static void unzip(final ZipFile zip, final Path targetDir) throws IOException {
    final Enumeration<? extends ZipEntry> entries = zip.entries();
    while (entries.hasMoreElements()) {
        final ZipEntry entry = entries.nextElement();
        final String name = entry.getName();
        final Path current = targetDir.resolve(name);
        if (entry.isDirectory()) {
            if (!Files.exists(current)) {
                Files.createDirectories(current);
            }
        } else {
            if (Files.notExists(current.getParent())) {
                Files.createDirectories(current.getParent());
            }
            try (final InputStream eis = zip.getInputStream(entry)) {
                Files.copy(eis, current);
            }
        }
        try {
            Files.getFileAttributeView(current, BasicFileAttributeView.class).setTimes(entry.getLastModifiedTime(), entry.getLastAccessTime(), entry.getCreationTime());
        } catch (IOException e) {
            //ignore, if we cannot set it, world will not end
        }
    }
}
项目:ocpjp    文件:WorkingBasicFileAttributes.java   
public static void main( String[] args )
        throws IOException {

    Path atxt = Paths.get( "a.txt" );
    BasicFileAttributes basic = Files.readAttributes( atxt , BasicFileAttributes.class );
    FileTime creationTime = basic.creationTime();
    FileTime lastAccessTime = basic.lastAccessTime();
    FileTime lastModifiedTime = basic.lastModifiedTime();
    mostrar( creationTime , lastAccessTime , lastModifiedTime , basic );

    System.out.println( "\nsetando os atributos de a.txt para a_copy.txt" );
    Path aCopy = Paths.get( "a_copy.txt" );
    BasicFileAttributeView basicView = Files.getFileAttributeView( aCopy ,
                                                                   BasicFileAttributeView.class );
    basicView.setTimes( lastModifiedTime , lastAccessTime , creationTime );
    basic = Files.readAttributes( aCopy , BasicFileAttributes.class );
    creationTime = basic.creationTime();
    lastAccessTime = basic.lastAccessTime();
    lastModifiedTime = basic.lastModifiedTime();
    mostrar( creationTime , lastAccessTime , lastModifiedTime , basic );
}
项目:mev    文件:CCCPHelpers.java   
public static FileTime getModDate (Path path) throws IOException {
  BasicFileAttributeView basicView =Files.getFileAttributeView (path, BasicFileAttributeView.class,LinkOption.NOFOLLOW_LINKS);
  if (basicView != null) {
    BasicFileAttributes basic = basicView.readAttributes (); // Get the
                                                             // attributes
                                                             // of the view

    FileTime result = basic.lastModifiedTime ();
    if (result == null)
      throw new IOException ("Attribute lastModifiedTime() is not suupported on file: " + path);
    else {
      if (log.isDebugEnabled ())
        log.debug ("File " + path + "last modified at  : " + result);
      return result;

    }

  } else {
    throw new IOException ("File not found: " + path);
  }

}
项目:jimfs    文件:AttributeServiceTest.java   
@SuppressWarnings("ConstantConditions")
@Test
public void testGetFileAttributeView() throws IOException {
  final File file = Directory.create(0);
  service.setInitialAttributes(file);

  FileLookup fileLookup =
      new FileLookup() {
        @Override
        public File lookup() throws IOException {
          return file;
        }
      };

  assertThat(service.getFileAttributeView(fileLookup, TestAttributeView.class)).isNotNull();
  assertThat(service.getFileAttributeView(fileLookup, BasicFileAttributeView.class)).isNotNull();

  TestAttributes attrs =
      service.getFileAttributeView(fileLookup, TestAttributeView.class).readAttributes();
  assertThat(attrs.foo()).isEqualTo("hello");
  assertThat(attrs.bar()).isEqualTo(0);
  assertThat(attrs.baz()).isEqualTo(1);
}
项目:jimfs    文件:JimfsUnixLikeFileSystemTest.java   
@Test
public void testMove_toDifferentFileSystem() throws IOException {
  try (FileSystem fs2 = Jimfs.newFileSystem(Configuration.unix())) {
    Path foo = fs.getPath("/foo");
    byte[] bytes = {0, 1, 2, 3, 4};
    Files.write(foo, bytes);
    Files.getFileAttributeView(foo, BasicFileAttributeView.class)
        .setTimes(FileTime.fromMillis(0), FileTime.fromMillis(1), FileTime.fromMillis(2));

    Path foo2 = fs2.getPath("/foo");
    Files.move(foo, foo2);

    assertThatPath(foo).doesNotExist();
    assertThatPath(foo2).exists()
        .and().attribute("lastModifiedTime").is(FileTime.fromMillis(0))
        .and().attribute("lastAccessTime").is(FileTime.fromMillis(1))
        .and().attribute("creationTime").is(FileTime.fromMillis(2))
        .and().containsBytes(bytes); // do this last; it updates the access time
  }
}
项目:KevaDB    文件:DefaultSSTable.java   
/**
 * Get time of the last modification.
 **/
public long getModificationTime() {
    // Just use the file modification time. 
    String path = dataPath + System.getProperty("file.separator") + uuid;

    try {
    BasicFileAttributes attr
        = Files.getFileAttributeView(Paths.get(path).toAbsolutePath(), 
                     BasicFileAttributeView.class)
        .readAttributes();

    return attr.lastModifiedTime().toMillis();
    } catch(IOException e) {
    e.printStackTrace();
    }

    return 0;
}
项目:Paja    文件:PaxosRecovery.java   
/**
    * Get the last modified file.
    *
    * @param The directory to find the log file
    * @return Path to the latest file
    */
   public Path getLatestFile(Path dir) {
long greatTime = 0;
Path greatPath = null;

try {
    DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "log*");
    for(Path entry: stream) {
    BasicFileAttributes v
        = Files.getFileAttributeView(entry, BasicFileAttributeView.class)
        .readAttributes();

    if(v.lastModifiedTime().toMillis() > greatTime) {
        greatTime = v.lastModifiedTime().toMillis();
        greatPath = entry;
    }
    }
}
catch(Exception e) {
    e.printStackTrace();
}

return greatPath;
   }
项目:jmt    文件:TemplateAddingPanel.java   
@Override
public Object getValueAt(Object parent, int index) {
    if (!(parent instanceof RootNode)) {
        if (("template".equals(((TreeTableNode) parent).getType()))) {
            switch (index) {
            case 0:
                return ((TemplateData) ((TreeTableNode) parent).getData()[0]).getName();
            case 1:
                return ((TemplateData) ((TreeTableNode) parent).getData()[0]).getAuthor();
            case 2:
                return ((TemplateData) ((TreeTableNode) parent).getData()[0]).getVersion();
            case 3:
                return ((TemplateData) ((TreeTableNode) parent).getData()[0]).getDate();
            case 4:
                return ((TemplateData) ((TreeTableNode) parent).getData()[0]).getShortDescription();
            case 5:
                Path temPath = Paths.get(TEMPLATE_FOLDER + ((TemplateData) ((TreeTableNode) parent).getData()[0]).getFileName());
                try {
                    BasicFileAttributes view = Files.getFileAttributeView(temPath,BasicFileAttributeView.class).readAttributes();
                    FileTime creationTime = view.creationTime();
                    DateFormat df = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
                    String cTime = df.format(creationTime.toMillis());
                    return cTime;
                } catch (Exception e) {
                    return "--";
                }
            default:
                return null;
            }
        } else {
            if (index < 1)
                return ((TreeTableNode) parent).getData()[index];
            else
                return null;
        }
    }
    return null;
}
项目:hadoop-oss    文件:RawLocalFileSystem.java   
/**
 * Sets the {@link Path}'s last modified time and last access time to
 * the given valid times.
 *
 * @param mtime the modification time to set (only if no less than zero).
 * @param atime the access time to set (only if no less than zero).
 * @throws IOException if setting the times fails.
 */
@Override
public void setTimes(Path p, long mtime, long atime) throws IOException {
  try {
    BasicFileAttributeView view = Files.getFileAttributeView(
        pathToFile(p).toPath(), BasicFileAttributeView.class);
    FileTime fmtime = (mtime >= 0) ? FileTime.fromMillis(mtime) : null;
    FileTime fatime = (atime >= 0) ? FileTime.fromMillis(atime) : null;
    view.setTimes(fmtime, fatime, null);
  } catch (NoSuchFileException e) {
    throw new FileNotFoundException("File " + p + " does not exist");
  }
}
项目:truevfs    文件:FileOutputSocket.java   
private void updateProperties(final Path file) throws IOException {
    final Entry template = this.template;
    if (null == template)
        return;
    getFileAttributeView(file, BasicFileAttributeView.class)
            .setTimes(  toFileTime(template.getTime(WRITE)),
                        toFileTime(template.getTime(READ)),
                        toFileTime(template.getTime(CREATE)));
}
项目:guava-mock    文件:MoreFiles.java   
/**
 * Returns whether or not the file with the given name in the given dir is a directory.
 */
private static boolean isDirectory(
    SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException {
  return dir.getFileAttributeView(name, BasicFileAttributeView.class, options)
      .readAttributes()
      .isDirectory();
}
项目:java-course    文件:LsShellCommand.java   
/**
 * Returns formatted date of creation for current file.
 * @param path Current file.
 * @return Formatted date.
 */
private String getFormattedDate(Path path) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        BasicFileAttributeView faView = Files.getFileAttributeView(path,
                BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
        BasicFileAttributes attributes = faView.readAttributes();
        FileTime fileTime = attributes.creationTime();
        return sdf.format(new Date(fileTime.toMillis()));
    } catch (IOException e) {
        return "";
    }
}
项目:openjdk-jdk10    文件:ZipFSTester.java   
static void testTime(Path src) throws Exception {
    BasicFileAttributes attrs = Files
                    .getFileAttributeView(src, BasicFileAttributeView.class)
                    .readAttributes();
    // create a new filesystem, copy this file into it
    Map<String, Object> env = new HashMap<String, Object>();
    env.put("create", "true");
    Path fsPath = getTempPath();
    FileSystem fs = newZipFileSystem(fsPath, env);

    System.out.println("test copy with timestamps...");
    // copyin
    Path dst = getPathWithParents(fs, "me");
    Files.copy(src, dst, COPY_ATTRIBUTES);
    checkEqual(src, dst);
    System.out.println("mtime: " + attrs.lastModifiedTime());
    System.out.println("ctime: " + attrs.creationTime());
    System.out.println("atime: " + attrs.lastAccessTime());
    System.out.println(" ==============>");
    BasicFileAttributes dstAttrs = Files
                    .getFileAttributeView(dst, BasicFileAttributeView.class)
                    .readAttributes();
    System.out.println("mtime: " + dstAttrs.lastModifiedTime());
    System.out.println("ctime: " + dstAttrs.creationTime());
    System.out.println("atime: " + dstAttrs.lastAccessTime());

    // 1-second granularity
    if (attrs.lastModifiedTime().to(TimeUnit.SECONDS) !=
        dstAttrs.lastModifiedTime().to(TimeUnit.SECONDS) ||
        attrs.lastAccessTime().to(TimeUnit.SECONDS) !=
        dstAttrs.lastAccessTime().to(TimeUnit.SECONDS) ||
        attrs.creationTime().to(TimeUnit.SECONDS) !=
        dstAttrs.creationTime().to(TimeUnit.SECONDS)) {
        throw new RuntimeException("Timestamp Copy Failed!");
    }
    Files.delete(fsPath);
}
项目:googles-monorepo-demo    文件:MoreFiles.java   
/**
 * Returns whether or not the file with the given name in the given dir is a directory.
 */
private static boolean isDirectory(
    SecureDirectoryStream<Path> dir, Path name, LinkOption... options) throws IOException {
  return dir.getFileAttributeView(name, BasicFileAttributeView.class, options)
      .readAttributes()
      .isDirectory();
}
项目:openjdk9    文件:ZipFSTester.java   
static void testTime(Path src) throws Exception {
    BasicFileAttributes attrs = Files
                    .getFileAttributeView(src, BasicFileAttributeView.class)
                    .readAttributes();
    // create a new filesystem, copy this file into it
    Map<String, Object> env = new HashMap<String, Object>();
    env.put("create", "true");
    Path fsPath = getTempPath();
    FileSystem fs = newZipFileSystem(fsPath, env);

    System.out.println("test copy with timestamps...");
    // copyin
    Path dst = getPathWithParents(fs, "me");
    Files.copy(src, dst, COPY_ATTRIBUTES);
    checkEqual(src, dst);
    System.out.println("mtime: " + attrs.lastModifiedTime());
    System.out.println("ctime: " + attrs.creationTime());
    System.out.println("atime: " + attrs.lastAccessTime());
    System.out.println(" ==============>");
    BasicFileAttributes dstAttrs = Files
                    .getFileAttributeView(dst, BasicFileAttributeView.class)
                    .readAttributes();
    System.out.println("mtime: " + dstAttrs.lastModifiedTime());
    System.out.println("ctime: " + dstAttrs.creationTime());
    System.out.println("atime: " + dstAttrs.lastAccessTime());

    // 1-second granularity
    if (attrs.lastModifiedTime().to(TimeUnit.SECONDS) !=
        dstAttrs.lastModifiedTime().to(TimeUnit.SECONDS) ||
        attrs.lastAccessTime().to(TimeUnit.SECONDS) !=
        dstAttrs.lastAccessTime().to(TimeUnit.SECONDS) ||
        attrs.creationTime().to(TimeUnit.SECONDS) !=
        dstAttrs.creationTime().to(TimeUnit.SECONDS)) {
        throw new RuntimeException("Timestamp Copy Failed!");
    }
    Files.delete(fsPath);
}
项目:aliyun-oss-hadoop-fs    文件:RawLocalFileSystem.java   
/**
 * Sets the {@link Path}'s last modified time and last access time to
 * the given valid times.
 *
 * @param mtime the modification time to set (only if no less than zero).
 * @param atime the access time to set (only if no less than zero).
 * @throws IOException if setting the times fails.
 */
@Override
public void setTimes(Path p, long mtime, long atime) throws IOException {
  try {
    BasicFileAttributeView view = Files.getFileAttributeView(
        pathToFile(p).toPath(), BasicFileAttributeView.class);
    FileTime fmtime = (mtime >= 0) ? FileTime.fromMillis(mtime) : null;
    FileTime fatime = (atime >= 0) ? FileTime.fromMillis(atime) : null;
    view.setTimes(fmtime, fatime, null);
  } catch (NoSuchFileException e) {
    throw new FileNotFoundException("File " + p + " does not exist");
  }
}
项目:judge    文件:CopyHelper.java   
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
    Path resolve = resolve(dir);
    if (!Files.exists(resolve)) {
        Files.createDirectories(resolve);
        BasicFileAttributeView view = Files.getFileAttributeView(resolve, BasicFileAttributeView.class);
        view.setTimes(attrs.lastModifiedTime(), attrs.lastAccessTime(), attrs.creationTime());
    }
    return FileVisitResult.CONTINUE;
}
项目:java-cloud-filesystem-provider    文件:DefaultCloudFileSystemImplementation.java   
/**
 * Can return a {@link CloudFileAttributesView}
 * @param type {@link CloudFileAttributesView} or {@link BasicFileAttributeView}
 */
@Override
public <V extends FileAttributeView> V getFileAttributeView(BlobStoreContext blobStoreContext, Class<V> type, CloudPath cloudPath) {
    if (CloudFileAttributesView.class.equals(type) || BasicFileAttributeView.class.equals(type)) {
        return type.cast(new CloudFileAttributesView(blobStoreContext, cloudPath));
    }

    return null;
}
项目:java-cloud-filesystem-provider    文件:DefaultCloudFileSystemImplementationTest.java   
@Test
public void testGetFileAttributeViewCreatesABasicFileAttributesViewInstance() {
    CloudPath path = context.mock(CloudPath.class);
    BlobStoreContext blobStoreContext = context.mock(BlobStoreContext.class);
    BasicFileAttributeView view = impl.getFileAttributeView(blobStoreContext, BasicFileAttributeView.class, path);
    Assert.assertNotNull(view);
    Assert.assertTrue(view instanceof CloudFileAttributesView);
}
项目:filesystem    文件:AbstractLocalFileSystemProvider.java   
@Override
@SuppressWarnings( "unchecked" )
public <V extends FileAttributeView> V getFileAttributeView( Path path, Class<V> type, LinkOption... options )
{
    if( type.isAssignableFrom( BasicFileAttributeView.class ) )
    {
        P p = toCachePath( path );
        return (V) p.getFileSystem().getFileSystemIO().getAttributeView( p.getResolvedPath() );
    }
    throw new UnsupportedOperationException();
}
项目:mycore    文件:MCRBasicFileAttributeViewImpl.java   
@Override
public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime) throws IOException {
    MCRFilesystemNode node = resolveNode();
    if (node instanceof MCRFile) {
        MCRFile file = (MCRFile) node;
        file.adjustMetadata(lastModifiedTime, file.getMD5(), file.getSize());
        Files.getFileAttributeView(file.getLocalFile().toPath(), BasicFileAttributeView.class).setTimes(
            lastModifiedTime,
            lastAccessTime, createTime);
    } else if (node instanceof MCRDirectory) {
        LOGGER.warn("Setting times on directories is not supported: {}", node.toPath());
    }
}
项目:reactive-data    文件:AbstractFileChunkHandler.java   
/**
 * Read mode.
 * @param f
 * @throws IOException
 */
public AbstractFileChunkHandler(File f) throws IOException {
  super();
  this.file = f;
  if(!file.exists() || !file.isFile())
    throw new IOException("Not a valid file");


  fileName = file.getName();
  fileSize = file.length();

  Path filePath = file.toPath();
  try 
  {
    if(Files.getFileStore(filePath).supportsFileAttributeView(BasicFileAttributeView.class))
    {
      getFileAttributes();

    }
    else
      throw new IOException("Unable to read basic file attributes");

  } catch (IOException e1) {
    throw e1;
  }



}