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) {
}
}
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));
}
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);
}
Aggregations