List of usage examples for java.io File lastModified
public long lastModified()
From source file:msi.gama.gui.swt.WorkspaceModelsManager.java
public static String getCurrentGamaStampString() { String gamaStamp = null;/*from w w w. j a v a 2 s . c o m*/ try { URL urlRep = FileLocator.toFileURL(new URL("platform:/plugin/msi.gama.models/models/")); File modelsRep = new File(urlRep.getPath()); long time = modelsRep.lastModified(); gamaStamp = ".built_in_models_" + time; System.out.println("Version of the models in GAMA = " + gamaStamp); } catch (IOException e) { e.printStackTrace(); } return gamaStamp; }
From source file:com.alibaba.jstorm.cluster.StormConfig.java
public static long get_supervisor_topology_Bianrymodify_time(Map conf, String topologyId) throws IOException { String topologyRoot = StormConfig.supervisor_stormdist_root(conf, topologyId); File f = new File(topologyRoot); long modifyTime = f.lastModified(); return modifyTime; }
From source file:com.netxforge.oss2.config.SnmpInterfacePollerConfigFactory.java
/** * Load the config from the default config file and create the singleton * instance of this factory./*from w w w . ja v a 2 s. c o m*/ * * @exception java.io.IOException * Thrown if the specified config file cannot be read * @exception org.exolab.castor.xml.MarshalException * Thrown if the file does not conform to the schema. * @exception org.exolab.castor.xml.ValidationException * Thrown if the contents do not match the required schema. * @throws java.io.IOException if any. * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. */ public static synchronized void init() throws IOException, MarshalException, ValidationException { if (m_loaded) { // init already called - return // to reload, reload() will need to be called return; } OpennmsServerConfigFactory.init(); OpennmsServerConfigFactory onmsSvrConfig = OpennmsServerConfigFactory.getInstance(); File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.SNMP_INTERFACE_POLLER_CONFIG_FILE_NAME); logStatic().debug("init: config file path: " + cfgFile.getPath()); InputStream stream = null; try { stream = new FileInputStream(cfgFile); SnmpInterfacePollerConfigFactory config = new SnmpInterfacePollerConfigFactory(cfgFile.lastModified(), stream, onmsSvrConfig.getServerName(), onmsSvrConfig.verifyServer()); setInstance(config); } finally { if (stream != null) { IOUtils.closeQuietly(stream); } } }
From source file:com.machinepublishers.jbrowserdriver.StreamConnectionClient.java
private static SSLContext sslContext() { final String property = SettingsManager.settings().ssl(); if (property != null && !property.isEmpty() && !"null".equals(property)) { if ("trustanything".equals(property)) { try { return SSLContexts.custom().loadTrustMaterial(KeyStore.getInstance(KeyStore.getDefaultType()), new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; }//from ww w. java 2s . c o m }).build(); } catch (Throwable t) { LogsServer.instance().exception(t); } } else { try { String location = property; location = location.equals("compatible") ? "https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt" : location; File cachedPemFile = new File("./pemfile_cached"); boolean remote = location.startsWith("https://") || location.startsWith("http://"); if (remote && cachedPemFile.exists() && (System.currentTimeMillis() - cachedPemFile.lastModified() < 48 * 60 * 60 * 1000)) { location = cachedPemFile.getAbsolutePath(); remote = false; } String pemBlocks = null; if (remote) { HttpURLConnection remotePemFile = (HttpURLConnection) StreamHandler .defaultConnection(new URL(location)); remotePemFile.setRequestMethod("GET"); remotePemFile.connect(); pemBlocks = Util.toString(remotePemFile.getInputStream(), Util.charset(remotePemFile)); cachedPemFile.delete(); Files.write(Paths.get(cachedPemFile.getAbsolutePath()), pemBlocks.getBytes("utf-8")); } else { pemBlocks = new String(Files.readAllBytes(Paths.get(new File(location).getAbsolutePath())), "utf-8"); } KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(null); CertificateFactory cf = CertificateFactory.getInstance("X.509"); Matcher matcher = pemBlock.matcher(pemBlocks); boolean found = false; while (matcher.find()) { String pemBlock = matcher.group(1).replaceAll("[\\n\\r]+", ""); ByteArrayInputStream byteStream = new ByteArrayInputStream( Base64.getDecoder().decode(pemBlock)); java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate) cf .generateCertificate(byteStream); String alias = cert.getSubjectX500Principal().getName("RFC2253"); if (alias != null && !keyStore.containsAlias(alias)) { found = true; keyStore.setCertificateEntry(alias, cert); } } if (found) { KeyManagerFactory keyManager = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyManager.init(keyStore, null); TrustManagerFactory trustManager = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManager.init(keyStore); SSLContext context = SSLContext.getInstance("TLS"); context.init(keyManager.getKeyManagers(), trustManager.getTrustManagers(), null); return context; } } catch (Throwable t) { LogsServer.instance().exception(t); } } } return SSLContexts.createSystemDefault(); }
From source file:com.netxforge.oss2.config.LinkdConfigFactory.java
/** * Load the config from the default config file and create the singleton * instance of this factory.//from w w w. j ava 2 s. c o m * * @exception java.io.IOException * Thrown if the specified config file cannot be read * @exception org.exolab.castor.xml.MarshalException * Thrown if the file does not conform to the schema. * @exception org.exolab.castor.xml.ValidationException * Thrown if the contents do not match the required schema. * @throws java.io.IOException if any. * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. */ public static synchronized void init() throws IOException, MarshalException, ValidationException { if (m_loaded) { // init already called - return // to reload, reload() will need to be called return; } final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.LINKD_CONFIG_FILE_NAME); LogUtils.debugf(LinkdConfigFactory.class, "init: config file path: %s", cfgFile.getPath()); InputStream stream = null; try { stream = new FileInputStream(cfgFile); setInstance(new LinkdConfigFactory(cfgFile.lastModified(), stream)); } finally { IOUtils.closeQuietly(stream); } }
From source file:Main.java
public static void compressAFileToZip(File zip, File source) throws IOException { Log.d("source: " + source.getAbsolutePath(), ", length: " + source.length()); Log.d("zip:", zip.getAbsolutePath()); zip.getParentFile().mkdirs();/*from w w w . j a v a 2s . c om*/ File tempFile = new File(zip.getAbsolutePath() + ".tmp"); FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos); ZipOutputStream zos = new ZipOutputStream(bos); ZipEntry zipEntry = new ZipEntry(source.getName()); zipEntry.setTime(source.lastModified()); zos.putNextEntry(zipEntry); FileInputStream fis = new FileInputStream(source); BufferedInputStream bis = new BufferedInputStream(fis); byte[] bArr = new byte[4096]; int byteRead = 0; while ((byteRead = bis.read(bArr)) != -1) { zos.write(bArr, 0, byteRead); } zos.flush(); zos.closeEntry(); zos.close(); Log.d("zipEntry: " + zipEntry, "compressedSize: " + zipEntry.getCompressedSize()); bos.flush(); fos.flush(); bos.close(); fos.close(); bis.close(); fis.close(); zip.delete(); tempFile.renameTo(zip); }
From source file:JarUtils.java
/** * This recursive method writes all matching files and directories to * the jar output stream.//from w ww .j a v a 2 s. c o m */ private static void jar(File src, String prefix, JarInfo info) throws IOException { JarOutputStream jout = info.out; if (src.isDirectory()) { // create / init the zip entry prefix = prefix + src.getName() + "/"; ZipEntry entry = new ZipEntry(prefix); entry.setTime(src.lastModified()); entry.setMethod(JarOutputStream.STORED); entry.setSize(0L); entry.setCrc(0L); jout.putNextEntry(entry); jout.closeEntry(); // process the sub-directories File[] files = src.listFiles(info.filter); for (int i = 0; i < files.length; i++) { jar(files[i], prefix, info); } } else if (src.isFile()) { // get the required info objects byte[] buffer = info.buffer; // create / init the zip entry ZipEntry entry = new ZipEntry(prefix + src.getName()); entry.setTime(src.lastModified()); jout.putNextEntry(entry); // dump the file FileInputStream in = new FileInputStream(src); int len; while ((len = in.read(buffer, 0, buffer.length)) != -1) { jout.write(buffer, 0, len); } in.close(); jout.closeEntry(); } }
From source file:org.eclipse.cft.server.core.internal.CloudUtil.java
private static void addZipEntries(ZipOutputStream out, List<IModuleResource> allResources, Set<IModuleResource> filterInFiles) throws Exception { if (allResources == null) return;//from www .ja v a 2s . co m for (IModuleResource resource : allResources) { if (resource instanceof IModuleFolder) { IModuleResource[] folderResources = ((IModuleFolder) resource).members(); String entryPath = getZipRelativeName(resource); ZipEntry zipEntry = new ZipEntry(entryPath); long timeStamp = 0; IContainer folder = (IContainer) resource.getAdapter(IContainer.class); if (folder != null) { timeStamp = folder.getLocalTimeStamp(); } if (timeStamp != IResource.NULL_STAMP && timeStamp != 0) { zipEntry.setTime(timeStamp); } out.putNextEntry(zipEntry); out.closeEntry(); addZipEntries(out, Arrays.asList(folderResources), filterInFiles); continue; } IModuleFile moduleFile = (IModuleFile) resource; // Only add files that are in the filterInList if (!filterInFiles.contains(moduleFile)) { continue; } String entryPath = getZipRelativeName(resource); ZipEntry zipEntry = new ZipEntry(entryPath); InputStream input = null; long timeStamp = 0; IFile iFile = (IFile) moduleFile.getAdapter(IFile.class); if (iFile != null) { timeStamp = iFile.getLocalTimeStamp(); input = iFile.getContents(); } else { File file = (File) moduleFile.getAdapter(File.class); timeStamp = file.lastModified(); input = new FileInputStream(file); } if (timeStamp != IResource.NULL_STAMP && timeStamp != 0) { zipEntry.setTime(timeStamp); } out.putNextEntry(zipEntry); try { int n = 0; while (n > -1) { n = input.read(buf); if (n > 0) { out.write(buf, 0, n); } } } finally { input.close(); } out.closeEntry(); } }
From source file:com.netxforge.oss2.config.PollerConfigFactory.java
/** * Load the config from the default config file and create the singleton * instance of this factory./*from ww w.j a va2s .c om*/ * * @exception java.io.IOException * Thrown if the specified config file cannot be read * @exception org.exolab.castor.xml.MarshalException * Thrown if the file does not conform to the schema. * @exception org.exolab.castor.xml.ValidationException * Thrown if the contents do not match the required schema. * @throws java.io.IOException if any. * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. */ public static synchronized void init() throws IOException, MarshalException, ValidationException { if (m_loaded) { // init already called - return // to reload, reload() will need to be called return; } OpennmsServerConfigFactory.init(); OpennmsServerConfigFactory onmsSvrConfig = OpennmsServerConfigFactory.getInstance(); final File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.POLLER_CONFIG_FILE_NAME); LogUtils.debugf(PollerConfigFactory.class, "init: config file path: %s", cfgFile.getPath()); InputStream stream = null; PollerConfigFactory config = null; try { stream = new FileInputStream(cfgFile); config = new PollerConfigFactory(cfgFile.lastModified(), stream, onmsSvrConfig.getServerName(), onmsSvrConfig.verifyServer()); } finally { IOUtils.closeQuietly(stream); } for (final org.opennms.netmgt.config.poller.Package pollerPackage : config.getConfiguration() .getPackageCollection()) { for (final org.opennms.netmgt.config.poller.Service service : pollerPackage.getServiceCollection()) { for (final org.opennms.netmgt.config.poller.Parameter parm : service.getParameterCollection()) { if (parm.getKey().equals("ds-name")) { if (parm.getValue().length() > ConfigFileConstants.RRD_DS_MAX_SIZE) { throw new ValidationException(String.format( "ds-name '%s' in service '%s' (poller package '%s') is greater than %d characters", parm.getValue(), service.getName(), pollerPackage.getName(), ConfigFileConstants.RRD_DS_MAX_SIZE)); } } } } } setInstance(config); }
From source file:com.amazonaws.eclipse.core.regions.RegionUtils.java
/** * Caches the regions file stored in cloudfront to the destination file * given. Tries S3 if cloudfront is unavailable. * * If the file in s3 is older than the one on disk, does nothing. *//*from w w w .j ava2 s . c o m*/ private static void cacheRegionsFile(File regionsFile) { Date regionsFileLastModified = new Date(0); if (!regionsFile.exists()) { regionsFile.getParentFile().mkdirs(); } else { regionsFileLastModified = new Date(regionsFile.lastModified()); } try { AmazonS3 s3 = AWSClientFactory.getAnonymousS3Client(); ObjectMetadata objectMetadata = s3.getObjectMetadata(REGIONS_METADATA_S3_BUCKET, REGIONS_METADATA_S3_OBJECT); if (objectMetadata.getLastModified().after(regionsFileLastModified)) { cacheRegionsFile(regionsFile, s3); } } catch (Exception e) { AwsToolkitCore.getDefault().logException("Failed to cache regions file", e); } }