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

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

Introduction

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

Prototype

long getLastModifiedTime() throws FileSystemException;

Source Link

Document

Determines the last-modified timestamp of the file.

Usage

From source file:org.apache.hadoop.gateway.topology.file.FileTopologyProvider.java

private static Topology loadTopology(FileObject file) throws IOException, SAXException, URISyntaxException {
    log.loadingTopologyFile(file.getName().getFriendlyURI());
    Digester digester = digesterLoader.newDigester();
    FileContent content = file.getContent();
    TopologyBuilder topologyBuilder = digester.parse(content.getInputStream());
    Topology topology = topologyBuilder.build();
    topology.setUri(file.getURL().toURI());
    topology.setName(FilenameUtils.removeExtension(file.getName().getBaseName()));
    topology.setTimestamp(content.getLastModifiedTime());
    return topology;
}

From source file:org.apache.synapse.transport.vfs.VFSTransportListener.java

/**
 * Process a single file through Axis2/*from  w  ww  .  java 2  s  .c om*/
 * @param entry the PollTableEntry for the file (or its parent directory or archive)
 * @param file the file that contains the actual message pumped into Axis2
 * @throws AxisFault on error
 */
private void processFile(PollTableEntry entry, FileObject file) throws AxisFault {

    try {
        FileContent content = file.getContent();
        String fileName = file.getName().getBaseName();
        String filePath = file.getName().getPath();
        String fileURI = file.getName().getURI();

        metrics.incrementBytesReceived(content.getSize());

        Map<String, Object> transportHeaders = new HashMap<String, Object>();
        transportHeaders.put(VFSConstants.FILE_PATH, filePath);
        transportHeaders.put(VFSConstants.FILE_NAME, fileName);
        transportHeaders.put(VFSConstants.FILE_URI, fileURI);

        try {
            transportHeaders.put(VFSConstants.FILE_LENGTH, content.getSize());
            transportHeaders.put(VFSConstants.LAST_MODIFIED, content.getLastModifiedTime());
        } catch (FileSystemException ignore) {
        }

        MessageContext msgContext = entry.createMessageContext();

        String contentType = entry.getContentType();
        if (BaseUtils.isBlank(contentType)) {
            if (file.getName().getExtension().toLowerCase().endsWith(".xml")) {
                contentType = "text/xml";
            } else if (file.getName().getExtension().toLowerCase().endsWith(".txt")) {
                contentType = "text/plain";
            }
        } else {
            // Extract the charset encoding from the configured content type and
            // set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this.
            String charSetEnc = null;
            try {
                if (contentType != null) {
                    charSetEnc = new ContentType(contentType).getParameter("charset");
                }
            } catch (ParseException ex) {
                // ignore
            }
            msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
        }

        // if the content type was not found, but the service defined it.. use it
        if (contentType == null) {
            if (entry.getContentType() != null) {
                contentType = entry.getContentType();
            } else if (VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE) != null) {
                contentType = VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE);
            }
        }

        // does the service specify a default reply file URI ?
        String replyFileURI = entry.getReplyFileURI();
        if (replyFileURI != null) {
            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
                    new VFSOutTransportInfo(replyFileURI, entry.isFileLockingEnabled()));
        }

        // Determine the message builder to use
        Builder builder;
        if (contentType == null) {
            log.debug("No content type specified. Using SOAP builder.");
            builder = new SOAPBuilder();
        } else {
            int index = contentType.indexOf(';');
            String type = index > 0 ? contentType.substring(0, index) : contentType;
            builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
            if (builder == null) {
                if (log.isDebugEnabled()) {
                    log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
                }
                builder = new SOAPBuilder();
            }
        }

        // set the message payload to the message context
        InputStream in;
        ManagedDataSource dataSource;
        if (builder instanceof DataSourceMessageBuilder && entry.isStreaming()) {
            in = null;
            dataSource = ManagedDataSourceFactory.create(new FileObjectDataSource(file, contentType));
        } else {
            in = new AutoCloseInputStream(content.getInputStream());
            dataSource = null;
        }

        try {
            OMElement documentElement;
            if (in != null) {
                documentElement = builder.processDocument(in, contentType, msgContext);
            } else {
                documentElement = ((DataSourceMessageBuilder) builder).processDocument(dataSource, contentType,
                        msgContext);
            }
            msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));

            handleIncomingMessage(msgContext, transportHeaders, null, //* SOAP Action - not applicable *//
                    contentType);
        } finally {
            if (dataSource != null) {
                dataSource.destroy();
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("Processed file : " + VFSUtils.maskURLPassword(file.toString()) + " of Content-type : "
                    + contentType);
        }

    } catch (FileSystemException e) {
        handleException(
                "Error reading file content or attributes : " + VFSUtils.maskURLPassword(file.toString()), e);

    } finally {
        try {
            if (file != null) {
                file.close();
            }
        } catch (FileSystemException warn) {
            // ignore the warning,  since we handed over the stream close job to
            // AutocloseInputstream..
        }
    }
}

