List of usage examples for java.io File lastModified
public long lastModified()
From source file:httpUtils.HttpUtils.java
/** * Get the file as an HttpServletResponse * @param request//from w ww. ja va 2 s. c om * @param response * @param file * @return */ public static HttpServletResponse getAssetAsStream(HttpServletRequest request, HttpServletResponse response, File file) { InputStream dataStream = null; try { dataStream = new FileInputStream(file); } catch (FileNotFoundException e) { log.warn("file not found", e); } long fileLength = file.length(); String fileName = file.getName(); long fileLastModified = file.lastModified(); String contentType = null; Path path = FileSystems.getDefault().getPath("", file.getPath()); try { contentType = Files.probeContentType(path); } catch (IOException e) { log.warn("content type determination failed", e); } //TODO make this better if (fileName.endsWith("js") && contentType == null) { contentType = "application/javascript"; } else if (fileName.endsWith("css") && contentType == null) { contentType = "text/css"; } return getFileAsStream(request, response, dataStream, fileLength, fileName, fileLastModified, contentType); }
From source file:net.paoding.analysis.knife.PaodingMaker.java
private static long getFileLastModified(File file) throws IOException { String path = file.getPath(); int jarIndex = path.indexOf(".jar!"); if (jarIndex == -1) { return file.lastModified(); } else {//from w w w. j av a 2 s . c o m path = path.replaceAll("%20", " ").replaceAll("\\\\", "/"); jarIndex = path.indexOf(".jar!"); int protocalIndex = path.indexOf(":"); String jarPath = path.substring(protocalIndex + ":".length(), jarIndex + ".jar".length()); File jarPathFile = new File(jarPath); JarFile jarFile; try { jarFile = new JarFile(jarPathFile); String entryPath = path.substring(jarIndex + ".jar!/".length()); JarEntry entry = jarFile.getJarEntry(entryPath); return entry.getTime(); } catch (IOException e) { System.err.println("error in handler path=" + path); System.err.println("error in handler jarPath=" + jarPath); throw e; } } }
From source file:exifIndexer.MetadataReader.java
public static void walk(String path, boolean is_recursive) { File root = new File(path); File[] list = root.listFiles(); String filePath;/*from www . j a v a2 s. c o m*/ String fileName; String fileExt; String valueName; String tagName; String catName; Metadata metadata; long fileSize; long fileLastModified; java.util.Date utilDate; java.sql.Date sqlDate; String sql = "{ ? = call INSERTIMAGE(?,?,?,?,?) }"; String sqlMetaData = "{ call INSERTMETADATA (?,?,?,?) }"; CallableStatement statement; CallableStatement statementMeta; long result; if (list == null) { return; } for (File f : list) { if (f.isDirectory() && is_recursive) { walk(f.getAbsolutePath(), true); } else { filePath = FilenameUtils.getFullPath(f.getAbsolutePath()); fileName = FilenameUtils.getBaseName(f.getName()); fileExt = FilenameUtils.getExtension(f.getName()); utilDate = new java.util.Date(f.lastModified()); sqlDate = new java.sql.Date(utilDate.getTime()); fileSize = f.length(); try { metadata = ImageMetadataReader.readMetadata(f.getAbsoluteFile()); try { DBHandler db = new DBHandler(); db.openConnection(); Connection con = db.getCon(); // llamada al metodo insertar imagen SQL con (filePath,fileName,fileExtension,fileSize, fileLastModified) statement = con.prepareCall(sql); statement.setString(2, filePath); statement.setString(3, fileName); statement.setString(4, fileExt); statement.setLong(5, fileSize); statement.setDate(6, sqlDate); statement.registerOutParameter(1, java.sql.Types.NUMERIC); statement.execute(); result = statement.getLong(1); // llamada al metodo insertar metadatos SQL con (idImg,valueName, tagName, catName) for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { valueName = tag.getDescription(); tagName = tag.getTagName(); catName = directory.getName(); if (isNull(valueName) || isNull(tagName) || isNull(catName) || valueName.equals("") || tagName.equals("") || catName.equals("") || valueName.length() > 250 || tagName.length() > 250 || catName.length() > 500) { System.out.println("Exif row omitted."); System.out.println("Omitting: [" + catName + "] " + tagName + " " + valueName); } else { statementMeta = con.prepareCall(sqlMetaData); statementMeta.setLong(1, result); statementMeta.setString(2, valueName); statementMeta.setString(3, tagName); statementMeta.setString(4, catName); statementMeta.executeUpdate(); } } } db.closeConnection(); } catch (SQLException ex) { System.err.println("Error with SQL command. \n" + ex); } } catch (ImageProcessingException e) { System.out.println("ImageProcessingException " + e); } catch (IOException e) { System.out.println("IOException " + e); } } } }
From source file:net.jcreate.xkins.XkinsLoader.java
public static void addDefinitionFilesTimeStamp(File file) { if (file == null) { return;/* w w w. j a v a2 s. co m*/ } getDefinitionFilesTimeStamp().put(file.getPath(), new Long(file.lastModified())); }
From source file:com.otaupdater.utils.Utils.java
public static String md5(File f) { if (!f.exists()) return ""; if (MD5_FILE_CACHE.containsKey(f)) { String cachedMD5 = MD5_FILE_CACHE.get(f); int cachedMD5Split = cachedMD5.indexOf(':'); long lastModified = Long.parseLong(cachedMD5.substring(cachedMD5Split + 1)); if (lastModified == f.lastModified()) { return cachedMD5.substring(0, cachedMD5Split); } else {/*from w w w. j av a 2 s . c o m*/ MD5_FILE_CACHE.remove(f); } } InputStream in = null; try { in = new FileInputStream(f); MessageDigest digest = MessageDigest.getInstance("MD5"); byte[] buf = new byte[4096]; int nRead; while ((nRead = in.read(buf)) != -1) { digest.update(buf, 0, nRead); } String md5 = byteArrToStr(digest.digest()); MD5_FILE_CACHE.put(f, md5 + ":" + Long.toString(f.lastModified())); return md5; } catch (Exception e) { e.printStackTrace(); } finally { if (in != null) { try { in.close(); } catch (IOException ignored) { } } } return ""; }
From source file:de.unileipzig.ub.indexer.App.java
public static long getLineCount(String filename) throws FileNotFoundException, IOException { long lines = 0; final File file = new File(filename); if (file.length() == 0) { return 0L; }//from www . j a va 2 s.c o m // use memcached if available final String mKey = "getLineCount::" + filename + "::" + file.lastModified(); if (memcachedClient != null) { final Object cachedObject = memcachedClient.get(mKey); if (cachedObject != null) { try { lines = Long.parseLong(cachedObject.toString()); logger.debug("cache hit on: " + mKey); return lines; } catch (NumberFormatException e) { // invalidate this cache item memcachedClient.delete(mKey); } } } BufferedReader reader = new BufferedReader(new FileReader(filename)); while (reader.readLine() != null) { lines++; } reader.close(); if (memcachedClient != null) { memcachedClient.set(mKey, 2592000, lines); logger.debug("updated cache: " + mKey); } return lines; }
From source file:dk.netarkivet.common.utils.arc.ARCUtils.java
/** * Write a file to an ARC file. The writing is done by * an existing ARCWriter./*from w w w. j av a 2 s . c o m*/ * An ARCRecord will be added, which contains a header and the contents * of the file. The date of the record written will be set to * the lastModified value of the file being written. * @param aw The ARCWriter doing the writing * @param file The file we want to write to the ARC file * @param uri The uri for the ARCRecord being written * @param mime The mimetype for the ARCRecord being written * @throws ArgumentNotValid if any arguments aw and file are null * and arguments uri and mime are null or empty. */ public static void writeFileToARC(ARCWriter aw, File file, String uri, String mime) { ArgumentNotValid.checkNotNull(aw, "ARCWriter aw"); ArgumentNotValid.checkNotNull(file, "File file"); ArgumentNotValid.checkNotNullOrEmpty(uri, "String uri"); ArgumentNotValid.checkNotNullOrEmpty(mime, "String mime"); InputStream is = null; try { try { //Prepare metadata... String ip = SystemUtils.getLocalIP(); long timeStamp = file.lastModified(); long length = file.length(); //...and write the CDX file's content into the writer is = new FileInputStream(file); aw.write(uri, mime, ip, timeStamp, length, is); } finally { if (is != null) { is.close(); } } } catch (IOException e) { String msg = "Error writing '" + file + "' to " + aw + " as " + uri; log.warn(msg, e); throw new IOFailure(msg, e); } }
From source file:AIR.ResourceBundler.Console.ResourcesBuilder.java
private static void writeFileHeader(FileWriter sw, String filePath) throws IOException { File scriptInfo = new File(filePath); // get file crc String crcResult = ""; FileInputStream fs = new FileInputStream(filePath); byte[] bb = new byte[4]; int i = fs.hashCode(); for (int k = 3, j = 0; k >= 0; k--, j += 8) { bb[k] = (byte) (i >> j); }/*from w w w . j a v a 2 s.c om*/ for (byte b : bb) crcResult += String.format("%2X", b).toLowerCase(); // write out script info String resourceFile = Path.getFileName(filePath); sw.write(String.format("/* SOURCE FILE: %s (%s) %s */\n", resourceFile, crcResult, scriptInfo.lastModified())); sw.write("\n"); }
From source file:net.mybox.mybox.Common.java
static private List<MyFile> getFileListingNoSort(String localParent, File aStartingDir) throws FileNotFoundException { List<MyFile> result = new ArrayList<MyFile>(); File[] filesAndDirs = aStartingDir.listFiles(); List<File> filesDirs = Arrays.asList(filesAndDirs); for (File file : filesDirs) { String prefix = ""; if (!localParent.equals("")) prefix = localParent + "/"; MyFile myFile = new MyFile(prefix + file.getName()); // myFile.name = localParent + "/" + file.getName(); myFile.modtime = file.lastModified(); if (file.isFile()) { myFile.type = "file"; result.add(myFile);/* ww w. j ava2 s .com*/ } else if (file.isDirectory()) { myFile.type = "directory"; result.add(myFile); //result.add(file); //always add, even if directory //if ( ! file.isFile() ) { //must be a directory //recursive call! List<MyFile> deeperList = getFileListingNoSort(prefix + file.getName(), file); result.addAll(deeperList); } } return result; }
From source file:net.naijatek.myalumni.util.utilities.FileUtil.java
public static List<FileHelper> getDirFileNameLength(final File dir, String fileExt) throws IOException { List<FileHelper> content = new ArrayList<FileHelper>(); File[] files = dir.listFiles(); FileHelper fh = null;/*from w w w.j a v a 2 s . c o m*/ if (files != null) { for (File file : files) { fh = new FileHelper(); if (file.isFile() && !file.getName().startsWith(".") && file.getName().indexOf(fileExt) > 1) { fh.setFileName(file.getName()); fh.setFileSize(getHumanSize(file.length())); fh.setFileDate(new Date(file.lastModified())); content.add(fh); } } //for } //if return content; }