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.docdoku.cli.helpers.FileHelper.java

public void downloadNativeCADFile(URL serverURL, File path, String workspace, String partNumber,
        PartRevision pr, PartIteration pi, boolean force)
        throws IOException, LoginException, NoSuchAlgorithmException {
    BinaryResource bin = pi.getNativeCADFile();
    String fileName = bin.getName();
    PartIterationKey partIPK = new PartIterationKey(workspace, partNumber, pr.getVersion(), pi.getIteration());
    boolean writable = (pr.isCheckedOut()) && (pr.getCheckOutUser().getLogin().equals(login))
            && (pr.getLastIteration().getIteration() == pi.getIteration());
    File localFile = new File(path, fileName);
    MetaDirectoryManager meta = new MetaDirectoryManager(path);

    if (localFile.exists() && !force
            && localFile.lastModified() != meta.getLastModifiedDate(localFile.getAbsolutePath())) {
        boolean confirm = FileHelper.confirmOverwrite(localFile.getAbsolutePath());
        if (!confirm)
            return;
    }/*from  ww  w. jav  a2  s. co m*/
    localFile.delete();
    System.out.println("Fetching part: " + partIPK.getPartMasterNumber() + " "
            + partIPK.getPartRevision().getVersion() + "." + partIPK.getIteration() + " (" + workspace + ")");
    String digest = downloadFile(localFile, FileHelper.getPartURL(serverURL, partIPK, fileName));
    localFile.setWritable(writable);

    saveMetadata(meta, partIPK, digest, localFile);
}

From source file:net.sf.jvifm.control.CopyCommand.java

public void execute() throws Exception {

    if (files == null || files.length <= 0)
        return;// w w  w.j a va2 s  . c om

    for (int i = 0; i < files.length; i++) {

        String src = FilenameUtils.concat(srcDir, files[i]);
        strValue = "";
        if (fileModelManager.isDestFileExisted(src, dstDir)) {
            if (yesToAll) {
                doFileOperator(src, dstDir, files[i]);
            } else if (noToAll) {
                continue;
            } else {

                File srcFile = new File(src);
                File dstFile = new File(FilenameUtils.concat(dstDir, srcFile.getName()));
                String srcSize = StringUtil.formatSize(srcFile.length());
                String srcDate = StringUtil.formatDate(srcFile.lastModified());
                String dstSize = StringUtil.formatSize(dstFile.length());
                String dstDate = StringUtil.formatDate(dstFile.lastModified());

                String msg = "";
                if (srcFile.isDirectory()) {
                    msg = msgFolderReplace;
                } else {
                    msg = msgFileReplace;
                }

                msg = msg.replaceAll("\\$name", srcFile.getName());
                msg = msg.replaceAll("\\$srcSize", srcSize);
                msg = msg.replaceAll("\\$srcDate", srcDate);
                msg = msg.replaceAll("\\$dstSize", dstSize);
                msg = msg.replaceAll("\\$dstDate", dstDate);
                strValue = new Util().openConfirmWindow(options, msgCpConfirmDlgTitle, msg, OptionShell.WARN);

                if (strValue == null || strValue.equals(msgOptionCancel))
                    return;

                if (strValue.equals(msgOptionYesToAll)) {
                    yesToAll = true;
                    doFileOperator(src, dstDir, files[i]);
                }

                if (strValue.equals(msgOptionNoToAll))
                    noToAll = true;
                if (strValue.equals(msgOptionNo))
                    continue;
                if (strValue.equals(msgOptionYes))
                    doFileOperator(src, dstDir, files[i]);
            }
        } else {
            doFileOperator(src, dstDir, files[i]);
        }
    }

}

From source file:com.xyxy.platform.examples.showcase.demos.web.StaticContentServlet.java

/**
 * Content?./*from w  w  w  .  jav  a  2 s.co m*/
 */
