Example usage for org.apache.commons.vfs FileContent getLastModifiedTime

List of usage examples for org.apache.commons.vfs FileContent getLastModifiedTime

Introduction

In this page you can find the example usage for org.apache.commons.vfs FileContent getLastModifiedTime.

Prototype

long getLastModifiedTime() throws FileSystemException;

Source Link

Document

Determines the last-modified timestamp of the file.

Usage

From source file:com.thinkberg.moxo.dav.GetHandler.java

void setHeader(HttpServletResponse response, FileContent content) throws FileSystemException {
    response.setHeader("Last-Modified", Util.getDateString(content.getLastModifiedTime()));
    response.setHeader("Content-Type", content.getContentInfo().getContentType());
}

From source file:com.thinkberg.webdav.GetHandler.java

void setHeader(HttpServletResponse response, FileContent content) throws FileSystemException {
    response.setHeader("Last-Modified", Util.getDateString(content.getLastModifiedTime()));
    response.setHeader("Content-Type", content.getContentInfo().getContentType());
    response.setHeader("ETag", Util.getETag(content.getFile()));
}

From source file:net.sf.jvifm.ui.ZipLister.java

private void changeCurrentNode() {

    boolean hasMatchSelectedName = false;
    FileObject[] children = null;
    try {//from  w  w w.  j  a v  a 2s .co  m
        children = currentFileObject.getChildren();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (children == null)
        return;

    sortFiles(children);

    String selectedName = historyManager.getSelectedItem(currentFileObject.getName().getPath());
    table.removeAll();
    TableItem item;

    for (int i = 0; i < children.length; i++) {
        FileName fileName = children[i].getName();

        if (fileName.getBaseName().equals(selectedName)) {
            currentRow = i;
            hasMatchSelectedName = true;
        }

        item = new TableItem(table, SWT.NONE);
        item.setData("fileObject", children[i]);
        item.setText(fileName.getBaseName());

        try {
            FileType fileType = children[i].getType();
            FileContent fileContent = children[i].getContent();

            if (fileType.equals(FileType.FOLDER)) {
                item.setImage(folderImage);
                item.setText(1, "--");
                item.setText(2, StringUtil.formatDate(fileContent.getLastModifiedTime()));
            } else {
                item.setImage(fileImage);
                item.setText(1, StringUtil.formatSize(fileContent.getSize()));
                item.setText(2, StringUtil.formatDate(fileContent.getLastModifiedTime()));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    if (!hasMatchSelectedName)
        currentRow = 0;
    table.setSelection(currentRow);
    table.setFocus();

}

From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java

/**
 * <p>//  ww w.  java2 s  . c o  m
 *  ? ??? .
 * </p>
 * @param cmd
 *        <code>String[]</code>
 * @return ? ? ?
 * @throws FileSystemException
 */
public List ls(final String[] cmd) throws FileSystemException {
    List list = new ArrayList();

    int pos = 1;
    final boolean recursive;
    if (cmd.length > pos && cmd[pos].equals("-R")) {
        recursive = true;
        pos++;
    } else {
        recursive = false;
    }

    final FileObject file;
    if (cmd.length > pos) {
        file = manager.resolveFile(basefile, cmd[pos]);
    } else {
        file = basefile;
    }

    if (file.getType() == FileType.FOLDER) {
        // List the contents
        log.info("Contents of " + file.getName());
        log.info(listChildren(file, recursive, ""));
        // list.add(file.getName());
    } else {
        // Stat the file
        log.info(file.getName());
        final FileContent content = file.getContent();
        log.info("Size: " + content.getSize() + " bytes.");
        final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime()));
        log.info("Last modified: " + lastMod);
    }

    return list;
}

From source file:org.apache.commons.vfs.example.Shell.java

/**
 * Does an 'ls' command.//from  w w w .  j ava  2  s  .  com
 */
private void ls(final String[] cmd) throws FileSystemException {
    int pos = 1;
    final boolean recursive;
    if (cmd.length > pos && cmd[pos].equals("-R")) {
        recursive = true;
        pos++;
    } else {
        recursive = false;
    }

    final FileObject file;
    if (cmd.length > pos) {
        file = mgr.resolveFile(cwd, cmd[pos]);
    } else {
        file = cwd;
    }

    if (file.getType() == FileType.FOLDER) {
        // List the contents
        System.out.println("Contents of " + file.getName());
        listChildren(file, recursive, "");
    } else {
        // Stat the file
        System.out.println(file.getName());
        final FileContent content = file.getContent();
        System.out.println("Size: " + content.getSize() + " bytes.");
        final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime()));
        System.out.println("Last modified: " + lastMod);
    }
}

