Example usage for org.eclipse.jdt.internal.compiler.util Util getZipEntryByteContent

List of usage examples for org.eclipse.jdt.internal.compiler.util Util getZipEntryByteContent

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.util Util getZipEntryByteContent.

Prototype

public static byte[] getZipEntryByteContent(ZipEntry ze, ZipFile zip) throws IOException 

Source Link

Document

Returns the contents of the given zip entry as a byte array.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.JarEntryFile.java

License:Open Source License

public InputStream getContents() throws CoreException {
    ZipFile zipFile = null;/*from w ww.  j ava  2  s. com*/
    try {
        zipFile = getZipFile();
        if (org.eclipse.jdt.internal.core.JavaModelManager.ZIP_ACCESS_VERBOSE) {
            System.out.println("(" + Thread.currentThread()
                    + ") [JarEntryFile.getContents()] Creating ZipFile on " + zipFile.getName()); //$NON-NLS-1$   //$NON-NLS-2$
        }
        String entryName = getEntryName();
        ZipEntry zipEntry = zipFile.getEntry(entryName);
        if (zipEntry == null) {
            throw new JavaModelException(
                    new JavaModelStatus(IJavaModelStatusConstants.INVALID_PATH, entryName));
        }
        byte[] contents = Util.getZipEntryByteContent(zipEntry, zipFile);
        return new ByteArrayInputStream(contents);
    } catch (IOException e) {
        throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
    } finally {
        // avoid leaking ZipFiles
        manager.closeZipFile(zipFile);
    }
}

From source file:org.ant4eclipse.lib.jdt.ecj.internal.tools.loader.JarClassFileImpl.java

License:Open Source License

public byte[] getBytes() {
    try {//www. j  a v  a 2 s  .c  o m
        return Util.getZipEntryByteContent(this._zipFile.getEntry(this._zipEntryName), this._zipFile);
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:org.eclipse.che.jdt.core.ToolFactory.java

License:Open Source License

/**
 * Create a default classfile reader, able to expose the internal representation of a given classfile
 * according to the decoding flag used to initialize the reader.
 * Answer null if the file named zipFileName doesn't represent a valid zip file or if the zipEntryName
 * is not a valid entry name for the specified zip file or if the bytes don't represent a valid
 * .class file according to the JVM specifications.
 * <p/>/*w ww  .  j ava 2 s.c  o m*/
 * The decoding flags are described in IClassFileReader.
 *
 * @param zipFileName
 *         the name of the zip file
 * @param zipEntryName
 *         the name of the entry in the zip file to be read
 * @param decodingFlag
 *         the flag used to decode the class file reader.
 * @return a default classfile reader
 * @see org.eclipse.jdt.core.util.IClassFileReader
 */
public static IClassFileReader createDefaultClassFileReader(String zipFileName, String zipEntryName,
        int decodingFlag) {
    ZipFile zipFile = null;
    try {
        if (JavaModelManager.ZIP_ACCESS_VERBOSE) {
            System.out.println("(" + Thread.currentThread()
                    + ") [ToolFactory.createDefaultClassFileReader()] Creating ZipFile on " + zipFileName); //$NON-NLS-1$   //$NON-NLS-2$
        }
        zipFile = new ZipFile(zipFileName);
        ZipEntry zipEntry = zipFile.getEntry(zipEntryName);
        if (zipEntry == null) {
            return null;
        }
        if (!zipEntryName.toLowerCase().endsWith(SuffixConstants.SUFFIX_STRING_class)) {
            return null;
        }
        byte classFileBytes[] = Util.getZipEntryByteContent(zipEntry, zipFile);
        return new ClassFileReader(classFileBytes, decodingFlag);
    } catch (ClassFormatException e) {
        return null;
    } catch (IOException e) {
        return null;
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}

From source file:org.eclipse.jdt.internal.core.SourceMapper.java

License:Open Source License

private char[] readSource(ZipEntry entry, ZipFile zip, String charSet) {
    try {/*w  w  w  .java 2s.  c  o  m*/
        byte[] bytes = Util.getZipEntryByteContent(entry, zip);
        if (bytes != null) {
            return Util.bytesToChar(bytes, charSet == null ? this.encoding : charSet);
        }
    } catch (IOException e) {
        // ignore
    }
    return null;
}

From source file:org.eclipse.xtext.common.types.ui.trace.ZipFileAwareTrace.java

License:Open Source License

@Override
public InputStream getContents(SourceRelativeURI uri, IProject project) {
    // inspired by org.eclipse.jdt.internal.core.JarEntryFile.getContents()
    JavaModelManager modelManager = JavaModelManager.getJavaModelManager();
    ZipFile zipFile = null;/*from   w ww.j av  a2  s .co m*/
    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;
}

From source file:org.summer.dsl.builder.trace.ZipFileAwareTrace.java

License:Open Source License

@Override
protected InputStream getContents(URI uri, IProject project) throws CoreException {
    // inspired by org.eclipse.jdt.internal.core.JarEntryFile.getContents()
    JavaModelManager modelManager = JavaModelManager.getJavaModelManager();
    ZipFile zipFile = modelManager.getZipFile(zipFilePath);
    try {/*w  w w  .j  a  va 2 s.c om*/
        ZipEntry zipEntry = zipFile.getEntry(uri.toString());
        if (zipEntry != null) {
            byte[] contents = Util.getZipEntryByteContent(zipEntry, zipFile);
            return new ByteArrayInputStream(contents);
        }
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, "", e.getMessage(), e));
    } finally {
        modelManager.closeZipFile(zipFile);
    }
    return null;
}