本文整理汇总了Java中org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java Util.getResourceContentsAsByteArray方法的具体用法?Java Util.getResourceContentsAsByteArray怎么用?Java Util.getResourceContentsAsByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.core.util.Util
的用法示例。
在下文中一共展示了Util.getResourceContentsAsByteArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypesToBytes
import org.eclipse.jdt.internal.core.util.Util; //导入方法依赖的package包/类
/**
* Returns a mapping of class files to the bytes that make up those class files.
*
* @param resources
* the classfiles
* @param qualifiedNames
* the fully qualified type names corresponding to the classfiles.
* The typeNames correspond to the resources on a one-to-one basis.
* @return a mapping of class files to bytes key: class file value: the bytes
* which make up that classfile
*/
private Map<ReferenceType, byte[]> getTypesToBytes(List<IResource> resources, List<String> qualifiedNames) {
Map<ReferenceType, byte[]> typesToBytes = new HashMap<>(resources.size());
Iterator<IResource> resourceIter = resources.iterator();
Iterator<String> nameIter = qualifiedNames.iterator();
IResource resource;
String name;
while (resourceIter.hasNext()) {
resource = resourceIter.next();
name = nameIter.next();
List<ReferenceType> classes = getJdiClassesByName(name);
byte[] bytes = null;
try {
bytes = Util.getResourceContentsAsByteArray((IFile) resource);
} catch (CoreException e) {
continue;
}
for (ReferenceType type : classes) {
typesToBytes.put(type, bytes);
}
}
return typesToBytes;
}
示例2: writeClassFileCheck
import org.eclipse.jdt.internal.core.util.Util; //导入方法依赖的package包/类
protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException {
try {
byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
notEqual : if (newBytes.length == oldBytes.length) {
for (int i = newBytes.length; --i >= 0;)
if (newBytes[i] != oldBytes[i]) break notEqual;
return false; // bytes are identical so skip them
}
URI location = file.getLocationURI();
if (location == null) return false; // unable to determine location of this class file
String filePath = location.getSchemeSpecificPart();
ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray());
// ignore local types since they're only visible inside a single method
if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
if (JavaBuilder.DEBUG)
System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
addDependentsOf(new Path(fileName), true);
this.newState.wasStructurallyChanged(fileName);
}
} catch (ClassFormatException e) {
addDependentsOf(new Path(fileName), true);
this.newState.wasStructurallyChanged(fileName);
}
return true;
}
示例3: getByteContents
import org.eclipse.jdt.internal.core.util.Util; //导入方法依赖的package包/类
public byte[] getByteContents() {
if (this.byteContents != null) return this.byteContents;
try {
return Util.getResourceContentsAsByteArray(getFile());
} catch (JavaModelException e) {
if (BasicSearchEngine.VERBOSE
|| JobManager.VERBOSE) { // used during search and during indexing
e.printStackTrace();
}
return null;
}
}
示例4: getByteContents
import org.eclipse.jdt.internal.core.util.Util; //导入方法依赖的package包/类
public byte[] getByteContents() {
if (this.byteContents != null) return this.byteContents;
try {
return Util.getResourceContentsAsByteArray(getFile());
} catch (JavaModelException e) {
if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { // used during search and during indexing
e.printStackTrace();
}
return null;
}
}
示例5: getBytes
import org.eclipse.jdt.internal.core.util.Util; //导入方法依赖的package包/类
public byte[] getBytes() throws JavaModelException {
JavaElement pkg = (JavaElement) getParent();
if (pkg instanceof JarPackageFragment) {
JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
ZipFile zip = null;
try {
zip = root.getJar();
String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
ZipEntry ze = zip.getEntry(entryName);
if (ze != null) {
return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
}
throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
} catch (IOException ioe) {
throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
} catch (CoreException e) {
if (e instanceof JavaModelException) {
throw (JavaModelException)e;
} else {
throw new JavaModelException(e);
}
} finally {
JavaModelManager.getJavaModelManager().closeZipFile(zip);
}
} else {
IFile file = (IFile) resource();
return Util.getResourceContentsAsByteArray(file);
}
}
示例6: readFileEntriesWithException
import org.eclipse.jdt.internal.core.util.Util; //导入方法依赖的package包/类
/**
* Reads the classpath file entries of this project's .classpath file. Returns a two-dimensional
* array, where the number of elements in the row is fixed to 2. The first element is an array of
* raw classpath entries, which includes the output entry, and the second element is an array of
* referenced entries that may have been stored by the client earlier. See {@link
* IJavaProject#getReferencedClasspathEntries()} for more details. As a side effect, unknown
* elements are stored in the given map (if not null) Throws exceptions if the file cannot be
* accessed or is malformed.
*/
public IClasspathEntry[][] readFileEntriesWithException(Map unknownElements)
throws CoreException, IOException, ClasspathEntry.AssertionFailedException {
IFile rscFile =
this.project.getFile(org.eclipse.jdt.internal.core.JavaProject.CLASSPATH_FILENAME);
byte[] bytes;
if (rscFile.exists()) {
bytes = Util.getResourceContentsAsByteArray(rscFile);
} else {
// when a project is imported, we get a first delta for the addition of the .project, but the
// .classpath is not accessible
// so default to using java.io.File
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=96258
// TODO: keep this comment code for the history
// TODO: this is original Eclipse code
// URI location = rscFile.getLocationURI();
// if (location == null)
// throw new IOException("Cannot obtain a location URI for " + rscFile);
// //$NON-NLS-1$
// File file = Util.toLocalFile(location, null/*no progress monitor available*/);
// if (file == null)
// throw new IOException("Unable to fetch file from " + location);
// //$NON-NLS-1$
// try {
// bytes =
// org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file);
// } catch (IOException e) {
// if (!file.exists())
return new IClasspathEntry[][] {defaultClasspath(), ClasspathEntry.NO_ENTRIES};
// throw e;
// }
}
if (hasUTF8BOM(bytes)) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=240034
int length = bytes.length - IContentDescription.BOM_UTF_8.length;
System.arraycopy(
bytes, IContentDescription.BOM_UTF_8.length, bytes = new byte[length], 0, length);
}
String xmlClasspath;
try {
xmlClasspath =
new String(
bytes,
org.eclipse.jdt.internal.compiler.util.Util
.UTF_8); // .classpath always encoded with UTF-8
} catch (UnsupportedEncodingException e) {
Util.log(e, "Could not read .classpath with UTF-8 encoding"); // $NON-NLS-1$
// fallback to default
xmlClasspath = new String(bytes);
}
return decodeClasspath(xmlClasspath, unknownElements);
}