mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-29 03:03:10 +02:00
[261644] [dstore] remote search improvements
-updating with changes that had gone into 3.0.3
This commit is contained in:
parent
26c3107d80
commit
8be739b9a0
1 changed files with 29 additions and 41 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2008 IBM Corporation and others.
|
* Copyright (c) 2006, 2009 IBM Corporation 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
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -30,10 +30,7 @@ import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.eclipse.dstore.core.model.DE;
|
import org.eclipse.dstore.core.model.DE;
|
||||||
import org.eclipse.dstore.core.model.DataElement;
|
import org.eclipse.dstore.core.model.DataElement;
|
||||||
|
@ -363,48 +360,39 @@ public class UniversalSearchHandler extends SecuredThread implements ICancellabl
|
||||||
long MAX_FILE = Runtime.getRuntime().freeMemory() / 4;
|
long MAX_FILE = Runtime.getRuntime().freeMemory() / 4;
|
||||||
long fileLength = theFile.length();
|
long fileLength = theFile.length();
|
||||||
|
|
||||||
//System.out.println("file="+absPath);
|
inputStream = new FileInputStream(theFile);
|
||||||
//System.out.println("MAX mem="+MAX_FILE);
|
InputStreamReader reader = new InputStreamReader(inputStream);
|
||||||
//System.out.println("fileLength="+fileLength);
|
BufferedReader bufReader = new BufferedReader(reader);
|
||||||
//if (fileLength < MAX_FILE)
|
|
||||||
if (true){ // if the file is too big, the server will run out of memory
|
// test for unreadable binary
|
||||||
inputStream = new FileInputStream(theFile);
|
if (isUnreadableBinary(bufReader) || fileLength > MAX_FILE){
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream);
|
// search some other way?
|
||||||
BufferedReader bufReader = new BufferedReader(reader);
|
long size = theFile.length();
|
||||||
|
if (simpleSearch(inputStream, size, _stringMatcher)){
|
||||||
// test for unreadable binary
|
|
||||||
if (isUnreadableBinary(bufReader) || fileLength > MAX_FILE){
|
|
||||||
// search some other way?
|
|
||||||
long size = theFile.length();
|
|
||||||
if (simpleSearch(inputStream, size, _stringMatcher)){
|
|
||||||
bufReader.close();
|
|
||||||
reader.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bufReader.close();
|
bufReader.close();
|
||||||
reader.close();
|
reader.close();
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
bufReader.close();
|
||||||
SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher);
|
reader.close();
|
||||||
|
|
||||||
SystemSearchLineMatch[] matches = locator.locateMatches();
|
|
||||||
boolean foundMatches = ((matches != null) && (matches.length > 0));
|
|
||||||
|
|
||||||
if (foundMatches) {
|
|
||||||
if (matches.length * 500 < MAX_FILE){ // only creating match objects if we have enough memory
|
|
||||||
convert(remoteFile, absPath, matches);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return foundMatches;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
_dataStore.trace("skipped:"+absPath + " due to memory constraints"); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, _stringMatcher);
|
||||||
|
|
||||||
|
SystemSearchLineMatch[] matches = locator.locateMatches();
|
||||||
|
boolean foundMatches = ((matches != null) && (matches.length > 0));
|
||||||
|
|
||||||
|
if (foundMatches) {
|
||||||
|
if (matches.length * 500 < MAX_FILE){ // only creating match objects if we have enough memory
|
||||||
|
convert(remoteFile, absPath, matches);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return foundMatches;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (OutOfMemoryError e){
|
catch (OutOfMemoryError e){
|
||||||
if (SystemServiceManager.getInstance().getSystemService() == null)
|
if (SystemServiceManager.getInstance().getSystemService() == null)
|
||||||
|
|
Loading…
Add table
Reference in a new issue