File: Concatenator.java

package info (click to toggle)
bbmap 39.20%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,024 kB
  • sloc: java: 312,743; sh: 18,099; python: 5,247; ansic: 2,074; perl: 96; makefile: 39; xml: 38
file content (60 lines) | stat: -rwxr-xr-x 1,304 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package driver;

import fileIO.TextFile;
import fileIO.TextStreamWriter;

public class Concatenator {
	
	
	public static void main(String args[]){
		
		assert(args.length==2 && !args[1].contains(","));
		TextStreamWriter tsw=new TextStreamWriter(args[1], false, false, true);
		tsw.start();
		for(String s : args[0].split(",")){
			writeFile(s, tsw);
		}
		tsw.poison();
	}
	
	public static void writeFile(String fname, TextStreamWriter tsw){
		TextFile tf=new TextFile(fname, false);
		if(tsw==null){
			for(String s=tf.nextLine(); s!=null; s=tf.nextLine()){
				System.out.println(s);
			}
		}else{
			for(String s=tf.nextLine(); s!=null; s=tf.nextLine()){
				tsw.println(s);
			}
		}
		tf.close();
	}
	
	
	public static StringBuilder merge(String[] fnames){
		StringBuilder sb=new StringBuilder();
		
		for(int i=0; i<fnames.length; i++){
			String fname=fnames[i];
			if(fname!=null){
				TextFile tf=new TextFile(fname, false);
				String[] lines=tf.toStringLines();
				tf.close();
				for(int j=0; j<lines.length; j++){
					String s=lines[j];
					lines[j]=null;
//					if(i<2 || !s.startsWith("#")){
//						sb.append(s);
//						sb.append('\n');
//					}
					sb.append(s);
					sb.append('\n');
				}
			}
		}
		return sb;
	}
	
	
}