1 package compbio.stat.collector;
\r
3 import java.io.BufferedReader;
\r
5 import java.io.FileReader;
\r
6 import java.io.IOException;
\r
8 import org.apache.log4j.Logger;
\r
10 import compbio.util.FileUtil;
\r
11 import compbio.util.Util;
\r
12 import compbio.ws.client.WSTester;
\r
14 public class InputFilter {
\r
16 private static final Logger log = Logger.getLogger(InputFilter.class);
\r
18 * Accepts input as valid unless it is a test input
\r
23 static boolean accept(File input) {
\r
26 assert input.isFile() : "Input file is not a file! " + input;
\r
27 String[] fastainput = WSTester.fastaInput2records.split("\n");
\r
28 assert fastainput.length == 4;
\r
29 String[] aligninput = WSTester.fastaAlignment.split("\n");
\r
30 assert aligninput.length == 4;
\r
31 // We do now know the type of the input here so must compare with both
\r
33 boolean isReference = compareLines(input, fastainput);
\r
35 isReference = compareLines(input, aligninput);
\r
37 // only accept genuine input
\r
38 return !isReference;
\r
41 private static boolean compareLines(File input, String[] reference) {
\r
42 BufferedReader reader = null;
\r
43 boolean status = true;
\r
45 reader = new BufferedReader(new FileReader(input));
\r
46 // only compare first four lines of the file with reference
\r
47 // because the reference length is only 4 lines
\r
48 for (int i = 0; i < 4; i++) {
\r
49 String line = reader.readLine();
\r
50 if (Util.isEmpty(line)) {
\r
55 if (!line.equals(reference[i].trim())) {
\r
61 } catch (IOException ioe) {
\r
62 log.warn(ioe, ioe.getCause());
\r
64 FileUtil.closeSilently(reader);
\r