| java.lang.Object org.archive.crawler.util.LogReader
LogReader | public class LogReader (Code) | | This class contains a variety of methods for reading log files (or other text
files containing repeated lines with similar information).
All methods are static.
author: Kristinn Sigurdsson |
Method Summary | |
public static String | buildDisplayingHeader(int len, long logsize) | public static int | findFirstLineBeginning(InputStreamReader reader, String prefix) Return the line number of the first line in the
log/file that that begins with the given string.
Parameters: reader - The reader of the log/file Parameters: prefix - The prefix string to match The line number (counting from 1, not zero) of the first linethat matches the given regular expression. | public static int | findFirstLineBeginningFromSeries(String aFileName, String prefix) Return the line number of the first line in the
log/file that begins with the given string.
Parameters: aFileName - The filename of the log/file Parameters: prefix - The prefix string to match The line number (counting from 1, not zero) of the first linethat matches the given regular expression. | public static int | findFirstLineContaining(String aFileName, String regExpr) Return the line number of the first line in the
log/file that matches a given regular expression.
Parameters: aFileName - The filename of the log/file Parameters: regExpr - The regular expression that is to be used The line number (counting from 1, not zero) of the first linethat matches the given regular expression. | public static int | findFirstLineContaining(InputStreamReader reader, String regExpr) Return the line number of the first line in the
log/file that matches a given regular expression.
Parameters: reader - The reader of the log/file Parameters: regExpr - The regular expression that is to be used The line number (counting from 1, not zero) of the first linethat matches the given regular expression. | public static int | findFirstLineContainingFromSeries(String aFileName, String regExpr) Return the line number of the first line in the
log/file that matches a given regular expression.
Parameters: aFileName - The filename of the log/file Parameters: regExpr - The regular expression that is to be used The line number (counting from 1, not zero) of the first linethat matches the given regular expression. | public static String | get(String aFileName) Returns the entire file. | public static String | get(InputStreamReader reader) Reads entire contents of reader, returns as string. | public static String[] | get(String aFileName, int lineNumber, int n) Gets a portion of a log file. | public static String[] | get(InputStreamReader reader, int lineNumber, int n, long logsize) Gets a portion of a log file. | public static String[] | getByRegExpr(String aFileName, String regExpr, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches) Returns all lines in a log/file matching a given regular expression. | public static String[] | getByRegExpr(InputStreamReader reader, String regExpr, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches, long logsize) Returns all lines in a log/file matching a given regular expression. | public static String[] | getByRegExpr(String aFileName, String regExpr, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches) Returns all lines in a log/file matching a given regular expression. | public static String[] | getByRegExpr(InputStreamReader reader, String regExpr, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches, long logsize) Returns all lines in a log/file matching a given regular expression. | public static String[] | getByRegExprFromSeries(String aFileName, String regExpr, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches) Returns all lines in a log/file matching a given regular expression. | public static String[] | getByRegExprFromSeries(String aFileName, String regExpr, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches) Returns all lines in a log/file matching a given regular expression. | public static String[] | getFromSeries(String aFileName, int lineNumber, int n) Gets a portion of a log spread across a numbered series of files.
Starting at a given line number and the n-1 lines following that
one or until the end of the log if that is reached
first.
Parameters: aFileName - The filename of the log/file Parameters: lineNumber - The number of the first line to get (if larger then thefile an empty string will be returned) Parameters: n - How many lines to return (total, including the one indicated by lineNumber). | public static String[] | tail(String aFileName) Implementation of a unix-like 'tail' command
Parameters: aFileName - a file name String An array of two strings is returned. | public static String[] | tail(String aFileName, int n) Implementation of a unix-like 'tail -n' command
Parameters: aFileName - a file name String Parameters: n - int number of lines to be returned An array of two strings is returned. | public static String[] | tail(RandomAccessFile raf, int n) Implementation of a unix-like 'tail -n' command
Parameters: raf - a RandomAccessFile to tail Parameters: n - int number of lines to be returned An array of two strings is returned. |
buildDisplayingHeader | public static String buildDisplayingHeader(int len, long logsize)(Code) | | |
findFirstLineBeginning | public static int findFirstLineBeginning(InputStreamReader reader, String prefix)(Code) | | Return the line number of the first line in the
log/file that that begins with the given string.
Parameters: reader - The reader of the log/file Parameters: prefix - The prefix string to match The line number (counting from 1, not zero) of the first linethat matches the given regular expression. -1 is returned if noline matches the regular expression. -1 also is returned if errors occur (file not found, io exception etc.) |
findFirstLineBeginningFromSeries | public static int findFirstLineBeginningFromSeries(String aFileName, String prefix)(Code) | | Return the line number of the first line in the
log/file that begins with the given string.
Parameters: aFileName - The filename of the log/file Parameters: prefix - The prefix string to match The line number (counting from 1, not zero) of the first linethat matches the given regular expression. -1 is returned if noline matches the regular expression. -1 also is returned if errors occur (file not found, io exception etc.) |
findFirstLineContaining | public static int findFirstLineContaining(String aFileName, String regExpr)(Code) | | Return the line number of the first line in the
log/file that matches a given regular expression.
Parameters: aFileName - The filename of the log/file Parameters: regExpr - The regular expression that is to be used The line number (counting from 1, not zero) of the first linethat matches the given regular expression. -1 is returned if noline matches the regular expression. -1 also is returned if errors occur (file not found, io exception etc.) |
findFirstLineContaining | public static int findFirstLineContaining(InputStreamReader reader, String regExpr)(Code) | | Return the line number of the first line in the
log/file that matches a given regular expression.
Parameters: reader - The reader of the log/file Parameters: regExpr - The regular expression that is to be used The line number (counting from 1, not zero) of the first linethat matches the given regular expression. -1 is returned if noline matches the regular expression. -1 also is returned if errors occur (file not found, io exception etc.) |
findFirstLineContainingFromSeries | public static int findFirstLineContainingFromSeries(String aFileName, String regExpr)(Code) | | Return the line number of the first line in the
log/file that matches a given regular expression.
Parameters: aFileName - The filename of the log/file Parameters: regExpr - The regular expression that is to be used The line number (counting from 1, not zero) of the first linethat matches the given regular expression. -1 is returned if noline matches the regular expression. -1 also is returned if errors occur (file not found, io exception etc.) |
get | public static String get(String aFileName)(Code) | | Returns the entire file. Useful for smaller files.
Parameters: aFileName - a file name The String representation of the entire file.Null is returned if errors occur (file not found or io exception) |
get | public static String get(InputStreamReader reader)(Code) | | Reads entire contents of reader, returns as string.
Parameters: reader - String of entire contents; null for any error. |
get | public static String[] get(String aFileName, int lineNumber, int n)(Code) | | Gets a portion of a log file. Starting at a given line number and the n-1
lines following that one or until the end of the log if that is reached
first.
Parameters: aFileName - The filename of the log/file Parameters: lineNumber - The number of the first line to get (if larger then the file an empty string will be returned) Parameters: n - How many lines to return (total, including the one indicated by lineNumber). If smaller then 1 then an empty string will be returned. An array of two strings is returned. At index 0 a portion of thefile starting at lineNumber and reaching lineNumber+n is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception) |
get | public static String[] get(InputStreamReader reader, int lineNumber, int n, long logsize)(Code) | | Gets a portion of a log file. Starting at a given line number and the n-1
lines following that one or until the end of the log if that is reached
first.
Parameters: reader - source to scan for lines Parameters: lineNumber - The number of the first line to get (if larger then thefile an empty string will be returned) Parameters: n - How many lines to return (total, including the one indicated bylineNumber). If smaller then 1 then an empty stringwill be returned. Parameters: logsize - total size of source An array of two strings is returned. At index 0 a portion of thefile starting at lineNumber and reaching lineNumber+n is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception) |
getByRegExpr | public static String[] getByRegExpr(String aFileName, String regExpr, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches)(Code) | | Returns all lines in a log/file matching a given regular expression.
Possible to get lines immediately following the matched line. Also
possible to have each line prepended by it's line number.
Parameters: aFileName - The filename of the log/file Parameters: regExpr - The regular expression that is to be used Parameters: addLines - How many lines (in addition to the matched line) to add. A value less then 1 will mean that only the matched line will be included. If another matched line is hit before we reach this limit it will be included and this countereffectively reset for it. Parameters: prependLineNumbers - If true, then each line will be prepended by it's line number in the file. Parameters: skipFirstMatches - The first number of matches up to this value willbe skipped over. Parameters: numberOfMatches - Once past matches that are to be skipped this manymatches will be added to the return value. Avalue of 0 will cause all matching lines to beincluded. An array of two strings is returned. At index 0 tall lines in alog/file matching a given regular expression is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception)If a PatternSyntaxException occurs, it's error message will bereturned and the informational string will be empty (not null). |
getByRegExpr | public static String[] getByRegExpr(InputStreamReader reader, String regExpr, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches, long logsize)(Code) | | Returns all lines in a log/file matching a given regular expression.
Possible to get lines immediately following the matched line. Also
possible to have each line prepended by it's line number.
Parameters: reader - The reader of the log/file Parameters: regExpr - The regular expression that is to be used Parameters: addLines - How many lines (in addition to the matched line) to add. A value less then 1 will mean that only the matched line will be included. If another matched line is hit before we reach this limit it will be included and this countereffectively reset for it. Parameters: prependLineNumbers - If true, then each line will be prepended by it's line number in the file. Parameters: skipFirstMatches - The first number of matches up to this value willbe skipped over. Parameters: numberOfMatches - Once past matches that are to be skipped this manymatches will be added to the return value. Avalue of 0 will cause all matching lines to beincluded. Parameters: logsize - Size of the log in bytes An array of two strings is returned. At index 0 all lines in alog/file matching a given regular expression is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception)If a PatternSyntaxException occurs, it's error message will bereturned and the informational string will be empty (not null). |
getByRegExpr | public static String[] getByRegExpr(String aFileName, String regExpr, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches)(Code) | | Returns all lines in a log/file matching a given regular expression.
Possible to get lines immediately following the matched line. Also
possible to have each line prepended by it's line number.
Parameters: aFileName - The filename of the log/file Parameters: regExpr - The regular expression that is to be used Parameters: addLines - Any lines following a match that begin with this string will also be included. We will stop including new lines once we hit the first that does not match. Parameters: prependLineNumbers - If true, then each line will be prepended by it's line number in the file. Parameters: skipFirstMatches - The first number of matches up to this value willbe skipped over. Parameters: numberOfMatches - Once past matches that are to be skipped this manymatches will be added to the return value. Avalue of 0 will cause all matching lines to beincluded. An array of two strings is returned. At index 0 tall lines in alog/file matching a given regular expression is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception)If a PatternSyntaxException occurs, it's error message will bereturned and the informational string will be empty (not null). |
getByRegExpr | public static String[] getByRegExpr(InputStreamReader reader, String regExpr, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches, long logsize)(Code) | | Returns all lines in a log/file matching a given regular expression.
Possible to get lines immediately following the matched line. Also
possible to have each line prepended by it's line number.
Parameters: reader - The reader of the log/file Parameters: regExpr - The regular expression that is to be used Parameters: addLines - Any lines following a match that begin with this string will also be included. We will stop including new lines once we hit the first that does not match. Parameters: prependLineNumbers - If true, then each line will be prepended by it's line number in the file. Parameters: skipFirstMatches - The first number of matches up to this value willbe skipped over. Parameters: numberOfMatches - Once past matches that are to be skipped this manymatches will be added to the return value. Avalue of 0 will cause all matching lines to beincluded. Parameters: logsize - Size of the log in bytes An array of two strings is returned. At index 0 tall lines in alog/file matching a given regular expression is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception)If a PatternSyntaxException occurs, it's error message will bereturned and the informational string will be empty (not null). |
getByRegExprFromSeries | public static String[] getByRegExprFromSeries(String aFileName, String regExpr, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches)(Code) | | Returns all lines in a log/file matching a given regular expression.
Possible to get lines immediately following the matched line. Also
possible to have each line prepended by it's line number.
Parameters: aFileName - The filename of the log/file Parameters: regExpr - The regular expression that is to be used Parameters: addLines - How many lines (in addition to the matched line) to add. A value less then 1 will mean that only the matched line will be included. If another matched line is hit before we reach this limit it will be included and this countereffectively reset for it. Parameters: prependLineNumbers - If true, then each line will be prepended by it's line number in the file. Parameters: skipFirstMatches - The first number of matches up to this value willbe skipped over. Parameters: numberOfMatches - Once past matches that are to be skipped this manymatches will be added to the return value. Avalue of 0 will cause all matching lines to beincluded. An array of two strings is returned. At index 0 tall lines in alog/file matching a given regular expression is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception)If a PatternSyntaxException occurs, it's error message will bereturned and the informational string will be empty (not null). |
getByRegExprFromSeries | public static String[] getByRegExprFromSeries(String aFileName, String regExpr, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches)(Code) | | Returns all lines in a log/file matching a given regular expression.
Possible to get lines immediately following the matched line. Also
possible to have each line prepended by it's line number.
Parameters: aFileName - The filename of the log/file Parameters: regExpr - The regular expression that is to be used Parameters: addLines - Any lines following a match that begin with this string will also be included. We will stop including new lines once we hit the first that does not match. Parameters: prependLineNumbers - If true, then each line will be prepended by it's line number in the file. Parameters: skipFirstMatches - The first number of matches up to this value willbe skipped over. Parameters: numberOfMatches - Once past matches that are to be skipped this manymatches will be added to the return value. Avalue of 0 will cause all matching lines to beincluded. An array of two strings is returned. At index 0 tall lines in alog/file matching a given regular expression is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception)If a PatternSyntaxException occurs, it's error message will bereturned and the informational string will be empty (not null). |
getFromSeries | public static String[] getFromSeries(String aFileName, int lineNumber, int n)(Code) | | Gets a portion of a log spread across a numbered series of files.
Starting at a given line number and the n-1 lines following that
one or until the end of the log if that is reached
first.
Parameters: aFileName - The filename of the log/file Parameters: lineNumber - The number of the first line to get (if larger then thefile an empty string will be returned) Parameters: n - How many lines to return (total, including the one indicated by lineNumber). If smaller then 1 then an empty string will be returned. An array of two strings is returned. At index 0 a portion of thefile starting at lineNumber and reaching lineNumber+n is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception) |
tail | public static String[] tail(String aFileName)(Code) | | Implementation of a unix-like 'tail' command
Parameters: aFileName - a file name String An array of two strings is returned. At index 0 the Stringrepresentation of at most 10 last lines is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception) |
tail | public static String[] tail(String aFileName, int n)(Code) | | Implementation of a unix-like 'tail -n' command
Parameters: aFileName - a file name String Parameters: n - int number of lines to be returned An array of two strings is returned. At index 0 the Stringrepresentation of at most n last lines is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception) |
tail | public static String[] tail(RandomAccessFile raf, int n)(Code) | | Implementation of a unix-like 'tail -n' command
Parameters: raf - a RandomAccessFile to tail Parameters: n - int number of lines to be returned An array of two strings is returned. At index 0 the Stringrepresentation of at most n last lines is located.At index 1 there is an informational string about how large asegment of the file is being returned.Null is returned if errors occur (file not found or io exception) |
|
|