Example usage for java.io File lastModified

List of usage examples for java.io File lastModified

Introduction

In this page you can find the example usage for java.io File lastModified.

Prototype

public long lastModified() 

Source Link

Document

Returns the time that the file denoted by this abstract pathname was last modified.

Usage

From source file:com.netxforge.oss2.config.WmiDataCollectionConfigFactory.java

/**
 * Be sure to call this method before calling getInstance().
 *
 * @throws java.io.IOException if any.//ww w .  j  a v a 2s  . c  om
 * @throws java.io.FileNotFoundException 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, FileNotFoundException, MarshalException, ValidationException {

    if (m_instance == null) {
        File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.WMI_COLLECTION_CONFIG_FILE_NAME);
        m_instance = new WmiDataCollectionConfigFactory(cfgFile.getPath());
        m_lastModified = cfgFile.lastModified();
        m_loadedFromFile = true;
    }
}

From source file:com.titilink.camel.rest.util.OtherUtil.java

/**
 * ??//from  w  ww .ja v a2s.  c  om
 *
 * @param filename --??
 * @return long -- 0-????0
 */
public static long getFileLastModified(String filename) {
    long l = 0;
    File f = new File(filename);
    if (f.exists()) {
        try {
            l = f.lastModified();
        } catch (SecurityException se) {
            l = 0;
            se.printStackTrace(); //NOPMD
        }
    }
    return l;
}

From source file:dk.netarkivet.common.utils.Settings.java

/**
 * Reload the settings if they have changed on disk. This behaves exactly as
 * forceReload, except it only reloads if the data of the file is different
 * than last time it was loaded.//from  w ww . j  a v a 2s .c o  m
 *
 * @throws IOFailure if settings cannot be loaded
 */
public static synchronized void conditionalReload() {
    List<File> settingsFiles = getSettingsFiles();
    for (File settingsFile : settingsFiles) {
        if (settingsFile.lastModified() > lastModified) {
            log.info("Do reload of settings, as the file '" + settingsFile.getAbsolutePath()
                    + "' has changed since last reload");
            reload();
            return;
        }
    }
}

From source file:com.zimbra.common.util.TemplateCompiler.java

private static boolean upToDate(File ifile, File ofile) {
    if (ifile.exists() && ofile.exists()) {
        return ifile.lastModified() < ofile.lastModified();
    }//from ww  w.  j  av a  2s .co  m
    return false;
}

From source file:com.seajas.search.contender.service.builder.RSSDirectoryBuilder.java

/**
 * Recursively travel a directory and add all files to the result
 *
 * @param directory//  w  w w.  j  ava 2  s.co  m
 * @param result
 * @return Map<String, Long>
 */
private static Map<String, Long> travelDirectory(final File directory, final Map<String, Long> result) {
    // Skip files that start with a '.'

    if (!directory.getName().startsWith(".")) {
        if (directory.isDirectory())
            for (File child : directory.listFiles())
                travelDirectory(child, result);
        else if (directory.isFile())
            result.put(directory.getAbsolutePath(), directory.lastModified());
        else
            logger.warn("Unknown type for file " + directory);
    }

    return result;
}

From source file:com.liferay.portal.servlet.filters.dynamiccss.DynamicCSSUtil.java

