List of usage examples for java.io File lastModified
public long lastModified()
From source file:com.ms.commons.fasttext.FasttextService.java
private static boolean checkFile(boolean isInit) { String path = System.getProperty(BANNED_DIR); if (path == null || path.trim().length() == 0) { return false; }/*from w w w .j a v a 2s . c o m*/ String weijinfilename = path + File.separator + BANNEDWORD; String forkfilename = path + File.separator + RADICALDIC; String homofilename = path + File.separator + HOMOPHONE; File wf = new File(weijinfilename); File ff = new File(forkfilename); File hf = new File(homofilename); boolean flag = wf.exists() && ff.exists() && hf.exists(); if (flag && isInit) { weijinLastModified = wf.lastModified(); forkLastModified = ff.lastModified(); homoLastModified = hf.lastModified(); } return flag; }
From source file:ch.entwine.weblounge.common.content.ResourceUtils.java
/** * Returns the value for the <code>ETag</code> header field, which is * calculated from the file's modification date. * /*from w w w . j ava 2 s . c o m*/ * @param file * the file * @return the <code>ETag</code> value * @throws IllegalArgumentException * if <code>file</code> is <code>null</code> */ public static String getETagValue(File file) { if (file == null) throw new IllegalArgumentException("File must not be null"); return getETagValue(file.lastModified()); }
From source file:org.commonjava.cartographer.rest.util.ResponseUtils.java
public static ResponseBuilder setInfoHeaders(final ResponseBuilder builder, final File item, final boolean includeContentLength, final String contentType) throws CartoRESTException { // I don't think we want to use the result from upstream; it's often junk...we should retain control of this. builder.header(ApplicationHeader.content_type.key(), contentType); builder.header(ApplicationHeader.last_modified.key(), HttpUtils.formatDateHeader(item.lastModified())); if (includeContentLength) { builder.header(ApplicationHeader.content_length.key(), item.length()); }//from w ww . ja va 2 s.c o m return builder; }
From source file:cn.fql.utility.FileUtility.java
/** * Copy source folder's content to a new folder, if there are existed duplicated files and overwrite * flag is true, it might overwrite it//from ww w.j a va 2s . com * * @param sourceFolder source folder path * @param newFolder new folder path * @param forceOverwrite determine whether it is required to overwrite for duplicated files */ public static void copyFolder(String sourceFolder, String newFolder, boolean forceOverwrite) { String oldPath = StringUtils.replace(sourceFolder, "/", File.separator); String newPath = StringUtils.replace(newFolder, "/", File.separator); if (!oldPath.endsWith(File.separator)) { oldPath = oldPath + File.separator; } if (!newPath.endsWith(File.separator)) { newPath = newPath + File.separator; } new File(newPath).mkdirs(); File sourceDir = new File(oldPath); String[] files = sourceDir.list(); File oldFile; File newFile; for (int i = 0; i < files.length; i++) { oldFile = new File(oldPath + files[i]); newFile = new File(newPath + files[i]); if (oldFile.isFile() && (!forceOverwrite || (!newFile.exists() || oldFile.length() != newFile.length() || oldFile.lastModified() > newFile.lastModified()))) { copyFile(oldFile.getPath(), newFile.getPath()); } if (oldFile.isDirectory()) { copyFolder(oldPath + files[i], newPath + files[i], forceOverwrite); } } }
From source file:org.eclipse.wst.json.core.internal.download.HttpClientProvider.java
public static File getFile(URL url) throws IOException { if (url == null) { return null; }/* w w w. ja va2s . c om*/ if (PROTOCOL_FILE.equals(url.getProtocol()) || PROTOCOL_PLATFORM.equalsIgnoreCase(url.getProtocol())) { File file; try { file = new File(new URI(url.toExternalForm())); } catch (Exception e) { file = new File(url.getFile()); } if (!file.exists()) { return null; } return file; } File file = getCachedFile(url); long urlLastModified = getLastModified(url); if (file.exists()) { long lastModified = file.lastModified(); if (urlLastModified > lastModified) { file = download(file, url); if (file != null) { file.setLastModified(urlLastModified); } } } else { file = download(file, url); if (file != null && urlLastModified > -1) { file.setLastModified(urlLastModified); } } return file; }
From source file:setiquest.renderer.Utils.java
/** * Remove old compamp files.//from w w w . jav a2 s . c om * @param dir the full path directory containing the files. * @param maxSecs the maximum seconds a file should live. */ public static int purgeOldCompampFiles(String dir, long maxSecs) { File directory = new File(dir); int count = 0; Log.log("Purging from " + dir); if (directory.exists()) { File[] listFiles = directory.listFiles(); long purgeTime = System.currentTimeMillis() - (maxSecs * 1000); for (File listFile : listFiles) { Log.log("Purging: " + listFile.getName()); if ((listFile.getName().contains(".requested.R.compamp") || listFile.getName().contains(".requested.L.compamp")) && listFile.lastModified() < purgeTime) { if (!listFile.delete()) { Log.log("Unable to delete file: " + listFile); } else { Log.log("Deleted ol compamp file: " + listFile + ", " + listFile.lastModified() + "," + purgeTime); count++; } } } } else { Log.log("Files were not deleted, directory " + dir + " does'nt exist!"); System.out.println("Files were not deleted, directory " + dir + " does'nt exist!"); } return count; }
From source file:ch.entwine.weblounge.common.content.ResourceUtils.java
/** * Returns <code>true</code> if the resource either is more recent than the * cached version on the client side with respect to the file's modification * date or the request does not contain caching information. * <p>// w ww.ja v a 2s. c om * The calculation is made based on the availability of either the * <code>If-None-Match</code> or the <code>If-Modified-Since</code> header (in * this order). * * @param request * the client request * @param file * the file * @return <code>true</code> if the resource is more recent than the version * that is cached at the client. * @throws IllegalArgumentException * if the <code>If-Modified-Since</code> header cannot be converted * to a date. */ public static boolean hasChanged(HttpServletRequest request, File file) throws IllegalArgumentException { if (file == null || !file.isFile()) return true; return hasChanged(request, file.lastModified()); }
From source file:edu.umd.cs.submit.CommandLineSubmit.java
/** * @param p/* w w w . j a v a 2s . c o m*/ * @param find * @param files * @param userProps * @return * @throws IOException * @throws FileNotFoundException */ public static MultipartPostMethod createFilePost(Properties p, FindAllFiles find, Collection<File> files, Properties userProps) throws IOException, FileNotFoundException { // ========================== assemble zip file in byte array // ============================== String loginName = userProps.getProperty("loginName"); String classAccount = userProps.getProperty("classAccount"); String from = classAccount; if (loginName != null && !loginName.equals(classAccount)) from += "/" + loginName; System.out.println(" submitted by " + from); System.out.println(); System.out.println("Submitting the following files"); ByteArrayOutputStream bytes = new ByteArrayOutputStream(4096); byte[] buf = new byte[4096]; ZipOutputStream zipfile = new ZipOutputStream(bytes); zipfile.setComment("zipfile for CommandLineTurnin, version " + VERSION); for (File resource : files) { if (resource.isDirectory()) continue; String relativePath = resource.getCanonicalPath().substring(find.rootPathLength + 1); System.out.println(relativePath); ZipEntry entry = new ZipEntry(relativePath); entry.setTime(resource.lastModified()); zipfile.putNextEntry(entry); InputStream in = new FileInputStream(resource); try { while (true) { int n = in.read(buf); if (n < 0) break; zipfile.write(buf, 0, n); } } finally { in.close(); } zipfile.closeEntry(); } // for each file zipfile.close(); MultipartPostMethod filePost = new MultipartPostMethod(p.getProperty("submitURL")); p.putAll(userProps); // add properties for (Map.Entry<?, ?> e : p.entrySet()) { String key = (String) e.getKey(); String value = (String) e.getValue(); if (!key.equals("submitURL")) filePost.addParameter(key, value); } filePost.addParameter("submitClientTool", "CommandLineTool"); filePost.addParameter("submitClientVersion", VERSION); byte[] allInput = bytes.toByteArray(); filePost.addPart(new FilePart("submittedFiles", new ByteArrayPartSource("submit.zip", allInput))); return filePost; }
From source file:ee.ria.xroad.proxy.messagelog.MessageLogTest.java
private static boolean changesLatestModified(File former, File candidate) { return former == null || former.lastModified() < candidate.lastModified(); }
From source file:Main.java
private static void compressDir(File srcFile, ZipOutputStream out, String destPath) throws IOException { if (srcFile.isDirectory()) { File subfile[] = srcFile.listFiles(); for (int i = 0; i < subfile.length; i++) { compressDir(subfile[i], out, destPath); }//from ww w . j av a 2 s . com } else { InputStream in = new FileInputStream(srcFile); String name = srcFile.getAbsolutePath().replace(destPath, ""); if (name.startsWith("\\")) name = name.substring(1); ZipEntry entry = new ZipEntry(name); entry.setSize(srcFile.length()); entry.setTime(srcFile.lastModified()); out.putNextEntry(entry); int len = -1; byte buf[] = new byte[1024]; while ((len = in.read(buf, 0, 1024)) != -1) out.write(buf, 0, len); out.closeEntry(); in.close(); } }