public class LogReader extends Object
All methods are static.
Constructor and Description |
---|
LogReader() |
Modifier and Type | Method and Description |
---|---|
static String |
buildDisplayingHeader(int len,
long logsize) |
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.
|
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.
|
static int |
findFirstLineContaining(InputStreamReader reader,
String regex)
Return the line number of the first line in the
log/file that matches a given regular expression.
|
static int |
findFirstLineContaining(String aFileName,
String regex)
Return the line number of the first line in the
log/file that matches a given regular expression.
|
static int |
findFirstLineContainingFromSeries(String aFileName,
String regex)
Return the line number of the first line in the
log/file that matches a given regular expression.
|
static String |
get(InputStreamReader reader)
Reads entire contents of reader, returns as string.
|
static String[] |
get(InputStreamReader reader,
int lineNumber,
int n,
long logsize)
Gets a portion of a log file.
|
static String |
get(String aFileName)
Returns the entire file.
|
static String[] |
get(String aFileName,
int lineNumber,
int n)
Gets a portion of a log file.
|
static String[] |
getByRegex(InputStreamReader reader,
String regex,
int addLines,
boolean prependLineNumbers,
int skipFirstMatches,
int numberOfMatches,
long logsize)
Returns all lines in a log/file matching a given regular expression.
|
static String[] |
getByRegex(InputStreamReader reader,
String regex,
String addLines,
boolean prependLineNumbers,
int skipFirstMatches,
int numberOfMatches,
long logsize)
Returns all lines in a log/file matching a given regular expression.
|
static String[] |
getByRegex(String aFileName,
String regex,
int addLines,
boolean prependLineNumbers,
int skipFirstMatches,
int numberOfMatches)
Returns all lines in a log/file matching a given regular expression.
|
static String[] |
getByRegex(String aFileName,
String regex,
String addLines,
boolean prependLineNumbers,
int skipFirstMatches,
int numberOfMatches)
Returns all lines in a log/file matching a given regular expression.
|
static String[] |
getByRegexFromSeries(String aFileName,
String regex,
int addLines,
boolean prependLineNumbers,
int skipFirstMatches,
int numberOfMatches)
Returns all lines in a log/file matching a given regular expression.
|
static String[] |
getByRegexFromSeries(String aFileName,
String regex,
String addLines,
boolean prependLineNumbers,
int skipFirstMatches,
int numberOfMatches)
Returns all lines in a log/file matching a given regular expression.
|
static String[] |
getFromSeries(String aFileName,
int lineNumber,
int n)
Gets a portion of a log spread across a numbered series of files.
|
static String[] |
tail(RandomAccessFile raf,
int n)
Implementation of a unix-like 'tail -n' command
|
static String[] |
tail(String aFileName)
Implementation of a unix-like 'tail' command
|
static String[] |
tail(String aFileName,
int n)
Implementation of a unix-like 'tail -n' command
|
public static String get(String aFileName)
aFileName
- a file namepublic static String get(InputStreamReader reader)
reader
- public static String[] get(String aFileName, int lineNumber, int n)
aFileName
- The filename of the log/filelineNumber
- The number of the first line to get (if larger then the
file an empty string will be returned)n
- How many lines to return (total, including the one indicated by
lineNumber). If smaller then 1 then an empty string
will be returned.public static String[] getFromSeries(String aFileName, int lineNumber, int n)
aFileName
- The filename of the log/filelineNumber
- The number of the first line to get (if larger then the
file an empty string will be returned)n
- How many lines to return (total, including the one indicated by
lineNumber). If smaller then 1 then an empty string
will be returned.public static String buildDisplayingHeader(int len, long logsize)
public static String[] get(InputStreamReader reader, int lineNumber, int n, long logsize)
reader
- source to scan for lineslineNumber
- The number of the first line to get (if larger then the
file an empty string will be returned)n
- How many lines to return (total, including the one indicated by
lineNumber). If smaller then 1 then an empty string
will be returned.logsize
- total size of sourcepublic static int findFirstLineContaining(String aFileName, String regex)
aFileName
- The filename of the log/fileregex
- The regular expression that is to be usedpublic static int findFirstLineBeginningFromSeries(String aFileName, String prefix)
aFileName
- The filename of the log/fileprefix
- The prefix string to matchpublic static int findFirstLineBeginning(InputStreamReader reader, String prefix)
reader
- The reader of the log/fileprefix
- The prefix string to matchpublic static int findFirstLineContainingFromSeries(String aFileName, String regex)
aFileName
- The filename of the log/fileregex
- The regular expression that is to be usedpublic static int findFirstLineContaining(InputStreamReader reader, String regex)
reader
- The reader of the log/fileregex
- The regular expression that is to be usedpublic static String[] getByRegex(String aFileName, String regex, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches)
aFileName
- The filename of the log/fileregex
- The regular expression that is to be usedaddLines
- 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 counter
effectively reset for it.prependLineNumbers
- If true, then each line will be prepended by
it's line number in the file.skipFirstMatches
- The first number of matches up to this value will
be skipped over.numberOfMatches
- Once past matches that are to be skipped this many
matches will be added to the return value. A
value of 0 will cause all matching lines to be
included.public static String[] getByRegexFromSeries(String aFileName, String regex, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches)
aFileName
- The filename of the log/fileregex
- The regular expression that is to be usedaddLines
- 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 counter
effectively reset for it.prependLineNumbers
- If true, then each line will be prepended by
it's line number in the file.skipFirstMatches
- The first number of matches up to this value will
be skipped over.numberOfMatches
- Once past matches that are to be skipped this many
matches will be added to the return value. A
value of 0 will cause all matching lines to be
included.public static String[] getByRegex(InputStreamReader reader, String regex, int addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches, long logsize)
reader
- The reader of the log/fileregex
- The regular expression that is to be usedaddLines
- 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 counter
effectively reset for it.prependLineNumbers
- If true, then each line will be prepended by
it's line number in the file.skipFirstMatches
- The first number of matches up to this value will
be skipped over.numberOfMatches
- Once past matches that are to be skipped this many
matches will be added to the return value. A
value of 0 will cause all matching lines to be
included.logsize
- Size of the log in bytespublic static String[] getByRegex(String aFileName, String regex, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches)
aFileName
- The filename of the log/fileregex
- The regular expression that is to be usedaddLines
- 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.prependLineNumbers
- If true, then each line will be prepended by
it's line number in the file.skipFirstMatches
- The first number of matches up to this value will
be skipped over.numberOfMatches
- Once past matches that are to be skipped this many
matches will be added to the return value. A
value of 0 will cause all matching lines to be
included.public static String[] getByRegexFromSeries(String aFileName, String regex, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches)
aFileName
- The filename of the log/fileregex
- The regular expression that is to be usedaddLines
- 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.prependLineNumbers
- If true, then each line will be prepended by
it's line number in the file.skipFirstMatches
- The first number of matches up to this value will
be skipped over.numberOfMatches
- Once past matches that are to be skipped this many
matches will be added to the return value. A
value of 0 will cause all matching lines to be
included.public static String[] getByRegex(InputStreamReader reader, String regex, String addLines, boolean prependLineNumbers, int skipFirstMatches, int numberOfMatches, long logsize)
reader
- The reader of the log/fileregex
- The regular expression that is to be usedaddLines
- 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.prependLineNumbers
- If true, then each line will be prepended by
it's line number in the file.skipFirstMatches
- The first number of matches up to this value will
be skipped over.numberOfMatches
- Once past matches that are to be skipped this many
matches will be added to the return value. A
value of 0 will cause all matching lines to be
included.logsize
- Size of the log in bytespublic static String[] tail(String aFileName)
aFileName
- a file name Stringpublic static String[] tail(String aFileName, int n)
aFileName
- a file name Stringn
- int number of lines to be returnedpublic static String[] tail(RandomAccessFile raf, int n)
raf
- a RandomAccessFile to tailn
- int number of lines to be returnedCopyright © 2003-2014 Internet Archive. All Rights Reserved.