List of usage examples for java.io File lastModified
public long lastModified()
From source file:ArchiveUtil.java
/** * Extracts the file {@code archive} to the target dir {@code targetDir} and deletes the * files extracted upon jvm exit if the flag {@code deleteOnExit} is true. *///from w ww.j a v a2 s. com public static boolean extract(URL archive, File targetDir, boolean deleteOnExit) throws IOException { String archiveStr = archive.toString(); String jarEntry = null; int idx = archiveStr.indexOf("!/"); if (idx != -1) { if (!archiveStr.startsWith("jar:") && archiveStr.length() == idx + 2) return false; archive = new URL(archiveStr.substring(4, idx)); jarEntry = archiveStr.substring(idx + 2); } else if (!isSupported(archiveStr)) return false; JarInputStream jis = new JarInputStream(archive.openConnection().getInputStream()); if (!targetDir.exists()) targetDir.mkdirs(); JarEntry entry = null; while ((entry = jis.getNextJarEntry()) != null) { String entryName = entry.getName(); File entryFile = new File(targetDir, entryName); if (!entry.isDirectory()) { if (jarEntry == null || entryName.startsWith(jarEntry)) { if (!entryFile.exists() || entryFile.lastModified() != entry.getTime()) extractEntry(entryFile, jis, entry, deleteOnExit); } } } try { jis.close(); } catch (Exception e) { } return true; }
From source file:com.qwazr.search.index.BackupStatus.java
final static BackupStatus newBackupStatus(File backupDir) { if (backupDir == null) return null; try {//from w w w . j ava 2 s.c o m long generation = Long.parseLong(backupDir.getName()); File[] files = backupDir.listFiles((FileFilter) FileFileFilter.FILE); long bytes_size = 0; if (files == null) return null; for (File file : files) bytes_size += file.length(); return new BackupStatus(generation, backupDir.lastModified(), bytes_size, files.length); } catch (NumberFormatException e) { return null; } }
From source file:de.clusteval.run.result.DataAnalysisRunResult.java
/** * @param run// ww w.j a v a 2s. co m * @param parentRepository * @param runResultFolder * @return The data analysis run result parsed from the given runresult * folder. * @throws RegisterException * @throws RunResultParseException * */ public static DataAnalysisRunResult parseFromRunResultFolder(final DataAnalysisRun run, final Repository parentRepository, final File runResultFolder, final List<RunResult> result, final boolean register) throws RegisterException, RunResultParseException { DataAnalysisRunResult analysisResult = null; File analysesFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "analyses")); analysisResult = new DataAnalysisRunResult(parentRepository, analysesFolder.lastModified(), analysesFolder, analysesFolder.getParentFile().getName(), run); if (register) { analysisResult.loadIntoMemory(); try { analysisResult.register(); } finally { analysisResult.unloadFromMemory(); } } result.add(analysisResult); return analysisResult; }
From source file:de.blizzy.backup.Utils.java
public static void zipFile(File source, File target) throws IOException { ZipOutputStream out = null;//from w ww .ja v a2 s . c o m try { out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(target))); out.setLevel(Deflater.BEST_COMPRESSION); ZipEntry entry = new ZipEntry(source.getName()); entry.setTime(source.lastModified()); out.putNextEntry(entry); Files.copy(source.toPath(), out); } finally { IOUtils.closeQuietly(out); } }
From source file:de.clusteval.run.result.RunDataAnalysisRunResult.java
/** * @param run/* www . j a v a 2s . c o m*/ * The run corresponding to the given runresult folder. * @param repository * The repository in which we want to register the parsed * runresult. * @param runResultFolder * The folder containing the runresult. * @return The run-data analysis runresult parsed from the given runresult * folder. * @throws RunResultParseException * @throws RegisterException * */ public static RunDataAnalysisRunResult parseFromRunResultFolder(final RunDataAnalysisRun run, final Repository repository, final File runResultFolder, final List<RunResult> result, final boolean register) throws RunResultParseException, RegisterException { RunDataAnalysisRunResult analysisResult = null; File analysesFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "analyses")); analysisResult = new RunDataAnalysisRunResult(repository, analysesFolder.lastModified(), analysesFolder, analysesFolder.getParentFile().getName(), run); List<RunDataStatistic> statistics = new ArrayList<RunDataStatistic>(); for (final Statistic runDataStatistic : run.getStatistics()) { final File completeFile = new File(FileUtils.buildPath(analysesFolder.getAbsolutePath(), runDataStatistic.getIdentifier() + ".txt")); if (!completeFile.exists()) throw new RunResultParseException("The result file of (" + runDataStatistic.getIdentifier() + ") could not be found: " + completeFile); final String fileContents = FileUtils.readStringFromFile(completeFile.getAbsolutePath()); runDataStatistic.parseFromString(fileContents); statistics.add((RunDataStatistic) runDataStatistic); } analysisResult.put( Pair.getPair(run.getUniqueRunAnalysisRunIdentifiers(), run.getUniqueDataAnalysisRunIdentifiers()), statistics); result.add(analysisResult); if (register) analysisResult.register(); return analysisResult; }
From source file:com.aimluck.eip.util.ALCommonUtils.java
public static String getCacheBust() { if (CACHE_BUST == null) { File file = new File(JetspeedResources.getString("aipo.cached.file")); long lastModified = file.lastModified(); CACHE_BUST = String.valueOf(lastModified); }//from ww w . j a v a2 s . c o m return CACHE_BUST; }
From source file:net.rim.ejde.internal.util.RIAUtils.java
public static void initDLLs() { IPath dllStoreLocation = ContextManager.PLUGIN.getStateLocation().append("installDlls"); //$NON-NLS-1$ File dllStoreFile = dllStoreLocation.toFile(); if (!dllStoreFile.exists()) dllStoreFile.mkdir();/*from w w w .j a v a 2 s .co m*/ InputStream inputStream; OutputStream outputStream; File dllFile; byte[] buf; int numbytes; URL bundUrl; for (String dllFileName : dllNames) { inputStream = null; outputStream = null; try { dllFile = dllStoreLocation.append(dllFileName).toFile(); Bundle bundle = ContextManager.PLUGIN.getBundle(); if (!dllFile.exists() || bundle.getLastModified() > dllFile.lastModified()) { bundUrl = bundle.getResource(dllFileName); if (bundUrl == null) continue; inputStream = bundUrl.openStream(); outputStream = new FileOutputStream(dllFile); buf = new byte[4096]; numbytes = 0; while ((numbytes = inputStream.read(buf)) > 0) outputStream.write(buf, 0, numbytes); } } catch (IOException t) { _log.error(t.getMessage(), t); } finally { try { if (inputStream != null) inputStream.close(); if (outputStream != null) outputStream.close(); } catch (IOException t) { _log.error(t.getMessage(), t); } } } // end for }
From source file:atg.tools.dynunit.test.util.FileUtil.java
/** * @see #forceGlobalScope(java.io.File)/*from ww w . j ava 2 s . c o m*/ * @see #forceComponentScope(java.io.File, String) */ @Deprecated public static void searchAndReplace(@NotNull final String originalValue, @NotNull final String newValue, @NotNull final File file) throws IOException { final File tempFile = newTempFile(); if (CONFIG_FILES_GLOBAL_FORCE != null && CONFIG_FILES_GLOBAL_FORCE.get(file.getPath()) != null && CONFIG_FILES_GLOBAL_FORCE.get(file.getPath()) == file.lastModified() && file.exists()) { dirty = false; logger.debug( "{} last modified hasn't changed and file still exists, " + "no need for global scope force", file.getPath()); } else { final BufferedWriter out = new BufferedWriter(new FileWriter(tempFile)); final BufferedReader in = new BufferedReader(new FileReader(file)); String str; while ((str = in.readLine()) != null) { if (str.contains(originalValue)) { out.write(newValue); } else { out.write(str); out.newLine(); } } out.close(); in.close(); JarUtils.copy(tempFile, file, true, false); CONFIG_FILES_GLOBAL_FORCE.put(file.getPath(), file.lastModified()); dirty = true; } }
From source file:BackupRestoreTest.java
private static List<String> getContentDir(String tstPath, boolean checkTime) throws Exception { List<String> result = new ArrayList<>(); for (File file : FileUtils.listFilesAndDirs(new File(tstPath), FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter())) { List<String> loc = new ArrayList<>(); loc.add(file.getName());//from w w w .ja v a 2 s . c om if (checkTime && !file.isDirectory()) { loc.add(String.valueOf(file.lastModified())); } loc.add(String.valueOf(file.isDirectory())); loc.add(String.valueOf((file.isDirectory() ? 0 : file.length()))); if (!file.isDirectory()) { loc.add(Repository.getMd5Sum(file.getAbsolutePath())); } result.add(StringUtils.join(loc, ";")); } return result; }
From source file:de.clusteval.run.result.RunAnalysisRunResult.java
/** * @param run/*from w ww . j a v a2 s . c om*/ * The run analysis run corresponding to the given runresult * folder. * @param repository * The repository in which we want to register the parsed * runresult. * @param runResultFolder * A file object referencing the runresult folder. * @return The run analysis runresult parsed from the given runresult * folder. * @throws RunResultParseException * @throws RegisterException * */ public static RunAnalysisRunResult parseFromRunResultFolder(final RunAnalysisRun run, final Repository repository, final File runResultFolder, final List<RunResult> result, final boolean register) throws RunResultParseException, RegisterException { RunAnalysisRunResult analysisResult = null; File analysesFolder = new File(FileUtils.buildPath(runResultFolder.getAbsolutePath(), "analyses")); analysisResult = new RunAnalysisRunResult(repository, false, analysesFolder.lastModified(), analysesFolder, analysesFolder.getParentFile().getName(), run); for (final String uniqueRunIdentifier : run.getUniqueRunAnalysisRunIdentifiers()) { List<RunStatistic> statistics = new ArrayList<RunStatistic>(); for (final Statistic runStatistic : run.getStatistics()) { final File completeFile = new File(FileUtils.buildPath(analysesFolder.getAbsolutePath(), uniqueRunIdentifier + "_" + runStatistic.getIdentifier() + ".txt")); if (!completeFile.exists()) throw new RunResultParseException("The result file of (" + uniqueRunIdentifier + "," + runStatistic.getIdentifier() + ") could not be found: " + completeFile); final String fileContents = FileUtils.readStringFromFile(completeFile.getAbsolutePath()); runStatistic.parseFromString(fileContents); statistics.add((RunStatistic) runStatistic); } analysisResult.put(uniqueRunIdentifier, statistics); } result.add(analysisResult); if (register) analysisResult.register(); return analysisResult; }