Example usage for javax.tools JavaFileObject getLastModified

List of usage examples for javax.tools JavaFileObject getLastModified

Introduction

In this page you can find the example usage for javax.tools JavaFileObject getLastModified.

Prototype

long getLastModified();

Source Link

Document

Returns the time this file object was last modified.

Usage

From source file:org.cdmckay.coffeep.Program.java

private static ClassFile getClassFile(JavaFileObject fileObject, CoffeepSystemInfo systemInfo)
        throws IOException, ConstantPoolException {
    if (fileObject == null) {
        throw new IllegalArgumentException("fileObject cannot be null");
    }/*from  w  ww .  j av  a  2  s  .  c o  m*/
    if (systemInfo == null) {
        throw new IllegalArgumentException("systemInfo cannot be null");
    }

    InputStream inputStream = fileObject.openInputStream();
    try {
        MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            logger.warn("Exception while getting MD5 MessageDigest", e);
        }

        DigestInputStream digestInputStream = new DigestInputStream(inputStream, messageDigest);
        CountingInputStream countingInputStream = new CountingInputStream(digestInputStream);

        Attribute.Factory attributeFactory = new Attribute.Factory();
        ClassFile classFile = ClassFile.read(countingInputStream, attributeFactory);

        systemInfo.classFileUri = fileObject.toUri();
        systemInfo.classFileSize = countingInputStream.getSize();
        systemInfo.lastModifiedTimestamp = fileObject.getLastModified();
        if (messageDigest != null) {
            systemInfo.digestAlgorithm = messageDigest.getAlgorithm();
            systemInfo.digest = new BigInteger(1, messageDigest.digest()).toString(16);
        }

        return classFile;
    } finally {
        inputStream.close();
    }
}