@Override public Manifest getManifest() { ZipFile jar = null; try { jar = getJar(); ZipEntry mfEntry = jar.getEntry(TypeConstants.META_INF_MANIFEST_MF); if (mfEntry != null) return new Manifest(jar.getInputStream(mfEntry)); } catch (CoreException | IOException e) { // must do without manifest } finally { JavaModelManager.getJavaModelManager().closeZipFile(jar); } return null; }
@Override public Manifest getManifest() { ZipFile jar = null; try { jar = getJar(); ZipEntry mfEntry = jar.getEntry(TypeConstants.META_INF_MANIFEST_MF); if (mfEntry != null) return new Manifest(jar.getInputStream(mfEntry)); } catch (CoreException | IOException e) { // must do without manifest } finally { JavaModelManager.getJavaModelManager().closeZipFile(jar); } return null; }
@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 { 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; }
public void verifyArchiveContent(IPath path) throws CoreException { if (isInvalidArchive(path)) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.status_IOException, new ZipException())); } ZipFile file = getZipFile(path); closeZipFile(file); }
public void verifyArchiveContent(IPath path) throws CoreException { if (isInvalidArchive(path)) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.status_IOException, new ZipException())); } ZipFile file = getZipFile(path); closeZipFile(file); }
public void verifyArchiveContent(IPath path) throws CoreException { if (isInvalidArchive(path)) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.status_IOException, new ZipException())); } ZipFile file = getZipFile(path); closeZipFile(file); }
public void verifyArchiveContent(IPath path) throws CoreException { if (isInvalidArchive(path)) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.status_IOException, new ZipException())); } ZipFile file = getZipFile(path); closeZipFile(file); }
public InputStream getContents() throws CoreException { ZipFile zipFile = null; try { zipFile = getZipFile(); if (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 JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } }
public InputStream getContents() throws CoreException { ZipFile zipFile = null; try { zipFile = getZipFile(); if (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 JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } }
public InputStream getContents() throws CoreException { ZipFile zipFile = null; try { zipFile = getZipFile(); if (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 JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } }
public InputStream getContents() throws CoreException { ZipFile zipFile = null; try { zipFile = getZipFile(); if (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 JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } }
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException { JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent(); ZipFile zip = null; try { zip = root.getJar(); String entryName = Util.concatWith(pkg.names, getElementName(), '/'); ZipEntry ze = zip.getEntry(entryName); if (ze != null) { byte contents[] = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName; return new ClassFileReader(contents, fileName.toCharArray(), fullyInitialize); } } finally { JavaModelManager.getJavaModelManager().closeZipFile(zip); } return null; } public IBuffer getBuffer() throws JavaModelException {
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException { JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent(); ZipFile zip = null; try { zip = root.getJar(); String entryName = Util.concatWith(pkg.names, getElementName(), '/'); ZipEntry ze = zip.getEntry(entryName); if (ze != null) { byte contents[] = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName; return new ClassFileReader(contents, fileName.toCharArray(), fullyInitialize); } } finally { JavaModelManager.getJavaModelManager().closeZipFile(zip); } return null; } public IBuffer getBuffer() throws JavaModelException {
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException { JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent(); ZipFile zip = null; try { zip = root.getJar(); String entryName = Util.concatWith(pkg.names, getElementName(), '/'); ZipEntry ze = zip.getEntry(entryName); if (ze != null) { byte contents[] = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName; return new ClassFileReader(contents, fileName.toCharArray(), fullyInitialize); } } finally { JavaModelManager.getJavaModelManager().closeZipFile(zip); } return null; } public IBuffer getBuffer() throws JavaModelException {
protected byte[] getClassFileContent(JarPackageFragmentRoot root, String className) throws CoreException, IOException { byte[] contents = null; String rootPath = root.getPath().toOSString(); if (org.eclipse.jdt.internal.compiler.util.Util.isJrt(rootPath)) { try { contents = org.eclipse.jdt.internal.compiler.util.JRTUtil.getClassfileContent( new File(rootPath), className, root.getElementName()); } catch (ClassFormatException e) { e.printStackTrace(); } } else { ZipFile zip = root.getJar(); try { ZipEntry ze = zip.getEntry(className); if (ze != null) { contents = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); } } finally { JavaModelManager.getJavaModelManager().closeZipFile(zip); } } if (contents == null && Thread.interrupted()) // reading from JRT is interruptible throw new OperationCanceledException(); return contents; }
public void verifyArchiveContent(IPath path) throws CoreException { // TODO: we haven't finalized what path the JRT is represented by. Don't attempt to validate it. if (isJrt(path)) { return; } throwExceptionIfArchiveInvalid(path); // Check if we can determine the archive's validity by examining the index if (JavaIndex.isEnabled()) { JavaIndex index = JavaIndex.getIndex(); String location = JavaModelManager.getLocalFile(path).getAbsolutePath(); try (IReader reader = index.getNd().acquireReadLock()) { NdResourceFile resourceFile = index.getResourceFile(location.toCharArray()); if (index.isUpToDate(resourceFile)) { // We have this file in the index and the index is up-to-date, so we can determine the file's // validity without touching the filesystem. if (resourceFile.isCorruptedZipFile()) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.status_IOException, new ZipException())); } return; } } } ZipFile file = getZipFile(path); closeZipFile(file); }
public void verifyArchiveContent(IPath path) throws CoreException { // TODO: we haven't finalized what path the JRT is represented by. Don't attempt to validate it. if (isJrt(path)) { return; } throwExceptionIfArchiveInvalid(path); // Check if we can determine the archive's validity by examining the index if (JavaIndex.isEnabled()) { JavaIndex index = JavaIndex.getIndex(); String location = JavaModelManager.getLocalFile(path).getAbsolutePath(); try (IReader reader = index.getNd().acquireReadLock()) { NdResourceFile resourceFile = index.getResourceFile(location.toCharArray()); if (index.isUpToDate(resourceFile)) { // We have this file in the index and the index is up-to-date, so we can determine the file's // validity without touching the filesystem. if (resourceFile.isCorruptedZipFile()) { throw new CoreException(new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, -1, Messages.status_IOException, new ZipException())); } return; } } } ZipFile file = getZipFile(path); closeZipFile(file); }
protected byte[] getClassFileContent(JarPackageFragmentRoot root, String className) throws CoreException, IOException { byte[] contents = null; String rootPath = root.getPath().toOSString(); if (org.eclipse.jdt.internal.compiler.util.Util.isJrt(rootPath)) { try { contents = org.eclipse.jdt.internal.compiler.util.JRTUtil.getClassfileContent( new File(rootPath), className, root.getElementName()); } catch (ClassFormatException e) { e.printStackTrace(); } } else { ZipFile zip = root.getJar(); try { ZipEntry ze = zip.getEntry(className); if (ze != null) { contents = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); } } finally { JavaModelManager.getJavaModelManager().closeZipFile(zip); } } return contents; }
/** * Create a type info from the given class file in a jar and adds it to the given list of infos. * * @throws CoreException */ protected static IBinaryType createInfoFromClassFileInJar(Openable classFile) throws CoreException { PackageFragment pkg = (PackageFragment) classFile.getParent(); String classFilePath = Util.concatWith(pkg.names, classFile.getElementName(), '/'); IBinaryType info = null; java.util.zip.ZipFile zipFile = null; try { zipFile = ((JarPackageFragmentRoot) pkg.getParent()).getJar(); info = org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.read(zipFile, classFilePath); } catch (Exception e) { throw new CoreException(Package.createStatus("Unable to parse JAR file", e)); //$NON-NLS-1$ } finally { JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } return info; }
/** * Create a type info from the given class file in a jar and adds it to the given list of infos. * * @throws CoreException */ protected static IBinaryType createInfoFromClassFileInJar(Openable classFile) throws CoreException { PackageFragment pkg = (PackageFragment) classFile.getParent(); String classFilePath = Util.concatWith(pkg.names, classFile.getElementName(), '/'); IBinaryType info = null; java.util.zip.ZipFile zipFile = null; try { zipFile = ((JarPackageFragmentRoot) pkg.getParent()).getJar(); info = org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.read(zipFile, classFilePath); } catch (Exception e) { throw new CoreException(Package.createStatus("Unable to parse JAR file", e)); //$NON-NLS-1$ } finally { JavaModelManager.getJavaModelManager().closeZipFile(zipFile); } return info; }