public static boolean isOlder(File file, long timeMillis) { if (!file.exists()) { return false; } return file.lastModified() < timeMillis; }
public PluginFileDetails(File plugin, boolean bundledPlugin) { this.pluginFile = plugin; this.bundledPlugin = bundledPlugin; pluginFileName = plugin.getName(); lastModified = plugin.lastModified(); }
public FileInfo(File file, EventDeserializer deserializer) { this.file = file; this.length = file.length(); this.lastModified = file.lastModified(); this.deserializer = deserializer; }
name = file.getName(); exists = file.exists(); directory = exists && file.isDirectory(); lastModified = exists ? file.lastModified() : 0; length = exists && !directory ? file.length() : 0;
@Override public <T extends Serializable> T load(String id, Class<T> type) { try { File file = new File(dir, id); if (!file.exists() || (validTime > 0 && file.lastModified() < new Date().getTime() - validTime)) { return null; } try (ObjectInputStream in = new ObjectInputStream(new FileInputStream(file))) { Object o = in.readObject(); return o.getClass() == type ? (T) o : null; } } catch (IOException | ClassNotFoundException e) { return null; } }
static void setLastModifiedNow(File file) throws IOException { if (file.exists()) { long now = System.currentTimeMillis(); boolean modified = file.setLastModified(now); // on some devices (e.g. Nexus 5) doesn't work if (!modified) { modify(file); if (file.lastModified() < now) { // NOTE: apparently this is a known issue (see: http://stackoverflow.com/questions/6633748/file-lastmodified-is-never-what-was-set-with-file-setlastmodified) HttpProxyCacheDebuger.printfWarning("Last modified date {} is not set for file {}", new Date(file.lastModified()).toString() + "\n" + file.getAbsolutePath()); } } } }
File file = new File(filePath); Date lastModDate = new Date(file.lastModified()); Log.i("File last modified @ : "+ lastModDate.toString());
/** * Deletes jar files in dirLoc older than seconds. * * @param dirLoc the location to look in for file * @param seconds how old is too old and should be deleted */ @VisibleForTesting public static void cleanInbox(String dirLoc, int seconds) { final long now = Time.currentTimeMillis(); final long ms = Time.secsToMillis(seconds); File dir = new File(dirLoc); for (File f : dir.listFiles((file) -> file.isFile() && ((file.lastModified() + ms) <= now))) { if (f.delete()) { LOG.info("Cleaning inbox ... deleted: {}", f.getName()); } else { LOG.error("Cleaning inbox ... error deleting: {}", f.getName()); } } }
/** * Scans the directory looking for source files to be compiled. * The results are returned in the class variable compileList * @param srcDir the source directory. * @param dest the destination directory. * @param mangler the jsp filename mangler. * @param files the file names to mangle. */ protected void scanDir(File srcDir, File dest, JspMangler mangler, String[] files) { long now = Instant.now().toEpochMilli(); for (String filename : files) { File srcFile = new File(srcDir, filename); File javaFile = mapToJavaFile(mangler, srcFile, srcDir, dest); if (javaFile == null) { continue; } if (srcFile.lastModified() > now) { log("Warning: file modified in the future: " + filename, Project.MSG_WARN); } if (isCompileNeeded(srcFile, javaFile)) { compileList.addElement(srcFile.getAbsolutePath()); javaFiles.addElement(javaFile); } } }
@Override protected RawResource getResourceImpl(String resPath) throws IOException { File f = file(resPath); if (f.exists() && f.isFile()) { if (f.length() == 0) { logger.warn("Zero length file: {}. ", f.getAbsolutePath()); } return new RawResource(resPath, f.lastModified(), new FileInputStream(f)); } else { return null; } }
public Watch(File file, String path) { this.file = file; this.path = path; this.exsists = file.exists(); this.last = exsists ? file.lastModified() : 0; if (file.isDirectory()) { contents = file.listFiles(); } }
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); JarOutputStream target = new JarOutputStream(new FileOutputStream("output.jar"), manifest); add(new File("inputDirectory"), target); target.close(); try if (source.isDirectory()) name += "/"; JarEntry entry = new JarEntry(name); entry.setTime(source.lastModified()); target.putNextEntry(entry); target.closeEntry(); entry.setTime(source.lastModified()); target.putNextEntry(entry); in = new BufferedInputStream(new FileInputStream(source));
static void writeFile(long templateTime, String outputDir, String classesDir, String className, String str) throws IOException { File outputFile = new File(outputDir, className + ".java"); File outputClass = new File(classesDir, className + ".class"); if (outputFile.lastModified() > templateTime && outputFile.length() == str.length() && outputClass.lastModified() > templateTime) { // best effort return; } writeFile(outputFile, str); }
public static Defines createWithFileName(File file) { if (file == null) { throw new IllegalArgumentException(); } final Defines result = createEmpty(); result.overrideFilename(file.getName()); result.environment.put("filedate", new Date(file.lastModified()).toString()); // result.environment.put("filename", file.getName()); // result.environment.put("filenameNoExtension", nameNoExtension(file)); result.environment.put("dirpath", file.getAbsoluteFile().getParentFile().getAbsolutePath().replace('\\', '/')); return result; }
private void addFileToWatchedList(File file) { filesToWatch.add(file); Map<File, FileInfo> map = new HashMap<>(); if (file.isDirectory()) { // We're watching a directory contents and its children for changes File[] children = file.listFiles(); if (children != null) { for (File child : children) { map.put(child, new FileInfo(child.lastModified(), child.length())); if (child.isDirectory()) { addFileToWatchedList(child); } } } } else { // Not a directory - we're watching a specific file - e.g. a jar map.put(file, new FileInfo(file.lastModified(), file.length())); } fileMap.put(file, map); }
/** * Create log file for given file. * * @param file Log file. */ public VisorLogFile(File file) { this(file.getAbsolutePath(), file.length(), file.lastModified()); }
public static long recursiveModifiedTime(File file) { long modified = file.lastModified(); if (file.isDirectory()) { File[] subfiles = file.listFiles(); for (int i = 0; i < subfiles.length; i++) { long submodified = recursiveModifiedTime(subfiles[i]); if (submodified > modified) { modified = submodified; } } } return modified; }
/** * Build mocked File object with given (or default) attributes for a file. */ public File build() { File mockFile = mock(File.class); when(mockFile.getName()).thenReturn(fileName); when(mockFile.lastModified()).thenReturn(mtime); when(mockFile.isFile()).thenReturn(true); try { when(mockFile.getCanonicalPath()).thenReturn("/mock/canonical/path/to/" + fileName); } catch (IOException e) { // we're making mock, ignoring... } when(mockFile.length()).thenReturn(length); return mockFile; } }
/** @return true if the output file does not yet exist or its last modification date is before the last modification date of * the input file */ static public boolean isModified (String input, String output, String packFileName, Settings settings) { String packFullFileName = output; if (!packFullFileName.endsWith("/")) { packFullFileName += "/"; } // Check against the only file we know for sure will exist and will be changed if any asset changes: // the atlas file packFullFileName += packFileName; packFullFileName += settings.atlasExtension; File outputFile = new File(packFullFileName); if (!outputFile.exists()) { return true; } File inputFile = new File(input); if (!inputFile.exists()) { throw new IllegalArgumentException("Input file does not exist: " + inputFile.getAbsolutePath()); } return isModified(inputFile, outputFile.lastModified()); }
public StringBuilder getContent() { File file = new File(finalFileName); if (!file.exists()) { throw new RuntimeException("File not found : " + finalFileName); } // 极为重要,否则在开发模式下 isModified() 一直返回 true,缓存一直失效(原因是 lastModified 默认值为 0) this.lastModified = file.lastModified(); return loadFile(file, encoding); }