From source file:org.efaps.webdav4vfs.handler.GetHandler.java

void setHeader(final HttpServletResponse response, final FileContent _content) throws FileSystemException {
    response.setHeader("Last-Modified", Util.getDateString(_content.getLastModifiedTime()));
    response.setHeader("Content-Type", _content.getContentInfo().getContentType());
    response.setHeader("ETag", Util.getETag(_content.getFile()));
}

From source file:org.jclouds.vfs.tools.blobstore.BlobStoreShell.java

private void ls(FileSystemManager mg, FileObject wd, final String[] cmd) throws FileSystemException {
    int pos = 1;/* w  ww .  j  a  va  2 s  . c  o  m*/
    final boolean recursive;
    if (cmd.length > pos && cmd[pos].equals("-R")) {
        recursive = true;
        pos++;
    } else {
        recursive = false;
    }

    final FileObject file;
    if (cmd.length > pos) {
        file = mg.resolveFile(wd, cmd[pos]);
    } else {
        file = wd;
    }

    if (file.getType() == FileType.FOLDER) {
        // List the contents
        System.out.println("Contents of " + file.getName().getFriendlyURI());
        listChildren(file, recursive, "");
    } else {
        // Stat the file
        System.out.println(file.getName());
        final FileContent content = file.getContent();
        System.out.println("Size: " + content.getSize() + " bytes.");
        final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime()));
        System.out.println("Last modified: " + lastMod);
    }
}

From source file:org.sonatype.gshell.commands.vfs.FileInfoCommand.java

public Object execute(final CommandContext context) throws Exception {
    assert context != null;
    IO io = context.getIo();//from   www.  j a v a2  s.com

    FileObject file = resolveFile(context, path);

    io.println("URL: {}", file.getURL());
    io.println("Name: {}", file.getName());
    io.println("BaseName: {}", file.getName().getBaseName());
    io.println("Extension: {}", file.getName().getExtension());
    io.println("Path: {}", file.getName().getPath());
    io.println("Scheme: {}", file.getName().getScheme());
    io.println("URI: {}", file.getName().getURI());
    io.println("Root URI: {}", file.getName().getRootURI());
    io.println("Parent: {}", file.getName().getParent());
    io.println("Type: {}", file.getType());
    io.println("Exists: {}", file.exists());
    io.println("Readable: {}", file.isReadable());
    io.println("Writeable: {}", file.isWriteable());
    io.println("Root path: {}", file.getFileSystem().getRoot().getName().getPath());

    if (file.exists()) {
        FileContent content = file.getContent();
        FileContentInfo contentInfo = content.getContentInfo();
        io.println("Content type: {}", contentInfo.getContentType());
        io.println("Content encoding: {}", contentInfo.getContentEncoding());

        try {
            // noinspection unchecked
            Map<String, Object> attrs = content.getAttributes();
            if (attrs != null && !attrs.isEmpty()) {
                io.println("Attributes:");
                for (Map.Entry<String, Object> entry : attrs.entrySet()) {
                    io.println("    {}='{}'", entry.getKey(), entry.getValue());
                }
            }
        } catch (FileSystemException e) {
            io.println("File attributes are NOT supported");
        }

        try {
            Certificate[] certs = content.getCertificates();
            if (certs != null && certs.length != 0) {
                io.println("Certificate:");
                for (Certificate cert : certs) {
                    io.println("    {}", cert);
                }
            }
        } catch (FileSystemException e) {
            io.println("File certificates are NOT supported");
        }

        if (file.getType().equals(FileType.FILE)) {
            io.println("Size: {} bytes", content.getSize());
        } else if (file.getType().hasChildren() && file.isReadable()) {
            FileObject[] children = file.getChildren();
            io.println("Directory with {} files", children.length);

            for (int iterChildren = 0; iterChildren < children.length; iterChildren++) {
                io.println("#{}:{}", iterChildren, children[iterChildren].getName());
                if (iterChildren > 5) {
                    break;
                }
            }
        }

        io.println("Last modified: {}",
                DateFormat.getInstance().format(new Date(content.getLastModifiedTime())));
    } else {
        io.println("The file does not exist");
    }

    FileObjects.close(file);

    return Result.SUCCESS;
}