From 18d9a53b48f3ecb3a700b286dde8727c3ae8a3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Wed, 12 Jun 2024 09:29:46 +0200 Subject: [PATCH] [performance] Use new IFile API: IFile.readAllBytes() / readAllChars() Instead of streaming IFile.getContents(true) --- org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF | 2 +- .../core/internal/util/FileSystemUtil.java | 38 +++------ .../compiler/batch/ClasspathJsr199.java | 2 +- .../compiler/classfmt/ClassFileReader.java | 8 +- .../jdt/internal/compiler/util/Util.java | 4 + .../META-INF/MANIFEST.MF | 4 +- org.eclipse.jdt.core.tests.builder/pom.xml | 2 +- .../jdt/core/tests/builder/ErrorsTests.java | 15 +--- .../META-INF/MANIFEST.MF | 2 +- .../regression/AbstractRegressionTest.java | 78 +++---------------- org.eclipse.jdt.core/META-INF/MANIFEST.MF | 4 +- .../jdt/internal/core/CompilationUnit.java | 12 +-- .../eclipse/jdt/internal/core/util/Util.java | 28 +++---- .../nd/java/model/BinaryModuleFactory.java | 7 +- .../core/nd/java/model/BinaryTypeFactory.java | 7 +- 15 files changed, 56 insertions(+), 157 deletions(-) diff --git a/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF index 04adcc31931..85775ec2628 100644 --- a/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF @@ -20,7 +20,7 @@ Export-Package: com.sun.mirror.apt, org.eclipse.jdt.apt.core.util Require-Bundle: org.eclipse.jdt.core;bundle-version="[3.36.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)", - org.eclipse.core.resources;bundle-version="[3.6.0,4.0.0)", + org.eclipse.core.resources;bundle-version="[3.21.0,4.0.0)", org.apache.ant;bundle-version="1.6.5" Bundle-Activator: org.eclipse.jdt.apt.core.internal.AptPlugin Bundle-Vendor: %providerName diff --git a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/FileSystemUtil.java b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/FileSystemUtil.java index 7f7cf55f1c0..e90093cc0a5 100644 --- a/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/FileSystemUtil.java +++ b/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/util/FileSystemUtil.java @@ -15,13 +15,13 @@ import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; @@ -126,32 +126,18 @@ public static void makeDerivedParentFolders (IContainer container) throws CoreEx } /** - * Returns the contents of a file as a string in UTF8 format + * Returns the contents of a IFile as a string in UTF8 format */ - public static String getContentsOfIFile(IFile file) throws IOException, CoreException { - return getContents(file.getContents(true)); - } - - public static String getContentsOfFile(File file) throws IOException { - return getContents(new FileInputStream(file)); - } + public static String getContentsOfIFile(IFile file) throws IOException, CoreException { + return new String(file.readAllBytes(), StandardCharsets.UTF_8); + } - private static String getContents(InputStream in) throws IOException { - try { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - byte[] buffer = new byte[512]; - int len; - while ((len = in.read(buffer)) > 0) { - out.write(buffer, 0, len); - } - out.close(); - String s = new String(out.toByteArray(), "UTF8"); //$NON-NLS-1$ - return s; - } - finally { - try {in.close();} catch (IOException ioe) {} - } - } + /** + * Returns the contents of a file as a string in UTF8 format + */ + public static String getContentsOfFile(File file) throws IOException { + return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); + } /** * Stores a string into an Eclipse file in UTF8 format. The file diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java index 9366e7dbf25..fcff3f78b20 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java @@ -100,7 +100,7 @@ public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageN return null; // most common case try (InputStream inputStream = jfo.openInputStream()) { - ClassFileReader reader = ClassFileReader.read(inputStream, qualifiedBinaryFileName); + ClassFileReader reader = ClassFileReader.read(inputStream.readAllBytes(), qualifiedBinaryFileName); if (reader != null) { return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName)); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java index 1f128dda281..be941d1f98e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/classfmt/ClassFileReader.java @@ -118,12 +118,12 @@ public static ClassFileReader read(File file, boolean fullyInitialize) throws Cl return classFileReader; } -public static ClassFileReader read(InputStream stream, String fileName) throws ClassFormatException, IOException { - return read(stream, fileName, false); +public static ClassFileReader read(byte[] classFileBytes, String fileName) throws ClassFormatException, IOException { + return read(classFileBytes, fileName, false); } -public static ClassFileReader read(InputStream stream, String fileName, boolean fullyInitialize) throws ClassFormatException, IOException { - byte classFileBytes[] = Util.getInputStreamAsByteArray(stream); +public static ClassFileReader read(byte[] classFileBytes, String fileName, boolean fullyInitialize) + throws ClassFormatException { ClassFileReader classFileReader = new ClassFileReader(classFileBytes, fileName.toCharArray()); if (fullyInitialize) { classFileReader.initialize(); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/Util.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/Util.java index 3c35a51b1eb..4bb18c5b5ed 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/Util.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/util/Util.java @@ -477,6 +477,10 @@ public static char[] getInputStreamAsCharArray(InputStream stream, String encod throws IOException { byte[] byteContents = getInputStreamAsByteArray(stream); + return getBytesAsCharArray(byteContents, encoding); + } + + public static char[] getBytesAsCharArray(byte[] byteContents, String encoding) { Charset charset; try { charset = Charset.forName(encoding); diff --git a/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF index 0d4125e0e56..218db4fd941 100644 --- a/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF @@ -2,14 +2,14 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.jdt.core.tests.builder; singleton:=true -Bundle-Version: 3.12.400.qualifier +Bundle-Version: 3.12.500.qualifier Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.jdt.core.tests.builder Require-Bundle: org.junit;bundle-version="3.8.1", org.eclipse.jdt.core;bundle-version="[3.36.0,4.0.0)", org.eclipse.jdt.core.tests.compiler;bundle-version="[3.4.0,4.0.0)", - org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", + org.eclipse.core.resources;bundle-version="[3.21.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)", org.eclipse.test.performance;bundle-version="[3.1.0,4.0.0)", org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional, diff --git a/org.eclipse.jdt.core.tests.builder/pom.xml b/org.eclipse.jdt.core.tests.builder/pom.xml index f05759e2486..d1d0d0079ab 100644 --- a/org.eclipse.jdt.core.tests.builder/pom.xml +++ b/org.eclipse.jdt.core.tests.builder/pom.xml @@ -18,7 +18,7 @@ ../tests-pom/ org.eclipse.jdt.core.tests.builder - 3.12.400-SNAPSHOT + 3.12.500-SNAPSHOT eclipse-test-plugin diff --git a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java index 6d698defc81..2bca1e0cb1b 100644 --- a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java +++ b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java @@ -423,21 +423,10 @@ public void test0107() throws JavaModelException { assertEquals("Wrong type", IResource.FILE, resources[0].getType()); IFile classFile = (IFile) resources[0]; - InputStream stream = null; try { - stream = classFile.getContents(); - ClassFileReader.read(stream, "C.java"); + ClassFileReader.read(classFile.readAllBytes(), "C.java"); } catch (Exception e) { - e.printStackTrace(); - assertTrue("Should not happen", false); - } finally { - if (stream != null) { - try { - stream.close(); - } catch(IOException e) { - // ignore - } - } + throw new AssertionError(e); } } private String getResourceOuput(IResource[] resources) { diff --git a/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF index d0807bc7a71..f9e826fbaab 100644 --- a/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF @@ -20,7 +20,7 @@ Require-Bundle: org.junit;bundle-version="3.8.1", org.eclipse.jdt.core;bundle-version="[3.36.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)", org.eclipse.test.performance;bundle-version="[3.10.0,4.0.0)", - org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", + org.eclipse.core.resources;bundle-version="[3.21.0,4.0.0)", org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional, org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional Import-Package: jakarta.annotation;version="[2.1.0,3.0.0)", diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index decac49c0aa..2c90b881a22 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -26,7 +26,6 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; @@ -1381,24 +1380,10 @@ protected void checkClassFile(String directoryName, String className, String dis if (index == -1) { assertEquals("Wrong contents", expectedOutput, result); } - FileInputStream stream = null; try { - stream = new FileInputStream(f); - ClassFileReader.read(stream, className + ".class", true); - } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { - e.printStackTrace(); - assertTrue("ClassFormatException", false); - } catch (IOException e) { - e.printStackTrace(); - assertTrue("IOException", false); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - /* ignore */ - } - } + ClassFileReader.read(Files.readAllBytes(f.toPath()), className + ".class", true); + } catch (Exception e) { + throw new AssertionError(e); } } finally { removeTempClass(className); @@ -1418,24 +1403,10 @@ protected ClassFileReader getInternalClassFile(String directoryName, String clas } File f = new File(directory, disassembledClassName + ".class"); ClassFileReader classFileReader = null; - FileInputStream stream = null; try { - stream = new FileInputStream(f); - classFileReader = ClassFileReader.read(stream, className + ".class", true); - } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { - e.printStackTrace(); - assertTrue("ClassFormatException", false); - } catch (IOException e) { - e.printStackTrace(); - assertTrue("IOException", false); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - /* ignore */ - } - } + classFileReader = ClassFileReader.read(Files.readAllBytes(f.toPath()), className + ".class", true); + } catch (Exception e) { + throw new AssertionError(e); } return classFileReader; } finally { @@ -1468,19 +1439,7 @@ protected void checkDisassembledClassFile(String fileName, String className, Str fail("ClassFormatException swallowed in Disassembler:\n..." + result.substring(start, end)); } - FileInputStream stream = null; - try { - stream = new FileInputStream(classFile); - ClassFileReader.read(stream, className + ".class", true); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - /* ignore */ - } - } - } + ClassFileReader.read(Files.readAllBytes(classFile.toPath()), className + ".class", true); } protected void compileAndDeploy(String source, String directoryName, String className, boolean suppressConsole) { @@ -1712,30 +1671,15 @@ protected void addIndexEntry(char[] category, char[] key) { protected ClassFileReader getClassFileReader(String fileName, String className) { File classFile = new File(fileName); - if (!classFile.exists()) { - assertTrue(".class file doesn't exist", false); - } - FileInputStream stream = null; + assertTrue(".class file doesn't exist:" + fileName, classFile.exists()); try { - stream = new FileInputStream(classFile); - ClassFileReader reader = ClassFileReader.read(stream, className + ".class", true); + ClassFileReader reader = ClassFileReader.read(Files.readAllBytes(classFile.toPath()), className + ".class", true); return reader; } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { - e.printStackTrace(); - assertTrue("ClassFormatException", false); + throw new AssertionError(e); } catch (IOException e) { - e.printStackTrace(); - assertTrue("IOException", false); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (IOException e) { - /* ignore */ - } - } + throw new AssertionError(e); } - return null; } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { diff --git a/org.eclipse.jdt.core/META-INF/MANIFEST.MF b/org.eclipse.jdt.core/META-INF/MANIFEST.MF index 2dfff3fc7c8..d22fc322a19 100644 --- a/org.eclipse.jdt.core/META-INF/MANIFEST.MF +++ b/org.eclipse.jdt.core/META-INF/MANIFEST.MF @@ -42,9 +42,9 @@ Export-Package: org.eclipse.jdt.core, org.eclipse.jdt.internal.formatter;x-friends:="org.eclipse.jdt.core.tests.model, org.eclipse.jdt.core.tests.compiler, org.eclipse.jdt.core.tests.builder, org.eclipse.jdt.core.tests.performance, org.eclipse.jdt.ui.tests, org.eclipse.jdt.ui.tests", org.eclipse.jdt.internal.formatter.linewrap;x-friends:="org.eclipse.jdt.core.tests.model, org.eclipse.jdt.core.tests.compiler, org.eclipse.jdt.core.tests.builder, org.eclipse.jdt.core.tests.performance, org.eclipse.jdt.ui.tests", org.eclipse.jdt.internal.formatter.old;x-friends:="org.eclipse.jdt.core.tests.model, org.eclipse.jdt.core.tests.compiler, org.eclipse.jdt.core.tests.builder, org.eclipse.jdt.core.tests.performance, org.eclipse.jdt.ui.tests" -Require-Bundle: org.eclipse.core.resources;bundle-version="[3.18.0,4.0.0)", +Require-Bundle: org.eclipse.core.resources;bundle-version="[3.21.0,4.0.0)", org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)", - org.eclipse.core.filesystem;bundle-version="[1.7.0,2.0.0)", + org.eclipse.core.filesystem;bundle-version="[1.11.0,2.0.0)", org.eclipse.text;bundle-version="[3.6.0,4.0.0)", org.eclipse.team.core;bundle-version="[3.1.0,4.0.0)";resolution:=optional, org.eclipse.jdt.core.compiler.batch;bundle-version="3.38.0";visibility:=reexport diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java index 794bf5c08d5..0a85ca4807e 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/CompilationUnit.java @@ -667,23 +667,15 @@ public char[] getContents() { // no need to force opening of CU to get the content // also this cannot be a working copy, as its buffer is never closed while the working copy is alive IFile file = (IFile) getResource(); - // Get encoding from file - String encoding; try { - encoding = file.getCharset(); - } catch(CoreException ce) { - // do not use any encoding - encoding = null; - } - try { - return Util.getResourceContentsAsCharArray(file, encoding); + return Util.getResourceContentsAsCharArray(file); } catch (JavaModelException e) { if (JavaModelManager.getJavaModelManager().abortOnMissingSource.get() == Boolean.TRUE) { IOException ioException = e.getJavaModelStatus().getCode() == IJavaModelStatusConstants.IO_EXCEPTION ? (IOException)e.getException() : new IOException(e.getMessage()); - throw new AbortCompilationUnit(null, ioException, encoding); + throw new AbortCompilationUnit(null, ioException, null); } else { Util.log(e); } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java index 0c22cd03cff..80d0dede28c 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java @@ -1172,12 +1172,10 @@ private static String[] decodeArgumentString(int length, String argumentsString) * Returns the given file's contents as a byte array. */ public static byte[] getResourceContentsAsByteArray(IFile file) throws JavaModelException { - try (InputStream stream = file.getContents(true)) { - return org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsByteArray(stream); + try { + return file.readAllBytes(); } catch (CoreException e) { - throw new JavaModelException(e); - } catch (IOException e) { - throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); + throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); } } @@ -1185,23 +1183,17 @@ public static byte[] getResourceContentsAsByteArray(IFile file) throws JavaModel * Returns the given file's contents as a character array. */ public static char[] getResourceContentsAsCharArray(IFile file) throws JavaModelException { - // Get encoding from file - String encoding; try { - encoding = file.getCharset(); - } catch(CoreException ce) { - // do not use any encoding - encoding = null; + return file.readAllChars(); + } catch (CoreException e) { + throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); } - return getResourceContentsAsCharArray(file, encoding); } public static char[] getResourceContentsAsCharArray(IFile file, String encoding) throws JavaModelException { // Get resource contents - try (InputStream stream = file.getContents(true)) { - return org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsCharArray(stream, encoding); - } catch (IOException e) { - throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); + try { + return org.eclipse.jdt.internal.compiler.util.Util.getBytesAsCharArray(file.readAllBytes(), encoding); } catch (CoreException e) { throw new JavaModelException(e, IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST); } @@ -1906,9 +1898,7 @@ public static void log(Throwable e) { } public static ClassFileReader newClassFileReader(IResource resource) throws CoreException, ClassFormatException, IOException { - try (InputStream in = ((IFile) resource).getContents(true)) { - return ClassFileReader.read(in, resource.getFullPath().toString()); - } + return ClassFileReader.read(((IFile) resource).readAllBytes(), resource.getFullPath().toString()); } /** diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/model/BinaryModuleFactory.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/model/BinaryModuleFactory.java index 7474c0ebeef..5aea825cc6a 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/model/BinaryModuleFactory.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/model/BinaryModuleFactory.java @@ -15,7 +15,6 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -145,16 +144,14 @@ public static IBinaryModule rawReadModuleTestForExists(BinaryModuleDescriptor de } else { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(new String(descriptor.workspacePath))); byte[] contents; - try (InputStream stream = file.getContents(true)) { - contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsByteArray(stream); + try { + contents = file.readAllBytes(); } catch (CoreException e) { IStatus status = e.getStatus(); if (status.getCode() == IResourceStatus.RESOURCE_NOT_FOUND) { throw new FileNotFoundException(); } throw new JavaModelException(e); - } catch (IOException e) { - throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } ClassFileReader classFileReader = new ClassFileReader(contents, file.getFullPath().toString().toCharArray(), fullyInitialize); return classFileReader.getModuleDeclaration(); diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/model/BinaryTypeFactory.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/model/BinaryTypeFactory.java index 32933f25290..53ff7eef77d 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/model/BinaryTypeFactory.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/nd/java/model/BinaryTypeFactory.java @@ -15,7 +15,6 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -165,16 +164,14 @@ public static ClassFileReader rawReadTypeTestForExists(BinaryTypeDescriptor desc } else { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(new String(descriptor.workspacePath))); byte[] contents; - try (InputStream stream = file.getContents(true)) { - contents = org.eclipse.jdt.internal.compiler.util.Util.getInputStreamAsByteArray(stream); + try { + contents = file.readAllBytes(); } catch (CoreException e) { IStatus status = e.getStatus(); if (status.getCode() == IResourceStatus.RESOURCE_NOT_FOUND) { throw new FileNotFoundException(); } throw new JavaModelException(e); - } catch (IOException e) { - throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION); } return new ClassFileReader(contents, file.getFullPath().toString().toCharArray(), fullyInitialize); }