public static String parseSass(HttpServletRequest request, String cssRealPath, String content)
        throws Exception {

    if (!DynamicCSSFilter.ENABLED) {
        return content;
    }// w ww  .  ja v  a  2 s  .  c om

    StopWatch stopWatch = null;

    if (_log.isDebugEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();
    }

    // Request will only be null when called by StripFilterTest

    if (request == null) {
        return content;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Theme theme = null;

    if (themeDisplay == null) {
        theme = _getTheme(request, cssRealPath);

        if (theme == null) {
            String currentURL = PortalUtil.getCurrentURL(request);

            if (_log.isWarnEnabled()) {
                _log.warn("No theme found for " + currentURL);
            }

            return content;
        }
    }

    String parsedContent = null;

    boolean themeCssFastLoad = _isThemeCssFastLoad(request, themeDisplay);

    File cssRealFile = new File(cssRealPath);
    File cacheCssRealFile = SassToCssBuilder.getCacheFile(cssRealPath);

    if (themeCssFastLoad && cacheCssRealFile.exists()
            && (cacheCssRealFile.lastModified() == cssRealFile.lastModified())) {

        parsedContent = FileUtil.read(cacheCssRealFile);

        if (_log.isDebugEnabled()) {
            _log.debug("Loading SASS cache from " + cacheCssRealFile + " takes " + stopWatch.getTime() + " ms");
        }
    } else {
        content = SassToCssBuilder.parseStaticTokens(content);

        String queryString = request.getQueryString();

        if (!themeCssFastLoad && Validator.isNotNull(queryString)) {
            content = _propagateQueryString(content, queryString);
        }

        parsedContent = _parseSass(request, themeDisplay, theme, cssRealPath, content);

        if (_log.isDebugEnabled()) {
            _log.debug("Parsing SASS for " + cssRealPath + " takes " + stopWatch.getTime() + " ms");
        }
    }

    if (Validator.isNull(parsedContent)) {
        return content;
    }

    parsedContent = StringUtil.replace(parsedContent, new String[] { "@portal_ctx@", "@theme_image_path@" },
            new String[] { PortalUtil.getPathContext(), _getThemeImagesPath(request, themeDisplay, theme) });

    return parsedContent;
}

From source file:edu.ku.brc.specify.tasks.subpane.JasperReportsCache.java

/**
 * Checks to see if any files in the database need to be copied to the database. A file may not
 * exist or be out of date./*from w w  w. j  a va  2  s.  c  om*/
 */
protected static void refreshCacheFromDatabase(final String mimeType) {
    File cachePath = getCachePath();

    Hashtable<String, File> hash = new Hashtable<String, File>();
    for (File f : cachePath.listFiles()) {
        //log.info("Report Cache File["+f.getName()+"]");
        hash.put(f.getName(), f);
    }

    for (AppResourceIFace ap : AppContextMgr.getInstance().getResourceByMimeType(mimeType)) {
        // Check to see if the resource or file has changed.
        boolean updateCache = false;
        File fileFromJasperCache = hash.get(ap.getName());
        if (fileFromJasperCache == null) {
            updateCache = true;

        } else {
            Date fileDate = new Date(fileFromJasperCache.lastModified());
            Timestamp apTime = ap.getTimestampModified() == null ? ap.getTimestampCreated()
                    : ap.getTimestampModified();
            updateCache = apTime == null || fileDate.getTime() < apTime.getTime();
        }

        // If it has changed then copy the contents into the cache and delete the compiled file
        // so it forces it to be recompiled.
        if (updateCache) {
            File localFilePath = new File(cachePath.getAbsoluteFile() + File.separator + ap.getName());
            try {
                XMLHelper.setContents(localFilePath, ap.getDataAsString());

                File compiledFile = getCompiledFile(localFilePath);
                if (compiledFile.exists()) {
                    compiledFile.delete();
                }

            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(JasperReportsCache.class, ex);
                throw new RuntimeException(ex);
            }
        }
    }
}

From source file:at.ac.uniklu.mobile.sportal.util.Utils.java

/**
 * Loads a bitmap for the network or from a cached file, if it has already been downloaded before. If the file
 * is loaded for the first time, it is written to the cache to be available next time.
 * //from  w  w  w .  jav  a  2s  . c o m
 * @param context
 * @param sourceUrl
 * @param cacheFileName
 * @return a bitmap or null if something went wrong
 */
public static Bitmap downloadBitmapWithCache(Context context, String sourceUrl, String cacheFileName)
        throws Exception {
    Bitmap bitmap = null;
    File cacheFile = new File(context.getCacheDir(), cacheFileName);

    boolean cached = cacheFile.exists();
    boolean cachedValid = cached && cacheFile.lastModified() > (System.currentTimeMillis() - MILLIS_PER_WEEK);

    if (cached && cachedValid) {
        // the requested file is cached, load it
        Log.d(TAG, "loading cached file: " + cacheFileName);
        bitmap = BitmapFactory.decodeFile(cacheFile.getAbsolutePath());
    } else {
        // the requested file is not cached, download it from the network
        Log.d(TAG, "file " + (cachedValid ? "too old" : "not cached") + ", downloading: " + sourceUrl);
        byte[] data = downloadFile(sourceUrl, 3);
        if (data != null) {
            bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
            if (bitmap != null) {
                // the download succeeded, cache the file so it is available next time
                FileOutputStream out = new FileOutputStream(cacheFile);
                out.write(data, 0, data.length);
                out.flush();
                out.close();
            } else {
                Log.e(TAG, "failed to download bitmap, may be an unsupported format: " + sourceUrl);
            }
        }
    }

    return bitmap;
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.QcliveAbstractBaseIntegrationTest.java

/**
 * Checks that the last modified date of the given file is on or after the test start date
 *
 * @param file the file//from   ww  w.  j  av a 2s . c om
 */
protected static void checkLastModified(final File file) {
    logger.info(" checkLastModified - IN");
    final Date lastModifiedDate = new Date(file.lastModified());
    assertFalse(lastModifiedDate.before(testStartDate));
    logger.info(" checkLastModified - OUT");
}

From source file:com.ms.commons.test.classloader.IntlTestURLClassPath.java

private static boolean isOutOfDate(File signature, URL jar, StringBuilder refAst) throws IOException {
    File jf = FileUtil.convertURLToFile(jar);
    long len = jf.length();
    long mod = jf.lastModified();
    String ast = String.valueOf(len) + "/" + String.valueOf(mod);
    refAst.append(ast);/*from   w w w  .j  a v  a 2s.  com*/

    if (!signature.exists()) {
        return true;
    }
    String st = FileUtils.readFileToString(signature);
    return (!StringUtil.trimedIgnoreCaseEquals(st, ast));
}