Example usage for javax.tools FileObject getName

List of usage examples for javax.tools FileObject getName

Introduction

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

Prototype

String getName();

Source Link

Document

Returns a user-friendly name for this file object.

Usage

From source file:name.martingeisse.webide.features.java.compiler.classpath.PlatformClasspathShieldFileManager.java

@Override
public boolean isSameFile(final FileObject a, final FileObject b) {
    logger.trace("standard file manager checking files for identity: [" + a + "] / [" + a.getName() + "], [" + b
            + "] / [" + b.getName() + "]");
    final boolean result = super.isSameFile(a, b);
    logger.trace("identical: " + result);
    return result;
}

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   w w w  . j av a 2  s.co  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.versly.rest.wsdoc.AnnotationProcessor.java

@Override
public boolean process(Set<? extends TypeElement> supportedAnnotations, RoundEnvironment roundEnvironment) {

    // short-circuit if there are multiple rounds
    if (_isComplete)
        return true;

    Collection<String> processedPackageNames = new LinkedHashSet<String>();
    processElements(roundEnvironment, processedPackageNames, new SpringMVCRestImplementationSupport());
    processElements(roundEnvironment, processedPackageNames, new JaxRSRestImplementationSupport());
    processElements(roundEnvironment, processedPackageNames, new JavaEEWebsocketImplementationSupport());

    _docs.postProcess();//from  w w w  .j a  va  2 s.  c o  m

    if (_docs.getApis().size() > 0) {

        OutputStream fileOutput = null;
        try {
            FileObject file = getOutputFile();
            boolean exists = new File(file.getName()).exists();
            fileOutput = file.openOutputStream();
            _docs.toStream(fileOutput);
            processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
                    String.format("Wrote REST docs for %s apis to %s file at %s", _docs.getApis().size(),
                            exists ? "existing" : "new", file.getName()));
        } catch (Exception e) {
            throw new RuntimeException(e); // TODO wrap in something nicer
        } finally {
            if (fileOutput != null) {
                try {
                    fileOutput.close();
                } catch (IOException ignored) {
                    // ignored
                }
            }
        }
    }
    _isComplete = true;
    return true;
}