mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 337701: Fixed, FileContentHelper doesn't close streams
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337701
This commit is contained in:
parent
4cff141597
commit
8d45a913ca
2 changed files with 23 additions and 26 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue