]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.example/src/main/java/org/argeo/slc/example/appli/ExampleAppli.java
Various fixes so that SLC example works again
[gpl/argeo-slc.git] / org.argeo.slc.example / src / main / java / org / argeo / slc / example / appli / ExampleAppli.java
1 package org.argeo.slc.example.appli;
2
3 import java.io.BufferedReader;
4 import java.io.FileReader;
5 import java.io.FileWriter;
6 import java.io.IOException;
7
8 /** Example appli. */
9 public class ExampleAppli {
10 private int skipFreq = 2;
11
12 /** Filters. */
13 public void filter(String[] args) {
14 if (args.length < 2) {
15 throw new RuntimeException(
16 "Not enough arguments. Usage: <inpuit file> <output file>");
17 }
18 String input = args[0];
19 String output = args[1];
20 if (args.length > 2) {
21 skipFreq = Integer.parseInt(args[2]);
22 }
23
24 try {
25 BufferedReader in = new BufferedReader(new FileReader(input));
26 FileWriter out = new FileWriter(output);
27 int count = 0;
28 String line;
29 while ((line = in.readLine()) != null) {
30 if (count % skipFreq != 0) {
31 out.write(line);
32 out.write("\n");
33 }
34 count++;
35 }
36 out.close();
37 in.close();
38 } catch (IOException e) {
39 throw new RuntimeException("Appli failed", e);
40 }
41 }
42
43 /** Sets the frequency of the lines to skip. */
44 public void setSkipFreq(int skipFreq) {
45 this.skipFreq = skipFreq;
46 }
47
48 }