private ContentInfo getContentInfo(String contentPath) {
    ContentInfo contentInfo = new ContentInfo();

    String realFilePath = getServletContext().getRealPath(contentPath);
    File file = new File(realFilePath);

    contentInfo.file = file;
    contentInfo.contentPath = contentPath;
    contentInfo.fileName = file.getName();
    contentInfo.length = (int) file.length();

    contentInfo.lastModified = file.lastModified();
    contentInfo.etag = "W/\"" + contentInfo.lastModified + "\"";

    contentInfo.mimeType = mimetypesFileTypeMap.getContentType(contentInfo.fileName);

    if ((contentInfo.length >= GZIP_MINI_LENGTH)
            && ArrayUtils.contains(GZIP_MIME_TYPES, contentInfo.mimeType)) {
        contentInfo.needGzip = true;
    } else {
        contentInfo.needGzip = false;
    }

    return contentInfo;
}

From source file:cn.dreampie.coffeescript.compiler.CoffeeCompiler.java

/**
 * Compiles the input <code>CoffeeSource</code> to CSS and writes it to the specified output <code>File</code>.
 *
 * @param input  The input <code>CoffeeSource</code> to compile.
 * @param output The output <code>File</code> to write the CSS to.
 * @param force  'false' to only compile the input <code>CoffeeSource</code> in case the COFFEE source has been modified (including imports) or the output file does not exists.
 * @throws java.io.IOException If the COFFEE file cannot be read or the output file cannot be written.
 *//*  w  ww.  j  a v a2s. c o  m*/
public void compile(CoffeeSource input, File output, boolean force) throws IOException, CoffeeException {
    if (force || (!output.exists() && output.createNewFile())
            || output.lastModified() < input.getLastModified()) {
        String data = compile(input);
        FileUtils.writeStringToFile(output, data, encoding);
    }
}

From source file:bboss.org.apache.velocity.runtime.resource.loader.FileResourceLoader.java

/**
 * @see bboss.org.apache.velocity.runtime.resource.loader.ResourceLoader#getLastModified(bboss.org.apache.velocity.runtime.resource.Resource)
 *//*from   ww w .j a v a2s.c  o  m*/
public long getLastModified(Resource resource) {
    String path = (String) templatePaths.get(resource.getName());
    File file = getFile(path, resource.getName());

    if (file.canRead()) {
        return file.lastModified();
    } else {
        return 0;
    }
}

From source file:edu.umd.cs.marmoset.modelClasses.ZipFileAggregator.java

/**
 * Add a zip file to be added to the aggregate.
 *
 * @param dirName   name of the top-level directory that will be
 *                  created in the aggregate zip file
 * @param inputFile the zip file to be added
 *
 * @throws BadInputZipFileException if the input file seems
 *                     to be invalid; in this case,
 *                     we do <em>not</em> write any
 *                     output to the output file, and
 *                     writing of other zip files to
 *                     the aggregate may continue
 * @throws IOException if an error occurs while copying the
 *                     input entries to the aggregate output;
 *                     in this case, the aggregate output is
 *                     probably corrupted or incomplete
 */// ww  w  .  j av a  2s  . co  m
public void addFile(String dirName, File inputFile) throws IOException, BadInputZipFileException {
    long time = -1L;

    // safely check the time in the file
    try {
        time = inputFile.lastModified();
    } catch (Exception e) {
    }

    if (time <= 0L)
        time = -1L;

    FileInputStream fis = null;
    try {
        fis = new FileInputStream(inputFile);
        addZipFileFromInputStream(dirName, time, fis);
    } finally {
        if (fis != null)
            fis.close();
    }
}

From source file:FileHelper.java

private static void copyFile(File srcFile, File destFile, long chunkSize) throws IOException {
    FileInputStream is = null;/*from w  ww  .  j a  va  2s  . c  om*/
    FileOutputStream os = null;
    try {
        is = new FileInputStream(srcFile);
        FileChannel iChannel = is.getChannel();
        os = new FileOutputStream(destFile, false);
        FileChannel oChannel = os.getChannel();
        long doneBytes = 0L;
        long todoBytes = srcFile.length();
        while (todoBytes != 0L) {
            long iterationBytes = Math.min(todoBytes, chunkSize);
            long transferredLength = oChannel.transferFrom(iChannel, doneBytes, iterationBytes);
            if (iterationBytes != transferredLength) {
                throw new IOException("Error during file transfer: expected " + iterationBytes + " bytes, only "
                        + transferredLength + " bytes copied.");
            }
            doneBytes += transferredLength;
            todoBytes -= transferredLength;
        }
    } finally {
        if (is != null) {
            is.close();
        }
        if (os != null) {
            os.close();
        }
    }
    boolean successTimestampOp = destFile.setLastModified(srcFile.lastModified());
    if (!successTimestampOp) {
        System.out.println("Could not change timestamp for {}. Index synchronization may be slow. " + destFile);
    }
}

