@Override public void changeDate(long lastModified) throws IOException, UnsupportedFileOperationException { file.changeDate(lastModified); }
private void tryCopyFileDate(AbstractFile sourceFile, AbstractFile destFile) { if(destFile.isFileOperationSupported(FileOperation.CHANGE_DATE)) { try { destFile.changeDate(sourceFile.getDate()); } catch (IOException e) { LOGGER.debug("failed to change the date of "+destFile, e); // Fail silently } } }
/** * Tests {@link AbstractFile#changeDate(long)} when the operation is not supported. * * @throws IOException should not happen */ protected void testChangeDateUnsupported() throws IOException { // Assert that #changeDate throws a proper UnsupportedFileOperationException when called UnsupportedFileOperationException e = null; try { tempFile.changeDate(System.currentTimeMillis()); } catch(UnsupportedFileOperationException ex) { e = ex; } assertUnsupportedFileOperationException(e, FileOperation.CHANGE_DATE); }
@Override protected void saveAs(AbstractFile destFile) throws IOException { OutputStream out = null; try { out = destFile.getOutputStream(); write(out); } finally { if(out != null) { try {out.close();} catch(IOException e) { // Ignored } } } // We get here only if the destination file was updated successfully // so we can set that no further save is needed at this stage setSaveNeeded(false); // Change the parent folder's date to now, so that changes are picked up by folder auto-refresh (see ticket #258) if(destFile.isFileOperationSupported(FileOperation.CHANGE_DATE)) { try { destFile.getParent().changeDate(System.currentTimeMillis()); } catch (IOException e) { LOGGER.debug("failed to change the date of "+destFile, e); // Fail silently } } }
/** * Validates that FileMonitor properly reports {@link FileMonitor#DATE_ATTRIBUTE} changes when a file's date changes. * * @throws IOException should not normally happen */ @Test public void testDateAttribute() throws IOException { setUp(DATE_ATTRIBUTE); file.changeDate(file.getDate()-2000); assert hasAttributeChanged(DATE_ATTRIBUTE); file.changeDate(file.getDate()+2000); assert hasAttributeChanged(DATE_ATTRIBUTE); }
/** * Tests {@link AbstractFile#changeDate(long)} when the operation is supported. * * @throws IOException should not happen * @throws NoSuchAlgorithmException should not happen */ protected void testChangeDateSupported() throws IOException, NoSuchAlgorithmException { createFile(tempFile, 0); long date; // Assert that changeDate succeeds (does not throw an exception) tempFile.changeDate(date=(tempFile.getDate()-1000)); // Assert that the getDate returns the date that was set assert date == tempFile.getDate(); }
file.changeDate(date); return true;
destFile.changeDate(sourceFile.getDate());
destFile.changeDate(file.getDate());
destFile.changeDate(file.getDate());