Search in sources :

Example 21 with BasicFileAttributeView

use of java.nio.file.attribute.BasicFileAttributeView in project sonarlint-core by SonarSource.

the class GlobalTempFolderProviderTest method setFileCreationDate.

private void setFileCreationDate(File f, long time) throws IOException {
    BasicFileAttributeView attributes = Files.getFileAttributeView(f.toPath(), BasicFileAttributeView.class);
    FileTime creationTime = FileTime.fromMillis(time);
    attributes.setTimes(creationTime, creationTime, creationTime);
}
Also used : BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) FileTime(java.nio.file.attribute.FileTime)

Example 22 with BasicFileAttributeView

use of java.nio.file.attribute.BasicFileAttributeView in project BiglyBT by BiglySoftware.

the class FileUtil method renameFile.

public static boolean renameFile(File from_file, File to_file, boolean fail_on_existing_directory, FileFilter file_filter, ProgressListener pl) {
    FileTime from_last_modified = null;
    FileTime from_last_access = null;
    FileTime from_created = null;
    try {
        BasicFileAttributeView from_attributes_view = Files.getFileAttributeView(from_file.toPath(), BasicFileAttributeView.class);
        BasicFileAttributes from_attributes = from_attributes_view.readAttributes();
        from_last_modified = from_attributes.lastModifiedTime();
        from_last_access = from_attributes.lastAccessTime();
        from_created = from_attributes.creationTime();
    } catch (Throwable e) {
    }
    boolean result = renameFileSupport(from_file, to_file, fail_on_existing_directory, file_filter, pl);
    if (result) {
        try {
            BasicFileAttributeView to_attributes_view = Files.getFileAttributeView(to_file.toPath(), BasicFileAttributeView.class);
            BasicFileAttributes to_attributes = to_attributes_view.readAttributes();
            FileTime to_last_modified = to_attributes.lastModifiedTime();
            FileTime to_last_access = to_attributes.lastAccessTime();
            FileTime to_created = to_attributes.creationTime();
            if (from_last_modified.equals(to_last_modified) && from_last_access.equals(to_last_access) && from_created.equals(to_created)) {
            } else {
                to_attributes_view.setTimes(from_last_modified, from_last_access, from_created);
            }
        } catch (Throwable e) {
        }
    }
    return (result);
}
Also used : BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) FileTime(java.nio.file.attribute.FileTime) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 23 with BasicFileAttributeView

use of java.nio.file.attribute.BasicFileAttributeView in project jimfs by google.

the class JimfsFileSystemCloseTest method testOpenFileAttributeViewsThrow.

@Test
public void testOpenFileAttributeViewsThrow() throws IOException {
    Path p = fs.getPath("/foo");
    Files.createFile(p);
    BasicFileAttributeView view = Files.getFileAttributeView(p, BasicFileAttributeView.class);
    fs.close();
    try {
        view.readAttributes();
        fail();
    } catch (ClosedFileSystemException expected) {
    }
    try {
        view.setTimes(null, null, null);
        fail();
    } catch (ClosedFileSystemException expected) {
    }
}
Also used : Path(java.nio.file.Path) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) ClosedFileSystemException(java.nio.file.ClosedFileSystemException) Test(org.junit.Test)

Example 24 with BasicFileAttributeView

use of java.nio.file.attribute.BasicFileAttributeView in project jimfs by google.

the class BasicAttributeProviderTest method testView.

@Test
public void testView() throws IOException {
    BasicFileAttributeView view = provider.view(fileLookup(), NO_INHERITED_VIEWS);
    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);
    attrs = view.readAttributes();
    assertThat(attrs.creationTime()).isEqualTo(time);
    assertThat(attrs.lastAccessTime()).isEqualTo(time);
    assertThat(attrs.lastModifiedTime()).isEqualTo(FileTime.fromMillis(0L));
}
Also used : BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) FileTime(java.nio.file.attribute.FileTime) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Example 25 with BasicFileAttributeView

use of java.nio.file.attribute.BasicFileAttributeView in project j2objc by google.

the class DefaultFileSystemProvider2Test method test_getFileAttributeView.

@Test
public void test_getFileAttributeView() throws IOException {
    BasicFileAttributeView fileAttributeView = provider.getFileAttributeView(filesSetup.getDataFilePath(), BasicFileAttributeView.class);
    assertTrue(fileAttributeView.readAttributes().isRegularFile());
    assertFalse(fileAttributeView.readAttributes().isDirectory());
}
Also used : BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) Test(org.junit.Test)

Aggregations

BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)28 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)13 Path (java.nio.file.Path)11 FileTime (java.nio.file.attribute.FileTime)11 IOException (java.io.IOException)7 Test (org.junit.Test)7 File (java.io.File)3 NoSuchFileException (java.nio.file.NoSuchFileException)3 FileOwnerAttributeView (java.nio.file.attribute.FileOwnerAttributeView)3 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)3 InputStream (java.io.InputStream)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 FileStore (java.nio.file.FileStore)2 SecureDirectoryStream (java.nio.file.SecureDirectoryStream)2 StandardCopyOption (java.nio.file.StandardCopyOption)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2