/** * Declare the underlying Zip file as up-to-date. Calling this method after the Zip file has been modified prevents * {@link #checkZipFile()} from being reloaded. */ private void declareZipFileUpToDate() { lastZipFileDate = file.getDate(); }
@Override public long getDate() { if(!getDateSet) { getDate = file.getDate(); getDateSet = true; } return getDate; }
@Override public long getDate() { return file.getDate(); }
/** * Forces this monitor to update current folder information. This method should be called when a folder has been * manually refreshed, so that this monitor doesn't detect changes and try to refresh the table again. * * @param folder the new current folder */ private void updateFolderInfo(AbstractFile folder) { this.currentFolder = folder; this.currentFolderDate = currentFolder.getDate(); // Reset time average totalCheckTime = 0; nbSamples = 0; }
@Override public long getLastModified() { try { checkConnected(); return file.getDate(); } catch(IOException e) { return 0; } }
/** * Has date changed ? * Note that date will be 0 if the folder is no longer available, and thus yield a refresh: this is exactly * what we want (the folder will be changed to a 'workable' folder). */ private boolean isFolderDateChanged() { // Update time average next loop long timeStamp = System.currentTimeMillis(); // Check folder's date long date = currentFolder.getDate(); totalCheckTime += System.currentTimeMillis()-timeStamp; nbSamples++; if (date == currentFolderDate) return false; LOGGER.debug(this+" ("+currentFolder.getName()+") Detected changes in current folder, refreshing table!"); return true; }
@Override public String apply(AbstractFile file) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(file.getDate()); StringBuilder result = new StringBuilder(); for (int i = 0; i < len; i++) { switch (token.charAt(i)) { case 'Y': result.append(year.format(c.get(Calendar.YEAR))); break; case 'M': result.append(digits2.format(c.get(Calendar.MONTH) + 1)); break; case 'D': result.append(digits2.format(c.get(Calendar.DAY_OF_MONTH))); break; case 'h': result.append(digits2.format(c.get(Calendar.HOUR_OF_DAY))); break; case 'm': result.append(digits2.format(c.get(Calendar.MINUTE))); break; case 's': result.append(digits2.format(c.get(Calendar.SECOND))); break; } } return result.toString(); }
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 } } }
/** * Checks if the underlying Zip file is up-to-date, i.e. exists and has not changed without this archive file * being aware of it. If one of those 2 conditions are not met, (re)load the ZipFile instance (parse the entries) * and declare the Zip file as up-to-date. * * @throws IOException if an error occurred while reloading */ private void checkZipFile() throws IOException, UnsupportedFileOperationException { long currentDate = file.getDate(); if(zipFile==null || currentDate!=lastZipFileDate) { zipFile = new ZipFile(file); declareZipFileUpToDate(); } }
public FolderChangeMonitor(FolderPanel folderPanel) { this.folderPanel = folderPanel; // Listen to folder changes to know when a folder is being / has been changed folderPanel.getLocationManager().addLocationListener(this); this.currentFolder = folderPanel.getCurrentFolder(); this.currentFolderDate = currentFolder.getDate(); // Folder contents is up-to-date let's wait before checking it for changes this.lastCheckTimestamp = System.currentTimeMillis(); this.waitBeforeCheckTime = waitAfterRefresh; folderPanel.getMainFrame().addWindowListener(this); instances.add(this); // Create and start the monitor thread on first FolderChangeMonitor instance if(monitorThread==null && checkPeriod>=0) { monitorThread = new Thread(this, getClass().getName()); monitorThread.setDaemon(true); monitorThread.start(); } }
/** * Checks if the underlying Rar file is up-to-date, i.e. exists and has not changed without this archive file * being aware of it. If one of those 2 conditions are not met, (re)load the RipFile instance (parse the entries) * and declare the Rar file as up-to-date. * * @throws IOException if an error occurred while reloading * @throws UnsupportedFileOperationException if this operation is not supported by the underlying filesystem, * or is not implemented. * @throws RarException */ private void checkRarFile() throws IOException, UnsupportedFileOperationException, RarException { long currentDate = file.getDate(); if (rarFile==null || currentDate != lastRarFileDate) { rarFile = new RarFile(file); declareRarFileUpToDate(currentDate); } }
/** * 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(); }
long currentDirectoryDate = currentDirectory.getDate(); if (cachedDirectoryName == null || !cachedDirectoryName.equals(currentDirectoryName) || currentDirectoryDate != cachedDirectoryDate) { AbstractFile[] currentDirectoryFiles;
/** * Tests {@link AbstractFile#getDate()}. * * @throws IOException should not happen * @throws NoSuchAlgorithmException should not happen */ @Test public void testGetDate() throws IOException, NoSuchAlgorithmException { createFile(tempFile, 0); // Asserts that the date changes when the file is modified long date = tempFile.getDate(); sleep(1000); // Sleep a full second, some filesystems may only have a one-second granularity createFile(tempFile, 1); // 1 byte should be enough assert tempFile.getDate()>date; }
private void addFileDetails(XAlignedComponentPanel panel, AbstractFile file, String nameLabel) { addFileDetailsRow(panel, nameLabel+":", new FileLabel(file, false), 0); AbstractFile parent = file.getParent(); addFileDetailsRow(panel, Translator.get("location")+":", new FileLabel((parent==null?file:parent), true), 0); addFileDetailsRow(panel, Translator.get("size")+":", new JLabel(SizeFormat.format(file.getSize(), SizeFormat.DIGITS_FULL| SizeFormat.UNIT_LONG| SizeFormat.INCLUDE_SPACE)), 0); addFileDetailsRow(panel, Translator.get("date")+":", new JLabel(CustomDateFormat.format(new Date(file.getDate()))), 0); addFileDetailsRow(panel, Translator.get("permissions")+":", new JLabel(file.getPermissionsString()), 10); }
/** * Checks if this directory is already cached. If it isn't cached then a new * cache thread is started. * @return true if directory is cached, false otherwise */ public synchronized boolean isCached() { // check if caching thread is running if (isReadingChildren()) { return false; } // check if directory contents changed if (lsTimeStamp != file.getDate()) { setReadingChildren(true); // read children in caching thread TreeIOThreadManager.getInstance().addTask(new Runnable() { public void run() { lsAsync(); } }); return false; } return true; }
/** * 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); }
cellValuesCache[0][Column.NAME.ordinal()-1] = ".."; cellValuesCache[0][Column.SIZE.ordinal()-1] = DIRECTORY_SIZE_STRING; currentFolderDateSnapshot = currentFolder.getDate(); cellValuesCache[0][Column.DATE.ordinal()-1] = CustomDateFormat.format(new Date(currentFolderDateSnapshot)); cellValuesCache[cellIndex][Column.NAME.ordinal()-1] = file.getName(); cellValuesCache[cellIndex][Column.SIZE.ordinal()-1] = file.isDirectory()?DIRECTORY_SIZE_STRING:SizeFormat.format(file.getSize(), sizeFormat); cellValuesCache[cellIndex][Column.DATE.ordinal()-1] = CustomDateFormat.format(new Date(file.getDate())); cellValuesCache[cellIndex][Column.PERMISSIONS.ordinal()-1] = file.getPermissionsString(); cellValuesCache[cellIndex][Column.OWNER.ordinal()-1] = file.getOwner();
/** * Creates a new SimpleFileAttributes instance whose attributes are set to those of the given AbstractFile. * Note that the path attribute is set to the file's {@link com.mucommander.commons.file.AbstractFile#getAbsolutePath() absolute path}. * * @param file the file from which to fetch the attribute values */ public SimpleFileAttributes(AbstractFile file) { setPath(file.getAbsolutePath()); setExists(file.exists()); setDate(file.getDate()); setSize(file.getSize()); setDirectory(file.isDirectory()); setPermissions(file.getPermissions()); setOwner(file.getOwner()); setGroup(file.getGroup()); }
/** * Asserts that the attributes of the given AbstractFile and SimpleFileAttributes match. */ private void assertAttributesMatch(AbstractFile file, SimpleFileAttributes attrs) { assert file.getAbsolutePath().equals(attrs.getPath()); assert file.exists() == attrs.exists(); assert file.getDate() == attrs.getDate(); assert file.getSize() == attrs.getSize(); assert file.isDirectory() == attrs.isDirectory(); assert file.getPermissions() == attrs.getPermissions(); assert file.getOwner() == null ? attrs.getOwner() == null : file.getOwner().equals(attrs.getOwner()); assert file.getGroup() == null ? attrs.getGroup() == null : file.getGroup().equals(attrs.getGroup()); }