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:krisa.c.gcwebviewer.inputprocessor.FileInputProcessor.java

public File getLatestGCFile(String path) {
    File dir = new File(path);
    FileFilter fileFilter = new WildcardFileFilter("*gc*");
    File[] files = dir.listFiles(fileFilter);
    log.debug("Found " + files.length + " gc logs under " + path);
    File targetFile = null;//w w w .j  a v a2s  .  co  m
    for (File file : files) {
        System.out.println(file + "," + file.lastModified());
        if (targetFile == null) {
            targetFile = file;
        } else {
            if (targetFile.lastModified() < file.lastModified()) {
                targetFile = file;
            }
        }
    }
    return targetFile;
}

From source file:com.sec.ose.osi.ui.frm.main.manage.DirectoryInfo.java

private void checkDirModified(File file) {
    totalFileCount++;//  w ww  .  j av a 2 s  . c o m
    if (file.lastModified() > baseDate) {
        isModify = true;
    }
    if (file.isDirectory()) {
        String[] children = file.list();
        if (children != null) {
            for (String child : children) {
                checkDirModified(new File(file, child));
            }
        }
    }
}

From source file:de.thischwa.pmcms.tool.image.ImageTool.java

public void createCashedImage(final VirtualImage imageFile) {
    File cachedFile = imageFile.getCacheFile();
    File srcFile = imageFile.getBaseFile();

    if (cachedFile.exists() && srcFile.lastModified() <= cachedFile.lastModified()) {
        logger.info("Image exists and isn't modified, don't need to render again: "
                .concat(cachedFile.getAbsolutePath()));
        return;//from  www. j  ava 2  s .  c  o m
    }

    if (!cachedFile.getParentFile().exists())
        cachedFile.getParentFile().mkdirs();
    try {
        imageManipulation.resizeImage(srcFile, cachedFile, imageFile.getDimension());
    } catch (Exception e) {
        throw new FatalException("Error while resizing image!", e);
    }
}

From source file:com.kylinolap.common.persistence.FileResourceStore.java

@Override
protected long checkAndPutResourceImpl(String resPath, byte[] content, long oldTS, long newTS)
        throws IOException, IllegalStateException {
    File f = file(resPath);
    if ((f.exists() && f.lastModified() != oldTS) || (f.exists() == false && oldTS != 0))
        throw new IllegalStateException("Overwriting conflict " + resPath + ", expect old TS " + oldTS
                + ", but found " + f.lastModified());

    putResourceImpl(resPath, new ByteArrayInputStream(content), newTS);

    // some FS lose precision on given time stamp
    return getResourceTimestamp(resPath);
}

From source file:entity.files.SYSFilesTools.java

/**
 * <code>putFile(String)</code> speichert eine Datei auf dem FTP Server ab und erstellt eine SYSFiles EntityBean. Die Methode geht dabei wie folgt vor:
 * <ol>//from ww  w  .jav  a  2 s  .  c  o m
 * <li>Zuerst wird der MD5 der zu speichernden Datei berechnet.</li>
 * <li>Anhand dieser MD5 Signatur wird ermittelt, ob es schon einen entsprechenden Eintrag in der Datenbank gibt.
 * <ul>
 * <li>Wenn ja, dann wird einfach der PK zurckgegeben. Nochmal speichern braucht man das ja nicht. <b>RETURN</b></li>
 * <li>Wenn nicht, dann geht die Bearbeitung weiter.</li>
 * </ul>
 * <li>Erstellen einer SYSFiles EB</li>
 * <li>Senden der Datei an den FTP Server</li>
 * <li>Wenn die letzten beiden Schritte erfolgreich waren, dann wird die neue EB als Ergebnis zurck gegeben. null, bei Fehler.</li>
 * </ol>
 *
 * @param file File Objekt der zu speichernden Datei
 * @return EB der neuen Datei. null bei Fehler.
 */
private static SYSFiles putFile(EntityManager em, FileTransferClient ftp, File file) throws Exception {
    SYSFiles sysfile = null;

    String md5 = SYSTools.getMD5Checksum(file);
    Query query = em.createQuery("SELECT s FROM SYSFiles s WHERE s.md5 = :md5");
    query.setParameter("md5", md5);

    ArrayList<SYSFiles> alreadyExistingFiles = new ArrayList<SYSFiles>(query.getResultList());

    // Gibts die Datei schon ?
    if (alreadyExistingFiles.isEmpty()) { // nein, noch nicht
        sysfile = em.merge(new SYSFiles(file.getName(), md5, new Date(file.lastModified()), file.length(),
                OPDE.getLogin().getUser()));
        //            FileInputStream fis = new FileInputStream(file);
        ftp.uploadFile(file.getPath(), sysfile.getRemoteFilename());

        //            ftp.storeF.storeFile(file.getPath(),sysfile.getRemoteFilename());
        OPDE.info(
                SYSTools.xx("misc.msg.upload") + ": " + sysfile.getFilename() + " (" + sysfile.getMd5() + ")");
        //            fis.close();
    } else { // Ansonsten die bestehende Datei zurckgeben

        sysfile = alreadyExistingFiles.get(0);

        // Does the User own this file already ?
        //            for (SYSFiles mySYSfile : alreadyExistingFiles) {
        //                if (mySYSfile.getResident().equals(resident)) {
        //                    sysfile = mySYSfile;
        //                    break;
        //                }
        //            }
        //            if (sysfile == null) {
        //                sysfile = em.merge(new SYSFiles(file.getName(), md5, new Date(file.lastModified()), file.length(), OPDE.getLogin().getUser(), resident));
        //            }
    }

    return sysfile;
}