From source file:org.celeria.minecraft.backup.Archive.java

private ZipEntry entryFor(final String name, final FileContent content) throws FileSystemException {
    final ZipEntry entry = new ZipEntry(name);
    entry.setTime(content.getLastModifiedTime());
    return entry;
}

From source file:org.celeria.minecraft.backup.DeleteOldBackupsTaskTest.java

@Before
public void setUpOldBackUp(@Named("old") final FileContent oldBackUpContent) throws Exception {
    when(oldBackUp.getContent()).thenReturn(oldBackUpContent);
    when(oldBackUpContent.getLastModifiedTime()).thenReturn(OLD_TIME);
}

From source file:org.celeria.minecraft.backup.DeleteOldBackupsTaskTest.java

@Before
public void setUpNewBackUp(@Named("new") final FileContent newBackUpContent) throws Exception {
    when(newBackUp.getContent()).thenReturn(newBackUpContent);
    when(newBackUpContent.getLastModifiedTime()).thenReturn(NEW_TIME);
}

From source file:org.fuin.vfs2.filter.AgeFileFilter.java

/**
 * Tests if the specified <code>File</code> is newer than the specified time
 * reference./*from   w w w . j a  v a  2s.  c  om*/
 * 
 * @param fileObject
 *            the <code>File</code> of which the modification date must be
 *            compared, must not be {@code null}
 * @param timeMillis
 *            the time reference measured in milliseconds since the epoch
 *            (00:00:00 GMT, January 1, 1970)
 * @return true if the <code>File</code> exists and has been modified after
 *         the given time reference.
 * @throws IllegalArgumentException
 *             if the file is {@code null}
 */
private static boolean isFileNewer(final FileObject fileObject, final long timeMillis) {
    if (fileObject == null) {
        throw new IllegalArgumentException("No specified file");
    }
    try {
        if (!fileObject.exists()) {
            return false;
        }
        final FileContent content = fileObject.getContent();
        try {
            final long lastModified = content.getLastModifiedTime();
            return lastModified > timeMillis;
        } finally {
            content.close();
        }
    } catch (final FileSystemException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.mycore.common.content.MCRVFSContent.java

@Override
public long lastModified() throws IOException {
    FileContent content = fo.getContent();
    try {/*  w ww.j  av  a  2 s . c  om*/
        return content.getLastModifiedTime();
    } finally {
        fo.close();
    }
}

From source file:org.mycore.common.content.MCRVFSContent.java

@Override
public String getETag() throws IOException {
    FileContent content = fo.getContent();
    try {/*from  w  w  w. j a  v a2 s  .co  m*/
        String systemId = getSystemId();
        if (systemId == null) {
            systemId = fo.getName().getURI();
        }
        long length = content.getSize();
        long lastModified = content.getLastModifiedTime();
        String eTag = getSimpleWeakETag(systemId, length, lastModified);
        if (eTag == null) {
            return null;
        }
        return eTag.substring(2); //remove weak
    } finally {
        content.close();
    }
}

From source file:org.mycore.datamodel.ifs2.MCRNode.java

/**
 * Returns the time this node was last modified, or null if no such time is
 * defined in the underlying filesystem//  w w  w .  ja v  a2  s  .  c  o m
 * 
 * @return the time this node was last modified
 */
public Date getLastModified() throws IOException {
    FileContent content = fo.getContent();
    try {
        if (content != null) {
            return new Date(content.getLastModifiedTime());
        } else {
            return null;
        }
    } finally {
        content.close();
    }
}

From source file:org.mycore.datamodel.ifs2.MCRStoredMetadata.java

/**
 * Returns the date this metadata document was last modified
 * //from  w w  w  .  ja v  a 2 s  . co  m
 * @return the date this metadata document was last modified
 */
public Date getLastModified() throws IOException {
    FileContent fileContent = fo.getContent();
    try {
        long time = fileContent.getLastModifiedTime();
        return new Date(time);
    } finally {
        fileContent.close();
    }
}