Search in sources :

Example 6 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 7 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 8 with BasicFileAttributeView

use of java.nio.file.attribute.BasicFileAttributeView in project sonarqube 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)

Aggregations

BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)8 Path (java.nio.file.Path)4 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3 FileTime (java.nio.file.attribute.FileTime)3 Test (org.junit.Test)3 DirectoryContent (com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ClosedDirectoryStreamException (java.nio.file.ClosedDirectoryStreamException)1 ClosedFileSystemException (java.nio.file.ClosedFileSystemException)1 DirectoryIteratorException (java.nio.file.DirectoryIteratorException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 SecureDirectoryStream (java.nio.file.SecureDirectoryStream)1 HashSet (java.util.HashSet)1 ApplicationContextException (org.springframework.context.ApplicationContextException)1