From source file:com.addthis.hydra.task.stream.StreamFileNative.java

public StreamFileNative(File file) {
    this(file.getPath(), file.length(), file.lastModified());
    this.file = file;
}

From source file:com.ogaclejapan.dotapk.controller.ApkApiController.java

@RequestMapping(value = { "", "/" }, method = RequestMethod.GET)
@ResponseBody//from   w w  w  . j ava2 s  .  co m
public ResponseEntity<WebApiReturns> getList() throws Exception {
    log.info("list");

    List<ApkFileDto> apkList = new ArrayList<ApkFileDto>();
    for (File f : apkManager.getList()) {
        apkList.add(new ApkFileDto(f.getName(), f.lastModified()));
    }

    return success(new ApkListDto(apkList));
}

From source file:com.adaptris.core.fs.enhanced.FileSorterCase.java

protected void log(String txt, List<File> list) {
    System.out.println(this.getClass().getSimpleName() + "--- Start file List (" + txt + ")");
    for (File f : list) {
        System.out.println(f.getName() + ", lastModified=" + f.lastModified() + ", size=" + f.length());
    }/*ww w  . j  av a  2s  .  c o m*/
    System.out.println("--- End file List");
}

From source file:com.bitplan.vzjava.resources.PowerPlotResource.java

/**
 * http://stackoverflow.com/a/10257341/1497139
 * Sends the file if modified and "not modified" if not modified
 * future work may put each file with a unique id in a separate folder in
 * tomcat//w  ww .  ja v  a2  s.  co  m
 * * use that static URL for each file
 * * if file is modified, URL of file changes
 * * -> client always fetches correct file
 * 
 * method header for calling method public Response
 * getXY(@HeaderParam("If-Modified-Since") String modified) {
 * 
 * @param file
 *          to send
 * @param modified
 *          - HeaderField "If-Modified-Since" - may be "null"
 * @return Response to be sent to the client
 */
public static Response returnFile(File file, String modified) {
    if (!file.exists()) {
        return Response.status(Status.NOT_FOUND).build();
    }

    // do we really need to send the file or can send "not modified"?
    if (modified != null) {
        Date modifiedDate = null;

        // we have to switch the locale to ENGLISH as parseDate parses in the
        // default locale
        Locale old = Locale.getDefault();
        Locale.setDefault(Locale.ENGLISH);
        try {
            modifiedDate = DateUtils.parseDate(modified, DEFAULT_PATTERNS);
        } catch (ParseException e) {
            LOGGER.log(Level.WARNING, e.getMessage());
        }
        Locale.setDefault(old);

        if (modifiedDate != null) {
            // modifiedDate does not carry milliseconds, but fileDate does
            // therefore we have to do a range-based comparison
            // 1000 milliseconds = 1 second
            if (file.lastModified() - modifiedDate.getTime() < DateUtils.MILLIS_PER_SECOND) {
                return Response.status(Status.NOT_MODIFIED).build();
            }
        }
    }
    // we really need to send the file

    try {
        Date fileDate = new Date(file.lastModified());
        return Response.ok(new FileInputStream(file)).lastModified(fileDate).build();
    } catch (FileNotFoundException e) {
        return Response.status(Status.NOT_FOUND).build();
    }
}

From source file:org.orderofthebee.addons.support.tools.repo.LogFileGet.java

/**
 *
 * {@inheritDoc}// ww w.ja v  a 2 s .c om
 */
@Override
public void execute(final WebScriptRequest req, final WebScriptResponse res) throws IOException {
    final String servicePath = req.getServicePath();
    final String matchPath = req.getServiceMatch().getPath();
    final String filePath = servicePath.substring(servicePath.indexOf(matchPath) + matchPath.length());

    final Map<String, Object> model = new HashMap<>();
    final Status status = new Status();
    final Cache cache = new Cache(this.getDescription().getRequiredCache());
    model.put("status", status);
    model.put("cache", cache);

    final String attachParam = req.getParameter("a");
    final boolean attach = attachParam != null && Boolean.parseBoolean(attachParam);

    final File file = this.validateFilePath(filePath);
    this.delegate.streamContent(req, res, file, file.lastModified(), attach, file.getName(), model);
}