use of org.eclipse.jdt.core.util.IClassFileReader in project che by eclipse.
the class ToolFactory method createDefaultClassFileReader.
/**
* 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/>
* 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 " + //$NON-NLS-1$ //$NON-NLS-2$
zipFileName);
}
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
}
}
}
}
use of org.eclipse.jdt.core.util.IClassFileReader in project eclipse.jdt.ls by eclipse.
the class SerialVersionHashOperation method calculateSerialVersionId.
public static Long calculateSerialVersionId(ITypeBinding typeBinding, final IProgressMonitor monitor) throws CoreException, IOException {
try {
IFile classfileResource = getClassfile(typeBinding);
if (classfileResource == null) {
return null;
}
InputStream contents = classfileResource.getContents();
try {
IClassFileReader cfReader = ToolFactory.createDefaultClassFileReader(contents, IClassFileReader.ALL);
if (cfReader != null) {
return calculateSerialVersionId(cfReader);
}
} finally {
contents.close();
}
return null;
} finally {
if (monitor != null) {
monitor.done();
}
}
}
Aggregations