int lineCount = 0;
try {
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileChannel fc = raf.getChannel();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
CharBuffer cb = Charset.forName("US-ASCII").decode(bb); //todo: does Log4J use a different charset on a foreign PC?
Matcher target = null;
Matcher any = null;
Matcher lines = FULL_LINE_PATTERN.matcher(cb);
Matcher text = textSearch == null ? null : textSearch.matcher("");
boolean hit = false;
max = Math.min(max, MAX_SEARCH_RESULTS);
while(lines.find()) {
++lineCount;
if(target == null) {
if(DEFAULT_ANY_START.matcher(cb.subSequence(lines.start(), lines.end())).find()) {
target = getDefaultPatternForLevel(targetLevel).matcher("");
any = DEFAULT_ANY_START.matcher("");
} else {
target = getUnknownPatternForLevel(targetLevel).matcher("");
any = UNKNOWN_ANY_START.matcher("");
}
}
if(start != null && start.intValue() > lineCount) {
continue;
}
if(stop != null && stop.intValue() < lineCount) {
continue;
}
CharSequence line = cb.subSequence(lines.start(), lines.end());
target.reset(line);
if(target.find()) {
if(text != null) {
text.reset(line);
if(!text.find()) {