org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsByteArray()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(16.1k)|赞(0)|评价(0)|浏览(201)

本文整理了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

Util.getResourceContentsAsByteArray介绍

[英]Returns the given file's contents as a byte array.
[中]以字节数组的形式返回给定文件的内容。

代码示例

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core

  1. public byte[] getByteContents() {
  2. if (this.byteContents != null) return this.byteContents;
  3. try {
  4. return Util.getResourceContentsAsByteArray(getFile());
  5. } catch (JavaModelException e) {
  6. if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { // used during search and during indexing
  7. e.printStackTrace();
  8. }
  9. return null;
  10. }
  11. }
  12. public char[] getCharContents() {

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

  1. public byte[] getByteContents() {
  2. if (this.byteContents != null) return this.byteContents;
  3. try {
  4. return Util.getResourceContentsAsByteArray(getFile());
  5. } catch (JavaModelException e) {
  6. if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { // used during search and during indexing
  7. e.printStackTrace();
  8. }
  9. return null;
  10. }
  11. }
  12. public char[] getCharContents() {

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core

  1. public byte[] getByteContents() {
  2. if (this.byteContents != null) return this.byteContents;
  3. try {
  4. return Util.getResourceContentsAsByteArray(getFile());
  5. } catch (JavaModelException e) {
  6. if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { // used during search and during indexing
  7. e.printStackTrace();
  8. }
  9. return null;
  10. }
  11. }
  12. public char[] getCharContents() {

代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core

  1. public byte[] getByteContents() {
  2. if (this.byteContents != null) return this.byteContents;
  3. try {
  4. return Util.getResourceContentsAsByteArray(getFile());
  5. } catch (JavaModelException e) {
  6. if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { // used during search and during indexing
  7. e.printStackTrace();
  8. }
  9. return null;
  10. }
  11. }
  12. public char[] getCharContents() {

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

  1. @Override
  2. public byte[] getByteContents() {
  3. if (this.byteContents != null) return this.byteContents;
  4. try {
  5. return Util.getResourceContentsAsByteArray(getFile());
  6. } catch (JavaModelException e) {
  7. if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { // used during search and during indexing
  8. e.printStackTrace();
  9. }
  10. return null;
  11. }
  12. }
  13. @Override

代码示例来源:origin: trylimits/Eclipse-Postfix-Code-Completion

  1. public byte[] getByteContents() {
  2. if (this.byteContents != null) return this.byteContents;
  3. try {
  4. return Util.getResourceContentsAsByteArray(getFile());
  5. } catch (JavaModelException e) {
  6. if (BasicSearchEngine.VERBOSE || JobManager.VERBOSE) { // used during search and during indexing
  7. e.printStackTrace();
  8. }
  9. return null;
  10. }
  11. }
  12. public char[] getCharContents() {

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

  1. protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException {
  2. try {
  3. byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
  4. notEqual : if (newBytes.length == oldBytes.length) {
  5. for (int i = newBytes.length; --i >= 0;)
  6. if (newBytes[i] != oldBytes[i]) break notEqual;
  7. return false; // bytes are identical so skip them
  8. }
  9. URI location = file.getLocationURI();
  10. if (location == null) return false; // unable to determine location of this class file
  11. String filePath = location.getSchemeSpecificPart();
  12. ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray());
  13. // ignore local types since they're only visible inside a single method
  14. if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
  15. if (JavaBuilder.DEBUG)
  16. System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
  17. addDependentsOf(new Path(fileName), true);
  18. this.newState.wasStructurallyChanged(fileName);
  19. }
  20. } catch (ClassFormatException e) {
  21. addDependentsOf(new Path(fileName), true);
  22. this.newState.wasStructurallyChanged(fileName);
  23. }
  24. return true;
  25. }

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core

  1. protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException {
  2. try {
  3. byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
  4. notEqual : if (newBytes.length == oldBytes.length) {
  5. for (int i = newBytes.length; --i >= 0;)
  6. if (newBytes[i] != oldBytes[i]) break notEqual;
  7. return false; // bytes are identical so skip them
  8. }
  9. URI location = file.getLocationURI();
  10. if (location == null) return false; // unable to determine location of this class file
  11. String filePath = location.getSchemeSpecificPart();
  12. ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray());
  13. // ignore local types since they're only visible inside a single method
  14. if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
  15. if (JavaBuilder.DEBUG)
  16. System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
  17. addDependentsOf(new Path(fileName), true);
  18. this.newState.wasStructurallyChanged(fileName);
  19. }
  20. } catch (ClassFormatException e) {
  21. addDependentsOf(new Path(fileName), true);
  22. this.newState.wasStructurallyChanged(fileName);
  23. }
  24. return true;
  25. }

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

  1. protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException {
  2. try {
  3. byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
  4. notEqual : if (newBytes.length == oldBytes.length) {
  5. for (int i = newBytes.length; --i >= 0;)
  6. if (newBytes[i] != oldBytes[i]) break notEqual;
  7. return false; // bytes are identical so skip them
  8. }
  9. URI location = file.getLocationURI();
  10. if (location == null) return false; // unable to determine location of this class file
  11. String filePath = location.getSchemeSpecificPart();
  12. ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray());
  13. // ignore local types since they're only visible inside a single method
  14. if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
  15. if (JavaBuilder.DEBUG)
  16. System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
  17. addDependentsOf(new Path(fileName), true);
  18. this.newState.wasStructurallyChanged(fileName);
  19. }
  20. } catch (ClassFormatException e) {
  21. addDependentsOf(new Path(fileName), true);
  22. this.newState.wasStructurallyChanged(fileName);
  23. }
  24. return true;
  25. }

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core

  1. protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException {
  2. try {
  3. byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
  4. notEqual : if (newBytes.length == oldBytes.length) {
  5. for (int i = newBytes.length; --i >= 0;)
  6. if (newBytes[i] != oldBytes[i]) break notEqual;
  7. return false; // bytes are identical so skip them
  8. }
  9. URI location = file.getLocationURI();
  10. if (location == null) return false; // unable to determine location of this class file
  11. String filePath = location.getSchemeSpecificPart();
  12. ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray());
  13. // ignore local types since they're only visible inside a single method
  14. if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
  15. if (JavaBuilder.DEBUG)
  16. System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
  17. addDependentsOf(new Path(fileName), true);
  18. this.newState.wasStructurallyChanged(fileName);
  19. }
  20. } catch (ClassFormatException e) {
  21. addDependentsOf(new Path(fileName), true);
  22. this.newState.wasStructurallyChanged(fileName);
  23. }
  24. return true;
  25. }

