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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -33,7 +33,9 @@ public class FileContentHelper {
|
||||||
InputStreamReader reader = getReaderForFile(file);
|
InputStreamReader reader = getReaderForFile(file);
|
||||||
skip(start, reader);
|
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);
|
skip(start, r);
|
||||||
|
|
||||||
read(length, r, bytes);
|
read(length, r, bytes);
|
||||||
|
r.close();
|
||||||
return new String(bytes);
|
return new String(bytes);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
CCorePlugin.log(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
|
* Rapperswil, University of applied sciences and others
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
@ -10,11 +10,9 @@
|
||||||
* Institute for Software - initial API and implementation
|
* Institute for Software - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.dom.rewrite.util;
|
package org.eclipse.cdt.internal.core.dom.rewrite.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||||
|
@ -40,40 +38,37 @@ public class FileHelper {
|
||||||
return ResourceLookup.selectFileForLocation(implPath, null);
|
return ResourceLookup.selectFileForLocation(implPath, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2){
|
public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2) {
|
||||||
|
|
||||||
boolean isEquals = true;
|
boolean isEquals = true;
|
||||||
|
|
||||||
isEquals &= loc1.getFileName().equals(loc2.getFileName());
|
isEquals &= loc1.getFileName().equals(loc2.getFileName());
|
||||||
isEquals &= loc1.getNodeOffset() >= loc2.getNodeOffset();
|
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;
|
return isEquals;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String determineLineDelimiter(IFile file) {
|
public static String determineLineDelimiter(IFile file) {
|
||||||
StringBuilder fileContent = new StringBuilder();
|
String fileContent = ""; //$NON-NLS-1$
|
||||||
|
|
||||||
try {
|
try {
|
||||||
InputStream fis = file.getContents();
|
fileContent = FileContentHelper.getContent(file, 0);
|
||||||
byte[] buffer = new byte[1024];
|
|
||||||
int read;
|
|
||||||
while ((read = fis.read(buffer)) >= 0)
|
|
||||||
fileContent.append(new String(buffer, 0, read));
|
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
} catch (NullPointerException e){
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject();
|
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject();
|
||||||
IScopeContext[] scopeContext;
|
IScopeContext[] scopeContext;
|
||||||
if(project != null){
|
if (project != null) {
|
||||||
scopeContext = new IScopeContext[] { new ProjectScope(project)};
|
scopeContext = new IScopeContext[] { new ProjectScope(project) };
|
||||||
}
|
} else {
|
||||||
else{
|
scopeContext = new IScopeContext[] { new InstanceScope() };
|
||||||
scopeContext = new IScopeContext[] { new InstanceScope()};
|
|
||||||
}
|
}
|
||||||
String platformDefaultLineDelimiter = System.getProperty("line.separator", DEFAULT_LINE_DELIMITTER); //$NON-NLS-1$
|
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);
|
return TextUtilities.determineLineDelimiter(fileContent.toString(), defaultLineDelimiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue