Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmanuel Graf2011-02-21 07:11:07 -0500
committerEmanuel Graf2011-02-21 07:11:07 -0500
commit8d45a913ca3be63e7e57c1d4b4e6fe1d5e1bd84b (patch)
tree6a4c9b5a3e2befcf75ff2451742de2feb8b951a7 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite
parent4cff1415976acc0f8f4ff862846c9fea7bcd3fa3 (diff)
downloadorg.eclipse.cdt-8d45a913ca3be63e7e57c1d4b4e6fe1d5e1bd84b.tar.gz
org.eclipse.cdt-8d45a913ca3be63e7e57c1d4b4e6fe1d5e1bd84b.tar.xz
org.eclipse.cdt-8d45a913ca3be63e7e57c1d4b4e6fe1d5e1bd84b.zip
Bug 337701: Fixed, FileContentHelper doesn't close streams
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337701
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java8
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java41
2 files changed, 23 insertions, 26 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
index a9fa9a9faa..6c8aaa8c51 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileContentHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -33,7 +33,9 @@ public class FileContentHelper {
InputStreamReader reader = getReaderForFile(file);
skip(start, reader);
- return readRest(reader);
+ final String rest = readRest(reader);
+ reader.close();
+ return rest;
}
@@ -45,7 +47,7 @@ public class FileContentHelper {
skip(start, r);
read(length, r, bytes);
-
+ r.close();
return new String(bytes);
} catch (IOException e) {
CCorePlugin.log(e);
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java
index 656f115c8b..5963520885 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik
+ * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik
* Rapperswil, University of applied sciences and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -10,11 +10,9 @@
* Institute for Software - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.dom.rewrite.util;
import java.io.IOException;
-import java.io.InputStream;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@@ -39,41 +37,38 @@ public class FileHelper {
IPath implPath = new Path(node.getContainingFilename());
return ResourceLookup.selectFileForLocation(implPath, null);
}
-
- public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2){
-
+
+ public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2) {
+
boolean isEquals = true;
-
+
isEquals &= loc1.getFileName().equals(loc2.getFileName());
isEquals &= loc1.getNodeOffset() >= loc2.getNodeOffset();
- isEquals &= loc1.getNodeOffset()+loc1.getNodeLength() <= loc2.getNodeOffset() + loc2.getNodeLength();
-
+ isEquals &= loc1.getNodeOffset() + loc1.getNodeLength() <= loc2.getNodeOffset()
+ + loc2.getNodeLength();
+
return isEquals;
}
public static String determineLineDelimiter(IFile file) {
- StringBuilder fileContent = new StringBuilder();
+ String fileContent = ""; //$NON-NLS-1$
+
try {
- InputStream fis = file.getContents();
- byte[] buffer = new byte[1024];
- int read;
- while ((read = fis.read(buffer)) >= 0)
- fileContent.append(new String(buffer, 0, read));
+ fileContent = FileContentHelper.getContent(file, 0);
} catch (CoreException e) {
} catch (IOException e) {
- } catch (NullPointerException e){
}
-
+
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject();
IScopeContext[] scopeContext;
- if(project != null){
- scopeContext = new IScopeContext[] { new ProjectScope(project)};
- }
- else{
- scopeContext = new IScopeContext[] { new InstanceScope()};
+ if (project != null) {
+ scopeContext = new IScopeContext[] { new ProjectScope(project) };
+ } else {
+ scopeContext = new IScopeContext[] { new InstanceScope() };
}
String platformDefaultLineDelimiter = System.getProperty("line.separator", DEFAULT_LINE_DELIMITTER); //$NON-NLS-1$
- String defaultLineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, platformDefaultLineDelimiter, scopeContext);
+ String defaultLineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME,
+ Platform.PREF_LINE_SEPARATOR, platformDefaultLineDelimiter, scopeContext);
return TextUtilities.determineLineDelimiter(fileContent.toString(), defaultLineDelimiter);
}
}

Back to the top