RetrievalWorker implements Runnable { protected void applyTimestamps(ContentStream content, File localFile) { FileTime createTime = convertDateToFileTime(content.getDateCreated()); FileTime lastAccessTime = convertDateToFileTime(content.getDateLastAccessed()); FileTime lastModTime = convertDateToFileTime(content.getDateLastModified()); BasicFileAttributeView fileAttributeView = Files.getFileAttributeView(localFile.toPath(), BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); try { fileAttributeView.setTimes(lastModTime, lastAccessTime, createTime); } catch (IOException e) { logger.error("Error setting timestamps for local file " + localFile.getAbsolutePath() + ": " + e.getMessage(), e); } } RetrievalWorker(ContentItem contentItem,
                           RetrievalSource source,
                           File contentDir,
                           boolean overwrite,
                           OutputWriter outWriter,
                           boolean createSpaceDir,
                           boolean applyTimestamps); void run(); Map<String, String> retrieveFile(); Map<String, String> retrieveFile(RetrievalListener listener); File getLocalFile();  }
@Test public void testApplyTimestamps() throws Exception { String time1 = DateUtil.convertToStringLong(testTime + 100000); String time2 = DateUtil.convertToStringLong(testTime + 200000); String time3 = DateUtil.convertToStringLong(testTime + 300000); Map<String, String> props = new HashMap<>(); props.put(ContentStore.CONTENT_FILE_CREATED, time1); props.put(ContentStore.CONTENT_FILE_ACCESSED, time2); props.put(ContentStore.CONTENT_FILE_MODIFIED, time3); ContentStream content = new ContentStream(null, props); File localFile = new File(tempDir, "timestamp-test"); FileUtils.writeStringToFile(localFile, contentValue); BasicFileAttributes fileAttributes = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class); long now = System.currentTimeMillis(); assertTrue(isTimeClose(fileAttributes.creationTime().toMillis(), now)); assertTrue(isTimeClose(fileAttributes.lastAccessTime().toMillis(), now)); assertTrue(isTimeClose(fileAttributes.lastModifiedTime().toMillis(), now)); RetrievalWorker worker = createRetrievalWorker(true); worker.applyTimestamps(content, localFile); fileAttributes = Files.readAttributes(localFile.toPath(), BasicFileAttributes.class); long creationTime = fileAttributes.creationTime().toMillis(); long lastAccessTime = fileAttributes.lastAccessTime().toMillis(); long lastModifiedTime = fileAttributes.lastModifiedTime().toMillis(); assertFalse(isTimeClose(creationTime, now)); assertFalse(isTimeClose(lastAccessTime, now)); assertFalse(isTimeClose(lastModifiedTime, now)); assertTrue(testTime + 100000 == creationTime || testTime + 300000 == creationTime); assertEquals(testTime + 200000, lastAccessTime); assertEquals(testTime + 300000, lastModifiedTime); }