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