1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 11:25:35 +02:00

Part of PR 68246.

Close the inputstream to release resource handle
	when we done with it, we can not rely on the GC to do it for us.
This commit is contained in:
Alain Magloire 2004-06-23 03:32:16 +00:00
parent 36ec31dca2
commit dbaa2dcea9
10 changed files with 97 additions and 12 deletions

View file

@ -1,3 +1,10 @@
2004-06-22 Alain Magloire
Part of PR 68246.
Close the inputstream to release resource handle
when we done with it, we can not rely on the GC to do it for us.
* src/org/eclipse/cdt/core/parsre/ParserUtil.java
2004-06-22 Alain Magloire 2004-06-22 Alain Magloire
Fix the exclusion scheme in IPathEntry. Fix the exclusion scheme in IPathEntry.

View file

@ -1,3 +1,10 @@
2004-06-22 Alain Magloire
Part of PR 68246.
Close the inputstream to release resource handle
when we done with it, we can not rely on the GC to do it for us.
* browser/org/eclipse/cdt/internal/core/browser/cache/TypeParser.java
2004-06-21 Chris Wiebe 2004-06-21 Chris Wiebe
- fix for bug #66108 (C++ browser cannot show members of class) - fix for bug #66108 (C++ browser cannot show members of class)

View file

