If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Threaded View

Help: Parse a log file and split every log entry.

parse a log file and split it by individual log entry. The log entry can be a single line or multiple lines. In addition separate out the timestamp from the rest of the message.

- Must not load entire file in memory (stream)
- Must capture the entire entry (single and multiple lines)
- Must split the entry also in two parts, timestamp and the rest of the entry
- Must use a regular expression to parse
- Must be configurable to parse log files in slightly different formats

1. if I use below to read log file, is it correct to meet the requirement (- Must not load entire file in memory (stream))?
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
// process the line.
}
br.close();

2. can I save timestamp and the rest of the entry to a HashMap<String, ArrayList<String>>? and key is the timestamp, the rest of entry is saved to ArrayList?
but if the log file is big, the HashMap should be very big, maybe it is not a good way.

3. how can I save the result? Can I save the result to a new log file (every entry has a number)?

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.