File: TestCompressionSpeed.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 (78 lines) | stat: -rwxr-xr-x 1,822 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package driver;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.zip.ZipOutputStream;

import fileIO.ReadWrite;
import fileIO.TextFile;
import shared.Timer;

public class TestCompressionSpeed {
	
	
	public static void main(String[] args){
		
		TextFile tf=new TextFile(args[0], false);
		String[] lines=tf.toStringLines();
		tf.close();

		Timer t=new Timer();
		
		for(int i=0; i<=9; i++){
			t.start();
			String fname=args[1].replaceFirst("#", ""+i);
			compress(lines, fname, i);
			t.stop();

			System.out.println("Level "+i+" compress:   "+t+"  \tsize:       "+new File(fname).length());
		}
		
		for(int i=0; i<=9; i++){
			t.start();
			String fname=args[1].replaceFirst("#", ""+i);
			String[] lines2=read(fname);
			assert(lines2.length>=lines.length);
			t.stop();
			
			System.out.println("Level "+i+" decompress: "+t);
		}
		
	}
	
	
	public static void compress(String[] text, String fname, int level){
		ReadWrite.ZIPLEVEL=level;
		OutputStream os=ReadWrite.getOutputStream(fname, false, true, true);
		PrintWriter writer=new PrintWriter(os);

		for(String s : text){writer.println(s);}
		for(String s : text){writer.println(s);}
		for(String s : text){writer.println(s);}
		for(String s : text){writer.println(s);}
		
		try {
			writer.flush();
			if(os.getClass()==ZipOutputStream.class){
				ZipOutputStream zos=(ZipOutputStream)os;
				zos.closeEntry();
				zos.finish();
			}
			writer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public static String[] read(String fname){
		TextFile tf=new TextFile(fname, false);
		String[] s=tf.toStringLines();
		tf.close();
		return s;
	}
	
}