@ -371,13 +371,22 @@ public class TypeParser implements ISourceElementRequestor {
CodeReader reader = null; CodeReader reader = null;
if (resource.isAccessible() && resource instanceof IFile) { if (resource.isAccessible() && resource instanceof IFile) {
IFile file = (IFile) resource; IFile file = (IFile) resource;
InputStream contents = null;
try { try {
InputStream contents = file.getContents(); contents = file.getContents();
if (contents != null) if (contents != null)
reader = new CodeReader(resource.getLocation().toOSString(), contents); reader = new CodeReader(resource.getLocation().toOSString(), contents);
} catch (CoreException ex) { } catch (CoreException ex) {
ex.printStackTrace(); ex.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
} finally {
if (contents != null) {
try {
contents.close();
} catch (IOException io) {
// ignore
}
}
} }
} }
return reader; return reader;

View file

@ -1,3 +1,11 @@
2004-06-22 Alain Magloire
Part of PR 68246.
Close the inputstream to release resource handle
when we done with it, we can not rely on the GC to do it for us.
* index/org/eclipse/cdt/internal/core/search/indexing/SourceIndexer.java
2004-06-21 Andrew Niefer 2004-06-21 Andrew Niefer
enable reporting of semantic problems: enable reporting of semantic problems:
* index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java * index/org/eclipse/cdt/internal/core/search/indexing/IndexManager.java

View file

@ -16,6 +16,7 @@ package org.eclipse.cdt.internal.core.search.indexing;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
@ -99,15 +100,19 @@ public class SourceIndexer extends AbstractIndexer {
IParser parser = null; IParser parser = null;
try InputStream contents = null;
{ try {
CodeReader reader = new CodeReader(resourceFile.getLocation().toOSString(), resourceFile.getContents()); contents = resourceFile.getContents();
CodeReader reader = new CodeReader(resourceFile.getLocation().toOSString(), contents);
parser = ParserFactory.createParser( parser = ParserFactory.createParser(
ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getScannerLogService(), null ), ParserFactory.createScanner(reader, scanInfo, ParserMode.COMPLETE_PARSE, language, requestor, ParserUtil.getScannerLogService(), null ),
requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() ); requestor, ParserMode.COMPLETE_PARSE, language, ParserUtil.getParserLogService() );
} catch( ParserFactoryError pfe ) } catch( ParserFactoryError pfe ){
{
} catch (CoreException e) { } catch (CoreException e) {
} finally {
if (contents != null) {
contents.close();
}
} }
try{ try{

View file

@ -1,3 +1,11 @@
2004-06-22 Alain Magloire
Part of PR 68246.
Close the inputstream to release resource handle
when we done with it, we can not rely on the GC to do it for us.
* parser/org/eclipse/cdt/core/parser/CodeReader.java
2004-04-23 Andrew Niefer 2004-04-23 Andrew Niefer
- fixed up CompleteParseASTFactory.lookupQualifiedName in the case where the - fixed up CompleteParseASTFactory.lookupQualifiedName in the case where the
tokenDuple has 1 segement tokenDuple has 1 segement

View file

@ -47,7 +47,11 @@ public class CodeReader {
this.filename = filename; this.filename = filename;
FileInputStream stream = new FileInputStream(filename); FileInputStream stream = new FileInputStream(filename);
buffer = load(stream); try {
buffer = load(stream);
} finally {
stream.close();
}
} }
// If you have a handle on a stream to the file, e.g. IFile.getContents() // If you have a handle on a stream to the file, e.g. IFile.getContents()
@ -58,7 +62,15 @@ public class CodeReader {
(stream instanceof FileInputStream) (stream instanceof FileInputStream)
? (FileInputStream)stream ? (FileInputStream)stream
: new FileInputStream(filename); : new FileInputStream(filename);
buffer = load(fstream); try {
buffer = load(fstream);
} finally {
// If we create the FileInputStream we need close to it when done,
// if not we figure the above layer will do it.
if (!(stream instanceof FileInputStream)) {
fstream.close();
}
}
} }
private char[] load(FileInputStream stream) throws IOException { private char[] load(FileInputStream stream) throws IOException {

View file

@ -1,3 +1,10 @@
2004-06-22 Alain Magloire
Part of PR 68246.
Close the inputstream to release resource handle
when we done with it, we can not rely on the GC to do it for us.
* search/org/eclipse/cdt/internal/core/search/matching/MatchLocator.java
2004-06-21 Bogdan Gheorghe 2004-06-21 Bogdan Gheorghe
Modified JobManager to change state from waiting to enabled on a job request. Modified JobManager to change state from waiting to enabled on a job request.

View file

@ -14,6 +14,7 @@
package org.eclipse.cdt.internal.core.search.matching; package org.eclipse.cdt.internal.core.search.matching;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -405,11 +406,13 @@ public class MatchLocator implements IMatchLocator{
} else { } else {
currentResource = workspaceRoot.findMember( pathString, true ); currentResource = workspaceRoot.findMember( pathString, true );
InputStream contents = null;
try{ try{
if( currentResource != null ){ if( currentResource != null ){
if (currentResource.isAccessible() && currentResource instanceof IFile) { if (currentResource.isAccessible() && currentResource instanceof IFile) {
IFile file = (IFile) currentResource; IFile file = (IFile) currentResource;
reader = new CodeReader(currentResource.getLocation().toOSString(), file.getContents()); contents = file.getContents();
reader = new CodeReader(currentResource.getLocation().toOSString(), contents);
realPath = currentResource.getLocation(); realPath = currentResource.getLocation();
project = file.getProject(); project = file.getProject();
} else { } else {
@ -420,6 +423,14 @@ public class MatchLocator implements IMatchLocator{
continue; continue;
} catch ( IOException e ) { } catch ( IOException e ) {
continue; continue;
} finally {
if (contents != null) {
try {
contents.close();
} catch (IOException io) {
// ignore.
}
}
} }
} }
} }

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.model.IWorkingCopy;
@ -65,7 +66,17 @@ public class ParserUtil
if( buffer != null ) if( buffer != null )
return new CodeReader(finalPath, buffer); return new CodeReader(finalPath, buffer);
} }
return new CodeReader(finalPath, ((IFile)resultingResource).getContents()); InputStream in = null;
try
{
in = ((IFile)resultingResource).getContents();
return new CodeReader(finalPath, in);
} finally {
if (in != null)
{
in.close();
}
}
} }
} }
catch( CoreException ce ) catch( CoreException ce )