From source file:org.openmrs.web.controller.report.export.DataExportListController.java

/**
 * @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest,
 *      java.lang.Object, org.springframework.validation.Errors)
 *//*from w  w  w.  ja va 2  s .  co m*/
@Override
@SuppressWarnings("unchecked")
protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();

    List<AbstractReportObject> reportList = (List<AbstractReportObject>) command;
    Map<AbstractReportObject, Date> generatedDates = new HashMap<AbstractReportObject, Date>();
    Map<AbstractReportObject, String> generatedSizes = new HashMap<AbstractReportObject, String>();

    // add the last modified date of the generated file as reference data
    for (AbstractReportObject report : reportList) {
        File file = DataExportUtil.getGeneratedFile((DataExportReportObject) report);

        if (file.exists()) {
            generatedDates.put(report, new Date(file.lastModified()));

            Long size = file.length(); // returned in bytes
            if (size > 1024 * 1024)
                generatedSizes.put(report, size / (1024 * 1024) + "MB");
            else if (size > 1024)
                generatedSizes.put(report, size / 1024 + "kB");
            else
                generatedSizes.put(report, size + "B");
        }
    }

    map.put("generatedDates", generatedDates);
    map.put("generatedSizes", generatedSizes);

    AdministrationService as = Context.getAdministrationService();
    String batchSize = as.getGlobalProperty(ReportingCompatibilityConstants.BATCH_SIZE_GP);
    map.put("batchSize", batchSize);

    return map;

}

From source file:com.xpn.xwiki.plugin.svg.SVGPlugin.java

public void outputSVGImageFromFile(String filename, XWikiContext context) throws IOException {
    File ofile = getTempFile(filename);
    byte[] svgbytes = readSVGImage(ofile);
    XWikiResponse response = context.getResponse();
    context.setFinished(true);//from   ww  w. j a va2 s.c  o m
    response.setDateHeader("Last-Modified", ofile.lastModified());
    response.setContentLength(svgbytes.length);
    response.setContentType(context.getEngineContext().getMimeType(filename));
    OutputStream os = response.getOutputStream();
    os.write(svgbytes);
}

From source file:com.fanniemae.ezpie.LogManager.java

public void addFileDetails(String filename, String logGroup) {
    if (_logLevel == LogLevel.ERROR_ONLY) {
        return;/* www.j av a2 s  .c  o m*/
    }

    if (!FileUtilities.isValidFile(_logFilename)) {
        return;
    }

    File fi = new File(filename);
    long lastModified = fi.lastModified();
    Date dtModified = new Date(lastModified);

    try (RandomAccessFile raf = new RandomAccessFile(_logFilename, "rw")) {
        raf.seek(raf.length() - _footerLength);
        raf.write(String.format(_basicLine, logGroup, "File Name", fi.getName(), elapsedTime()).getBytes());
        // Turning off the full path on log, could be security concern.
        // raf.write(String.format(_basicLine, "", "Full Path", filename, elapsedTime()).getBytes())
        raf.write(String
                .format(_basicLine, groupString(""), "Last Modified Date", dtModified.toString(), elapsedTime())
                .getBytes());
        raf.write(String.format(_basicLine, groupString(""), "Size", String.format("%,d bytes", fi.length()),
                elapsedTime()).getBytes());
        raf.write(_footerByteArray);
        raf.close();
    } catch (IOException e) {
        throw new PieException("Error trying to add message to debug page.", e);
    }
}