org.apache.lenya.search
Class Grep

java.lang.Object
  extended by org.apache.lenya.search.Grep

public class Grep
extends java.lang.Object

Utility class to provide a subset of the grep functionality.


Constructor Summary
Grep()
           
 
Method Summary
static boolean containsPattern(java.io.File file, java.util.regex.Pattern pattern)
          Check if the given file contains the pattern
static java.io.File[] find(java.io.File file, java.lang.String searchString)
          Find all files below the given file which contain the given search string.
static java.lang.String[] findPattern(java.io.File file, java.util.regex.Pattern pattern, int group)
          Find all occurences of pattern in a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grep

public Grep()
Method Detail

containsPattern

public static boolean containsPattern(java.io.File file,
                                      java.util.regex.Pattern pattern)
                               throws java.io.IOException
Check if the given file contains the pattern

Parameters:
file - the file which is to be searched for the pattern
pattern - the pattern that is being searched.
Returns:
true if the file contains the string, false otherwise.
Throws:
java.io.IOException

findPattern

public static java.lang.String[] findPattern(java.io.File file,
                                             java.util.regex.Pattern pattern,
                                             int group)
                                      throws java.io.IOException
Find all occurences of pattern in a file.

Parameters:
file - the file to search for occurences of pattern
pattern - the pattern to search for
group - which group in the pattern to return
Returns:
an array of occurences of pattern (i.e. the groupth group of the match)
Throws:
java.io.IOException - if the file could not be read.

find

public static java.io.File[] find(java.io.File file,
                                  java.lang.String searchString)
                           throws java.io.IOException
Find all files below the given file which contain the given search string.

Parameters:
file - the where to start the search
searchString - the string to search for.
Returns:
an array of files which contain the search string.
Throws:
java.io.IOException - if any of the files could not be opened.


Copyright 1999-2006 Apache Software Foundation. All Rights Reserved.