Example usage for javax.tools FileObject getLastModified

List of usage examples for javax.tools FileObject getLastModified

Introduction

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

Prototype

long getLastModified();

Source Link

Document

Returns the time this file object was last modified.

Usage

From source file:io.druid.storage.s3.S3DataSegmentPuller.java

/**
 * Returns the "version" (aka last modified timestamp) of the URI
 *
 * @param uri The URI to check the last timestamp
 *
 * @return The time in ms of the last modification of the URI in String format
 *
 * @throws IOException//  w w  w  . j  a  v  a  2  s .  c om
 */
@Override
public String getVersion(URI uri) throws IOException {
    try {
        final FileObject object = buildFileObject(uri, s3Client);
        // buildFileObject has a hidden input stream that gets open deep in jets3t. This helps prevent resource leaks
        try (InputStream nullStream = object.openInputStream()) {
            return String.format("%d", object.getLastModified());
        }
    } catch (S3ServiceException e) {
        if (S3Utils.isServiceExceptionRecoverable(e)) {
            // The recoverable logic is always true for IOException, so we want to only pass IOException if it is recoverable
            throw new IOException(
                    String.format("Could not fetch last modified timestamp from URI [%s]", uri.toString()), e);
        } else {
            throw Throwables.propagate(e);
        }
    }
}

From source file:org.callimachusproject.behaviours.ZipArchiveSupport.java

public XMLEventReader createAtomFeedFromArchive(final String id, final String entryPattern) throws IOException {
    final FileObject file = this;
    final XMLEventFactory ef = XMLEventFactory.newInstance();
    final byte[] buf = new byte[1024];
    final ZipArchiveInputStream zip = new ZipArchiveInputStream(file.openInputStream());
    return new XMLEventReaderBase() {
        private boolean started;
        private boolean ended;

        public void close() throws XMLStreamException {
            try {
                zip.close();/*from ww  w.j a v a 2 s . c  o m*/
            } catch (IOException e) {
                throw new XMLStreamException(e);
            }
        }

        protected boolean more() throws XMLStreamException {
            try {
                ZipArchiveEntry entry;
                if (!started) {
                    Namespace atom = ef.createNamespace(FEED.getPrefix(), FEED.getNamespaceURI());
                    add(ef.createStartDocument());
                    add(ef.createStartElement(FEED, null, Arrays.asList(atom).iterator()));
                    add(ef.createStartElement(TITLE, null, null));
                    add(ef.createCharacters(file.getName()));
                    add(ef.createEndElement(TITLE, null));
                    add(ef.createStartElement(ID, null, null));
                    add(ef.createCharacters(id));
                    add(ef.createEndElement(ID, null));
                    Attribute href = ef.createAttribute("href", file.toUri().toASCIIString());
                    List<Attribute> attrs = Arrays.asList(href, ef.createAttribute("type", "application/zip"));
                    add(ef.createStartElement(LINK, attrs.iterator(), null));
                    add(ef.createEndElement(LINK, null));
                    add(ef.createStartElement(UPDATED, null, null));
                    add(ef.createCharacters(format(new Date(file.getLastModified()))));
                    add(ef.createEndElement(UPDATED, null));
                    started = true;
                    return true;
                } else if (started && !ended && (entry = zip.getNextZipEntry()) != null) {
                    String name = entry.getName();
                    String link = entryPattern.replace("{entry}", PercentCodec.encode(name));
                    MimetypesFileTypeMap mimetypes = new javax.activation.MimetypesFileTypeMap();
                    String type = mimetypes.getContentType(name);
                    if (type == null || type.length() == 0) {
                        type = "application/octet-stream";
                    }
                    add(ef.createStartElement(ENTRY, null, null));
                    add(ef.createStartElement(TITLE, null, null));
                    add(ef.createCharacters(name));
                    add(ef.createEndElement(TITLE, null));
                    Attribute href = ef.createAttribute("href", link);
                    List<Attribute> attrs = Arrays.asList(href, ef.createAttribute("type", type));
                    add(ef.createStartElement(LINK, attrs.iterator(), null));
                    add(ef.createEndElement(LINK, null));
                    long size = entry.getSize();
                    if (size > 0) {
                        zip.skip(size);
                    } else {
                        while (zip.read(buf, 0, buf.length) >= 0)
                            ;
                    }
                    add(ef.createEndElement(ENTRY, null));
                    return true;
                } else if (!ended) {
                    add(ef.createEndElement(FEED, null));
                    add(ef.createEndDocument());
                    ended = true;
                    return true;
                } else {
                    return false;
                }
            } catch (IOException e) {
                throw new XMLStreamException(e);
            }
        }
    };
}

From source file:org.jannocessor.processor.JannocessorProcessorBase.java

private FileInformation readFile(Location location, String pkg, String filename) {
    try {//from w w  w . j ava2  s. co  m
        FileObject file = filer.getResource(location, pkg, filename);

        InputStream inputStream = file.openInputStream();
        String content = IOUtils.toString(inputStream);
        inputStream.close();

        Date lastModified = new Date(file.getLastModified());

        String name = new File(file.toUri()).getCanonicalPath();

        return new DefaultFileInformation(content, name, lastModified);
    } catch (IOException e) {
        return null;
    }
}

From source file:therian.buildweaver.StandardOperatorsProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    try {//from   w  w w.  ja va  2s.  c  om
        final FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT,
                StringUtils.substringBeforeLast(TARGET_CLASSNAME, ".").replace('.', '/'),
                StringUtils.substringAfterLast(TARGET_CLASSNAME, ".") + ".class");

        if (resource.getLastModified() > 0L) {
            processingEnv.getMessager().printMessage(Kind.NOTE,
                    String.format("%s already generated", TARGET_CLASSNAME));
            return false;
        }
    } catch (IOException e1) {
        // expected, swallow
    }
    try {
        ClassUtils.getClass(TARGET_CLASSNAME);
        processingEnv.getMessager().printMessage(Kind.ERROR,
                String.format("%s exists on classpath", TARGET_CLASSNAME));
        return false;
    } catch (ClassNotFoundException e) {
        // expected, swallow
    }

    if (roundEnv.processingOver()) {
        write();
        return true;
    }
    for (TypeElement ann : annotations) {
        final Set<? extends Element> standardOperatorElements = roundEnv.getElementsAnnotatedWith(ann);
        originatingElements.addAll(standardOperatorElements);

        for (Element element : standardOperatorElements) {
            Validate.validState(isValidStandardOperator(element), "%s is not a valid @StandardOperator",
                    appendTo(new StringBuilder(), element).toString());

            if (element.getKind() == ElementKind.CLASS) {
                operators.add(appendTo(new StringBuilder("new "), element).append("()").toString());
            }
            if (element.getKind() == ElementKind.METHOD) {
                operators.add(appendTo(new StringBuilder(), element).append("()").toString());
            }
            if (element.getKind() == ElementKind.FIELD) {
                operators.add(appendTo(new StringBuilder(), element).toString());
            }
        }
    }
    return true;
}