Bug 500477 - Use try-with in CreateFileChange
Change-Id: I3c0430e68c09866d9963ceb68d2884a12e8b69ad
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
diff --git a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/refactoring/CreateFileChange.java b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/refactoring/CreateFileChange.java
index 3c1bc52..e33d97f 100644
--- a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/refactoring/CreateFileChange.java
+++ b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/refactoring/CreateFileChange.java
@@ -123,14 +123,12 @@
@Override
public Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
- InputStream is = null;
- try {
- SubMonitor subMonitor = SubMonitor.convert(pm, RefactoringMessages.CreateFileChange_3, 3);
+ SubMonitor subMonitor = SubMonitor.convert(pm, RefactoringMessages.CreateFileChange_3, 3);
+ try {
initializeEncoding();
IFile file = getOldFile(subMonitor.split(1));
- try {
- is = new ByteArrayInputStream(fSource.getBytes(fEncoding));
+ try (InputStream is = new ByteArrayInputStream(fSource.getBytes(fEncoding))) {
file.create(is, false, subMonitor.split(1));
if (fStampToRestore != IResource.NULL_STAMP) {
file.revertModificationStamp(fStampToRestore);
@@ -144,14 +142,8 @@
} catch (UnsupportedEncodingException e) {
throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
}
- } finally {
- try {
- if (is != null) {
- is.close();
- }
- } catch (IOException ioe) {
- throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
- }
+ } catch (IOException ioe) {
+ throw new JavaModelException(ioe, IJavaModelStatusConstants.IO_EXCEPTION);
}
}