代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core

  1. protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException {
  2. try {
  3. byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
  4. notEqual : if (newBytes.length == oldBytes.length) {
  5. for (int i = newBytes.length; --i >= 0;)
  6. if (newBytes[i] != oldBytes[i]) break notEqual;
  7. return false; // bytes are identical so skip them
  8. }
  9. URI location = file.getLocationURI();
  10. if (location == null) return false; // unable to determine location of this class file
  11. String filePath = location.getSchemeSpecificPart();
  12. ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray());
  13. // ignore local types since they're only visible inside a single method
  14. if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
  15. if (JavaBuilder.DEBUG)
  16. System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
  17. addDependentsOf(new Path(fileName), true);
  18. this.newState.wasStructurallyChanged(fileName);
  19. }
  20. } catch (ClassFormatException e) {
  21. addDependentsOf(new Path(fileName), true);
  22. this.newState.wasStructurallyChanged(fileName);
  23. }
  24. return true;
  25. }

代码示例来源:origin: trylimits/Eclipse-Postfix-Code-Completion

  1. protected boolean writeClassFileCheck(IFile file, String fileName, byte[] newBytes) throws CoreException {
  2. try {
  3. byte[] oldBytes = Util.getResourceContentsAsByteArray(file);
  4. notEqual : if (newBytes.length == oldBytes.length) {
  5. for (int i = newBytes.length; --i >= 0;)
  6. if (newBytes[i] != oldBytes[i]) break notEqual;
  7. return false; // bytes are identical so skip them
  8. }
  9. URI location = file.getLocationURI();
  10. if (location == null) return false; // unable to determine location of this class file
  11. String filePath = location.getSchemeSpecificPart();
  12. ClassFileReader reader = new ClassFileReader(oldBytes, filePath.toCharArray());
  13. // ignore local types since they're only visible inside a single method
  14. if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) {
  15. if (JavaBuilder.DEBUG)
  16. System.out.println("Type has structural changes " + fileName); //$NON-NLS-1$
  17. addDependentsOf(new Path(fileName), true);
  18. this.newState.wasStructurallyChanged(fileName);
  19. }
  20. } catch (ClassFormatException e) {
  21. addDependentsOf(new Path(fileName), true);
  22. this.newState.wasStructurallyChanged(fileName);
  23. }
  24. return true;
  25. }

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core

  1. byte[] contents = Util.getResourceContentsAsByteArray(file);
  2. try {
  3. return new ClassFileReader(contents, file.getFullPath().toString().toCharArray(), fullyInitialize);

代码示例来源:origin: com.google.code.maven-play-plugin.org.eclipse.jdt/org.eclipse.jdt.core

  1. byte[] contents = Util.getResourceContentsAsByteArray(file);
  2. try {
  3. return new ClassFileReader(contents, file.getFullPath().toString().toCharArray(), fullyInitialize);

代码示例来源:origin: org.eclipse.tycho/org.eclipse.jdt.core

  1. public byte[] getBytes() throws JavaModelException {
  2. JavaElement pkg = (JavaElement) getParent();
  3. if (pkg instanceof JarPackageFragment) {
  4. JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
  5. try {
  6. String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
  7. entryName = root.getClassFilePath(entryName);
  8. return getClassFileContent(root, entryName);
  9. // Java 9 - The below exception is not thrown in new scheme of things. Could cause issues?
  10. // throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
  11. } catch (IOException ioe) {
  12. throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
  13. } catch (CoreException e) {
  14. if (e instanceof JavaModelException) {
  15. throw (JavaModelException)e;
  16. } else {
  17. throw new JavaModelException(e);
  18. }
  19. }
  20. } else {
  21. IFile file = (IFile) resource();
  22. return Util.getResourceContentsAsByteArray(file);
  23. }
  24. }
  25. protected byte[] getClassFileContent(JarPackageFragmentRoot root, String className) throws CoreException, IOException {

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.core

  1. @Override
  2. public byte[] getBytes() throws JavaModelException {
  3. JavaElement pkg = (JavaElement) getParent();
  4. if (pkg instanceof JarPackageFragment) {
  5. JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
  6. try {
  7. String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
  8. entryName = root.getClassFilePath(entryName);
  9. return getClassFileContent(root, entryName);
  10. // Java 9 - The below exception is not thrown in new scheme of things. Could cause issues?
  11. // throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
  12. } catch (IOException ioe) {
  13. throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
  14. } catch (CoreException e) {
  15. if (e instanceof JavaModelException) {
  16. throw (JavaModelException)e;
  17. } else {
  18. throw new JavaModelException(e);
  19. }
  20. }
  21. } else {
  22. IFile file = (IFile) resource();
  23. return Util.getResourceContentsAsByteArray(file);
  24. }
  25. }
  26. protected byte[] getClassFileContent(JarPackageFragmentRoot root, String className) throws CoreException, IOException {

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.jdt.core

  1. public byte[] getBytes() throws JavaModelException {
  2. JavaElement pkg = (JavaElement) getParent();
  3. if (pkg instanceof JarPackageFragment) {
  4. JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
  5. ZipFile zip = null;
  6. try {
  7. zip = root.getJar();
  8. String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
  9. ZipEntry ze = zip.getEntry(entryName);
  10. if (ze != null) {
  11. return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
  12. }
  13. throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
  14. } catch (IOException ioe) {
  15. throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
  16. } catch (CoreException e) {
  17. if (e instanceof JavaModelException) {
  18. throw (JavaModelException)e;
  19. } else {
  20. throw new JavaModelException(e);
  21. }
  22. } finally {
  23. JavaModelManager.getJavaModelManager().closeZipFile(zip);
  24. }
  25. } else {
  26. IFile file = (IFile) resource();
  27. return Util.getResourceContentsAsByteArray(file);
  28. }
  29. }
  30. private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException {

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.core

  1. public byte[] getBytes() throws JavaModelException {
  2. JavaElement pkg = (JavaElement) getParent();
  3. if (pkg instanceof JarPackageFragment) {
  4. JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
  5. ZipFile zip = null;
  6. try {
  7. zip = root.getJar();
  8. String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
  9. ZipEntry ze = zip.getEntry(entryName);
  10. if (ze != null) {
  11. return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
  12. }
  13. throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
  14. } catch (IOException ioe) {
  15. throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
  16. } catch (CoreException e) {
  17. if (e instanceof JavaModelException) {
  18. throw (JavaModelException)e;
  19. } else {
  20. throw new JavaModelException(e);
  21. }
  22. } finally {
  23. JavaModelManager.getJavaModelManager().closeZipFile(zip);
  24. }
  25. } else {
  26. IFile file = (IFile) resource();
  27. return Util.getResourceContentsAsByteArray(file);
  28. }
  29. }
  30. 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

  1. public byte[] getBytes() throws JavaModelException {
  2. JavaElement pkg = (JavaElement) getParent();
  3. if (pkg instanceof JarPackageFragment) {
  4. JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
  5. ZipFile zip = null;
  6. try {
  7. zip = root.getJar();
  8. String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
  9. ZipEntry ze = zip.getEntry(entryName);
  10. if (ze != null) {
  11. return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
  12. }
  13. throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
  14. } catch (IOException ioe) {
  15. throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
  16. } catch (CoreException e) {
  17. if (e instanceof JavaModelException) {
  18. throw (JavaModelException)e;
  19. } else {
  20. throw new JavaModelException(e);
  21. }
  22. } finally {
  23. JavaModelManager.getJavaModelManager().closeZipFile(zip);
  24. }
  25. } else {
  26. IFile file = (IFile) resource();
  27. return Util.getResourceContentsAsByteArray(file);
  28. }
  29. }
  30. private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException {

代码示例来源:origin: trylimits/Eclipse-Postfix-Code-Completion

  1. public byte[] getBytes() throws JavaModelException {
  2. JavaElement pkg = (JavaElement) getParent();
  3. if (pkg instanceof JarPackageFragment) {
  4. JarPackageFragmentRoot root = (JarPackageFragmentRoot) pkg.getParent();
  5. ZipFile zip = null;
  6. try {
  7. zip = root.getJar();
  8. String entryName = Util.concatWith(((PackageFragment) pkg).names, getElementName(), '/');
  9. ZipEntry ze = zip.getEntry(entryName);
  10. if (ze != null) {
  11. return org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
  12. }
  13. throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, this));
  14. } catch (IOException ioe) {
  15. throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
  16. } catch (CoreException e) {
  17. if (e instanceof JavaModelException) {
  18. throw (JavaModelException)e;
  19. } else {
  20. throw new JavaModelException(e);
  21. }
  22. } finally {
  23. JavaModelManager.getJavaModelManager().closeZipFile(zip);
  24. }
  25. } else {
  26. IFile file = (IFile) resource();
  27. return Util.getResourceContentsAsByteArray(file);
  28. }
  29. }
  30. private IBinaryType getJarBinaryTypeInfo(PackageFragment pkg, boolean fullyInitialize) throws CoreException, IOException, ClassFormatException {

相关文章

Util类方法