Search in sources :

Example 1 with JavaModelManager

use of org.eclipse.jdt.internal.core.JavaModelManager in project xtext-eclipse by eclipse.

the class ZipFileAwareTrace method getContents.

@Override
public InputStream getContents(SourceRelativeURI uri, IProject project) {
    // inspired by org.eclipse.jdt.internal.core.JarEntryFile.getContents()
    JavaModelManager modelManager = JavaModelManager.getJavaModelManager();
    ZipFile zipFile = null;
    try {
        zipFile = modelManager.getZipFile(zipFilePath);
        ZipEntry zipEntry = zipFile.getEntry(uri.getURI().toString());
        if (zipEntry != null) {
            byte[] contents = Util.getZipEntryByteContent(zipEntry, zipFile);
            return new ByteArrayInputStream(contents);
        }
    } catch (IOException e) {
        log.debug("Could not read zip file " + uri, e);
    } catch (CoreException e) {
        log.debug("Could not read zip file " + uri, e);
    } finally {
        if (zipFile != null) {
            modelManager.closeZipFile(zipFile);
        }
    }
    return null;
}
Also used : JavaModelManager(org.eclipse.jdt.internal.core.JavaModelManager) ZipFile(java.util.zip.ZipFile) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 JavaModelManager (org.eclipse.jdt.internal.core.JavaModelManager)1