[task] Txt transformation

Description

txtt is text transformer task that allow to:

Txtt task parameters

Attribute Description Value Required
file input file .txt file or fileset
tofile output file . tofile or todir
todir output dir no
template freemarker template .ftl yes (or inner template)
overwrite overwrite output file true by default no
ouputproperty output property no
extension output extension (with fileset + todir) no
Element Description Value Required
fileset fileset element no
template inner template element no
parameter custom param value <parameter name=”” value=”"/> no
foreach foreach element no

Usages

Use cases

file2file set2set set2file file2set
txtt grep format java
todo logs (syslog + mysql => res) ?

Usecase

List files or dirs

<bj:txtt tofile="tmp/res.txt” overwrite="true">

        </template>
        <dirset dir="gen">
            <include name="*aaa*"/>
        </dirset>
    </bj:txtt>

Examples

Parse each line of a file and write a specific Java parser.

result.txt

  • input file (result of command: time my.bin)
Command being timed: "./my.bin"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 0%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 1124
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 339
Voluntary context switches: 1
Involuntary context switches: 1
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0

build.xml

  • ant file:
<project name="bidji-txtt" xmlns:bj="antlib:org.bidji.taskdefs">
<target name="txt2java" description=" transform txt to java">		
	<bj:txtt file="result.txt" tofile="parser.java" template="txt2java.ftl" overwrite="true"/>
</target>
</project>

txt2java.ftl

  • freemarker file
// copy this function to your java code
public void parseLines(List<String> lines) {
    for (String line : lines) {        
        switch (line.substring(0,line.indexOf(":")-1)) {
            <#foreach line in lines>
            case "BJDOLLAR{line?substring(0,line?index_of(':'))?replace('(','\\\\(')}":
                // TODO
                break;
            </#foreach>
            default:
                throw new Exception("Fail to parse line " + line);
        }
    }    
}

parser.java

  • output file
// copy this function to your java code
public void parseLines(List<String> lines) {
    for (String line : lines) {
        switch (line.substring(0,line.indexOf(":")-1)) {
            case "Command being timed":
                // TODO
                break;
            case "User time \\(seconds)":
                // TODO
                break;
            case "System time \\(seconds)":
                // TODO
                break;
            case "Percent of CPU this job got":
                // TODO
                break;
            case "Elapsed \\(wall clock) time \\(h":
                // TODO
                break;
            case "Average shared text size \\(kbytes)":
                // TODO
                break;
            case "Average unshared data size \\(kbytes)":
                // TODO
                break;
            case "Average stack size \\(kbytes)":
                // TODO
                break;
            case "Average total size \\(kbytes)":
                // TODO
                break;
            case "Maximum resident set size \\(kbytes)":
                // TODO
                break;
            case "Average resident set size \\(kbytes)":
                // TODO
                break;
            case "Major \\(requiring I/O) page faults":
                // TODO
                break;
            case "Minor \\(reclaiming a frame) page faults":
                // TODO
                break;
            case "Voluntary context switches":
                // TODO
                break;
            case "Involuntary context switches":
                // TODO
                break;
            case "Swaps":
                // TODO
                break;
            case "File system inputs":
                // TODO
                break;
            case "File system outputs":
                // TODO
                break;
            case "Socket messages sent":
                // TODO
                break;
            case "Socket messages received":
                // TODO
                break;
            case "Signals delivered":
                // TODO
                break;
            case "Page size \\(bytes)":
                // TODO
                break;
            case "Exit status":
                // TODO
                break;
            default:
                throw new Exception("Fail to parse line " + line);
        }
    }
}