本文整理了Java中org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsByteArray()
方法的一些代码示例,展示了Util.getResourceContentsAsByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getResourceContentsAsByteArray()
方法的具体详情如下:
包路径:org.eclipse.jdt.internal.core.util.Util
类名称:Util
方法名:getResourceContentsAsByteArray
[英]Returns the given file's contents as a byte array.
[中]以字节数组的形式返回给定文件的内容。
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core
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;
}
}
public char[] getCharContents() {
代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core
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;
}
}
public char[] getCharContents() {
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core
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;
}
}
public char[] getCharContents() {
代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core
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;
}
}
public char[] getCharContents() {
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
@Override
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;
}
}
@Override
代码示例来源:origin: trylimits/Eclipse-Postfix-Code-Completion
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;
}
}
public char[] getCharContents() {
代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core
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;
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core
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;
}
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
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;
}
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core
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;
}
代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core
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;
}
代码示例来源:origin: trylimits/Eclipse-Postfix-Code-Completion
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;
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core
byte[] contents = Util.getResourceContentsAsByteArray(file);
try {
return new ClassFileReader(contents, file.getFullPath().toString().toCharArray(), fullyInitialize);
代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core
byte[] contents = Util.getResourceContentsAsByteArray(file);
try {
return new ClassFileReader(contents, file.getFullPath().toString().toCharArray(), fullyInitialize);
代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core
public byte[] getBytes() throws JavaModelException {
JavaElement pkg = (JavaElement) getParent();
if (pkg instanceof JarPackageFragment) {
JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
try {
String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
entryName = root.getClassFilePath(entryName);
return getClassFileContent(root, entryName);
// Java 9 - The below exception is not thrown in new scheme of things. Could cause issues?
// 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);
}
}
} else {
IFile file = (IFile) resource();
return Util.getResourceContentsAsByteArray(file);
}
}
protected byte[] getClassFileContent(JarPackageFragmentRoot root, String className) throws CoreException, IOException {
代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core
@Override
public byte[] getBytes() throws JavaModelException {
JavaElement pkg = (JavaElement) getParent();
if (pkg instanceof JarPackageFragment) {
JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
try {
String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
entryName = root.getClassFilePath(entryName);
return getClassFileContent(root, entryName);
// Java 9 - The below exception is not thrown in new scheme of things. Could cause issues?
// 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);
}
}
} else {
IFile file = (IFile) resource();
return Util.getResourceContentsAsByteArray(file);
}
}
protected byte[] getClassFileContent(JarPackageFragmentRoot root, String className) throws CoreException, IOException {
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core
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);
}
}
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException {
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core
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);
}
}
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException {
代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core
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);
}
}
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException {
代码示例来源:origin: trylimits/Eclipse-Postfix-Code-Completion
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);
}
}
private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException {
内容来源于网络,如有侵权,请联系作者删除!