java2.util2.zip2.ZipOutputStream: 77.10%
Overview
Search Parameters
- plot: false
- chromosome_length: 40
- static_hack: false
- tournament_size: 10
- max_int: 2048
- string_length: 20
- crossover_rate: 0.75
- max_attempts: 1000
- CP: build/classes
- check_parents_length: true
- PREFIX: java2.util2.zip2
- stopping_condition: MaxStatements
- max_recursion: 10
- primitive_pool: 0.5
- selection_function: Rank
- generations: 200000
- primitive_reuse_probability: 0.5
- test_excludes: test.excludes
- bloat_factor: 2
- object_reuse_probability: 0.9
- minimize: false
- html: true
- null_probability: 0.1
- strategy: EvoSuite
- elite: 1
- check_best_length: true
- num_tests: 2
- PROJECT_PREFIX: java2.util2.zip2
- OUTPUT_DIR: evosuite-files
- algorithm: SteadyStateGA
- string_replacement: true
- crossover_function: SinglePointRelative
- report_dir: evosuite-report
- test_includes: test.includes
- output_dir: evosuite-files
- criterion: branch
- rank_bias: 1.7
- timeout: 5000
- population: 100
- test_dir: evosuite-tests
- max_size: 100
- check_max_length: true
- TARGET_CLASS: java2.util2.zip2.ZipOutputStream
- check_rank_length: true
- max_length: 5000
- make_accessible: true
EvoSuite Parameters
- plot: false
- chromosome_length: 40
- static_hack: false
- tournament_size: 10
- max_int: 2048
- string_length: 20
- crossover_rate: 0.75
- max_attempts: 1000
- CP: build/classes
- check_parents_length: true
- PREFIX: java2.util2.zip2
- stopping_condition: MaxStatements
- max_recursion: 10
- primitive_pool: 0.5
- selection_function: Rank
- generations: 200000
- primitive_reuse_probability: 0.5
- test_excludes: test.excludes
- bloat_factor: 2
- object_reuse_probability: 0.9
- minimize: false
- html: true
- null_probability: 0.1
- strategy: EvoSuite
- elite: 1
- check_best_length: true
- num_tests: 2
- PROJECT_PREFIX: java2.util2.zip2
- OUTPUT_DIR: evosuite-files
- algorithm: SteadyStateGA
- string_replacement: true
- crossover_function: SinglePointRelative
- report_dir: evosuite-report
- test_includes: test.includes
- output_dir: evosuite-files
- criterion: branch
- rank_bias: 1.7
- timeout: 5000
- population: 100
- test_dir: evosuite-tests
- max_size: 100
- check_max_length: true
- TARGET_CLASS: java2.util2.zip2.ZipOutputStream
- check_rank_length: true
- max_length: 5000
- make_accessible: true
Old Parameters
- Algorithm: SteadyStateGA
- Population size: 100
- Initial test length: 40
- Stopping condition: MaxStatements: null
- Bloat control factor: 2
- Random seed: 0
Statistics
- Start time: 2010-10-18 17:49:59
- End time: 2010-10-18 17:50:13
- Fitness evaluations: 13370
- Tests executed: 7836
- Statements executed: 200036
- Generations: 134
- Number of tests before minimization: 11
- Number of tests after minimization: 11
- Length of tests before minimization: 293
- Length of tests after minimization: 293
- Total predicates: 55
- Total branches: 110
- Covered branches: 80
- Total methods: 21
- Covered methods: 21
- Methods without branches: 7
- Total coverage goal: 131
- Covered goals: 101
- Time for search: 0:00:13
- Time for minimization: 0:00:00
- Total time: 0:00:13
Test suite
Test case 1
1: String var0 = "q5\u0016\u001F&\u001E";;
2: ByteArrayOutputStream var1 = new java.io.ByteArrayOutputStream();;
3: ZipOutputStream var2 = new java2.util2.zip2.ZipOutputStream(var1);;
4: String var3 = "ZIP file comment too long.";;
5: byte[] var4 = new byte[0];;
6: int var5 = -1045;;
7: var2.setComment(var3);
8: ;
9: byte[] var7 = new byte[4];;
10: byte var8 = -32;;
11: var7[0] = var8;;
12: var2.setComment(var3);
13: ;
14: ZipEntry var11 = new java2.util2.zip2.ZipEntry(var0);;
15: var11.setExtra(var7);
16: ;
17: try {
18: var2.write(var4, var5, var7[2]);
19: } catch(IndexOutOfBoundsException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
20: var2.setComment(var3);
21: ;
22: var11.setExtra(var4);
23: ;
24: try {
25: var2.putNextEntry(var11);
26: }
27: catch(IOException e) {} // Declared exception;
28: try {
29: var2.flush();
30: }
31: catch(IOException e) {} // Declared exception;
32: var7[1] = var7[1];;
33: try {
34: var2.write(var7);
35: }
36: catch(IOException e) {} // Declared exception;
37: Deflater var20 = var2.def;;
38: DeflaterOutputStream var21 = new java2.util2.zip2.DeflaterOutputStream(var1, var20);;
39: var7[2] = var7[0];;
40: var2.setComment(var0);
41: ;
42: try {
43: var2.putNextEntry((ZipEntry) null);
44: } catch(NullPointerException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
45: try {
46: var2.finish();
47: }
48: catch(IOException e) {} // Declared exception;
49: try {
50: var2.putNextEntry(var11);
51: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
52: try {
53: var2.close();
54: }
55: catch(IOException e) {} // Declared exception;
56: try {
57: var2.write(var7, var7[0], var8);
58: } catch(IOException e) {} // Raised exception
Test case 2
1: int var0 = 21;;
2: ByteArrayOutputStream var1 = new java.io.ByteArrayOutputStream(var0);;
3: ZipOutputStream var2 = new java2.util2.zip2.ZipOutputStream(var1);;
4: int var3 = 809;;
5: try {
6: var2.setLevel(var3);
7: } catch(IllegalArgumentException e) {} // Raised exception
8: ZipOutputStream var5 = new java2.util2.zip2.ZipOutputStream(var1);;
9: Deflater var6 = new java.util.zip.Deflater();;
10: try {
11: var1.writeTo(var5);
12: }
13: catch(IOException e) {} // Declared exception;
14: try {
15: var2.finish();
16: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
17: DeflaterOutputStream var9 = new java2.util2.zip2.DeflaterOutputStream(var2, var6);;
18: ZipOutputStream var10 = new java2.util2.zip2.ZipOutputStream(var9);;
19: try {
20: var10.flush();
21: }
22: catch(IOException e) {} // Declared exception;
Test case 3
1: ByteArrayOutputStream var0 = new java.io.ByteArrayOutputStream();;
2: int var1 = 522;;
3: ZipOutputStream var2 = new java2.util2.zip2.ZipOutputStream(var0);;
4: String var3 = null;
5: var3 = var0.toString(var1);
6: ;
7: try {
8: var0.close();
9: }
10: catch(IOException e) {} // Declared exception;
11: try {
12: var2.write(var1);
13: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
14: String var6 = null;
15: var6 = var0.toString(var1);
16: ;
17: int var7 = null;
18: var7 = var0.size();
19: ;
20: int var8 = 25;;
21: ZipEntry var9 = new java2.util2.zip2.ZipEntry(var3);;
22: try {
23: var2.putNextEntry(var9);
24: }
25: catch(IOException e) {} // Declared exception;
26: int var11 = null;
27: var11 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var6);
28: ;
29: var9.setComment(var3);
30: ;
31: try {
32: var9.setMethod(var8);
33: } catch(IllegalArgumentException e) {} // Raised exception
34: try {
35: var2.close();
36: }
37: catch(IOException e) {} // Declared exception;
38: try {
39: var2.flush();
40: }
41: catch(IOException e) {} // Declared exception;
Test case 4
1: ByteArrayOutputStream var0 = new java.io.ByteArrayOutputStream();;
2: byte[] var1 = new byte[15];;
3: var1[0] = var1[11];;
4: var1[1] = var1[11];;
5: var1[2] = var1[11];;
6: var1[3] = var1[9];;
7: var1[4] = var1[8];;
8: var1[5] = var1[2];;
9: var1[6] = var1[10];;
10: var1[7] = var1[3];;
11: var1[8] = var1[4];;
12: var1[9] = var1[13];;
13: var1[10] = var1[13];;
14: var1[11] = var1[12];;
15: var1[12] = var1[3];;
16: var1[13] = var1[10];;
17: var1[14] = var1[10];;
18: try {
19: var0.write(var1);
20: }
21: catch(IOException e) {} // Declared exception;
22: byte[] var18 = null;
23: var18 = var0.toByteArray();
24: ;
25: int var19 = 522;;
26: ZipOutputStream var20 = new java2.util2.zip2.ZipOutputStream(var0);;
27: String var21 = null;
28: var21 = var0.toString(var19);
29: ;
30: try {
31: var20.write(var18);
32: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
33: try {
34: var20.close();
35: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
36: try {
37: var20.write(var18);
38: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
39: var0.write(var19);
40: ;
41: try {
42: var20.setLevel(var19);
43: } catch(IllegalArgumentException e) {} // Raised exception
44: String var27 = null;
45: var27 = var0.toString(var19);
46: ;
47: int var28 = null;
48: var28 = var0.size();
49: ;
50: int var29 = 25;;
51: ZipEntry var30 = new java2.util2.zip2.ZipEntry(var21);;
52: try {
53: var20.putNextEntry(var30);
54: }
55: catch(IOException e) {} // Declared exception;
56: int var32 = null;
57: var32 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var27);
58: ;
59: try {
60: var20.close();
61: }
62: catch(IOException e) {} // Declared exception;
63: try {
64: var30.setMethod(var29);
65: } catch(IllegalArgumentException e) {} // Raised exception
66: try {
67: var20.close();
68: }
69: catch(IOException e) {} // Declared exception;
70: try {
71: var20.flush();
72: }
73: catch(IOException e) {} // Declared exception;
Test case 5
1: ByteArrayOutputStream var0 = new java.io.ByteArrayOutputStream();;
2: ZipOutputStream var1 = new java2.util2.zip2.ZipOutputStream(var0);;
3: String var2 = "";;
4: String var3 = "+%ON9eqda\u0001h84WIpwq";;
5: var1.setComment(var3);
6: ;
7: try {
8: var1.close();
9: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
10: ZipOutputStream var6 = new java2.util2.zip2.ZipOutputStream(var1);;
11: byte[] var7 = new byte[7];;
12: var7[0] = var7[2];;
13: try {
14: var1.write(var7, var7[3], var7[0]);
15: }
16: catch(IOException e) {} // Declared exception;
17: var7[3] = var7[2];;
18: var7[4] = var7[4];;
19: var7[5] = var7[6];;
20: try {
21: var1.closeEntry();
22: }
23: catch(IOException e) {} // Declared exception;
24: try {
25: var1.write(var7);
26: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
27: byte[] var15 = new byte[12];;
28: var15[1] = var15[0];;
29: var15[2] = var15[11];;
30: var15[3] = var15[6];;
31: var15[4] = var15[5];;
32: var15[5] = var15[11];;
33: try {
34: var1.flush();
35: }
36: catch(IOException e) {} // Declared exception;
37: try {
38: var6.close();
39: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
40: ZipEntry var23 = new java2.util2.zip2.ZipEntry(var3);;
41: try {
42: var6.putNextEntry(var23);
43: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
44: var15[6] = var15[10];;
45: var15[7] = var15[3];;
46: var15[8] = var15[9];;
47: var15[9] = var15[2];;
48: int var29 = -548;;
49: try {
50: var6.write(var15, var15[10], var29);
51: } catch(IndexOutOfBoundsException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
Test case 6
1: int var0 = 12;;
2: ByteArrayOutputStream var1 = new java.io.ByteArrayOutputStream(var0);;
3: String var2 = "\bp\"=l}mj\u001Eh?WO\n\u0015";;
4: String var3 = null;
5: try {
6: var3 = var1.toString(var2);
7: } catch(UnsupportedEncodingException e) {} // Raised exception
8: ZipOutputStream var4 = new java2.util2.zip2.ZipOutputStream(var1);;
9: try {
10: var4.close();
11: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
12: boolean var6 = false;;
13: try {
14: var4.setLevel(var0);
15: } catch(IllegalArgumentException e) {} // Raised exception
16: ZipEntry var8 = null;
17: try {
18: var8 = new java2.util2.zip2.ZipEntry(var0);
19: } catch(UnsatisfiedLinkError e) {}
20: try {
21: var4.putNextEntry(var8);
22: } catch(NullPointerException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
23: byte[] var10 = new byte[7];;
24: var10[0] = var10[0];;
25: var10[1] = var10[5];;
26: var10[2] = var10[2];;
27: try {
28: var4.write(var10[5]);
29: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
30: var10[3] = var10[6];;
31: try {
32: var4.write(var10, var0, var10[0]);
33: } catch(IndexOutOfBoundsException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
34: var10[4] = var10[3];;
35: var10[5] = var10[4];;
36: byte var19 = 39;;
37: var10[6] = var19;;
38: try {
39: var4.write(var10, var10[4], var10[1]);
40: }
41: catch(IOException e) {} // Declared exception;
42: byte[] var22 = null;
43: var22 = var1.toByteArray();
44: ;
45: var4.setMethod(var10[2]);
46: ;
47: var4.setComment(var3);
48: ;
49: Deflater var25 = null;
50: try {
51: var25 = new java.util.zip.Deflater(var0, var6);
52: } catch(IllegalArgumentException e) {}
53: DeflaterOutputStream var26 = null;
54: try {
55: var26 = new java2.util2.zip2.DeflaterOutputStream(var4, var25);
56: } catch(NullPointerException e) {}
57: try {
58: var25.finish();
59: } catch(NullPointerException e) {} // Raised exception
60: try {
61: var4.write(var10[0]);
62: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
63: DeflaterOutputStream var29 = null;
64: try {
65: var29 = new java2.util2.zip2.DeflaterOutputStream(var1, var25, var0);
66: } catch(NullPointerException e) {}
67: DeflaterOutputStream var30 = null;
68: try {
69: var30 = new java2.util2.zip2.DeflaterOutputStream(var29, var25, var0);
70: } catch(NullPointerException e) {}
71: try {
72: var4.write(var10, var10[5], var10[4]);
73: }
74: catch(IOException e) {} // Declared exception;
Test case 7
1: int var0 = 8;;
2: ByteArrayOutputStream var1 = new java.io.ByteArrayOutputStream(var0);;
3: ZipOutputStream var2 = new java2.util2.zip2.ZipOutputStream(var1);;
4: String var3 = "</test>";;
5: int var4 = null;
6: var4 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var3);
7: ;
8: Deflater var5 = var2.def;;
9: DeflaterOutputStream var6 = new java2.util2.zip2.DeflaterOutputStream(var2, var5, var0);;
10: DeflaterOutputStream var7 = new java2.util2.zip2.DeflaterOutputStream(var6, var5, var0);;
11: int var8 = null;
12: var8 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var3);
13: ;
14: DeflaterOutputStream var9 = new java2.util2.zip2.DeflaterOutputStream(var2, var5, var0);;
15: byte[] var10 = new byte[7];;
16: var10[0] = var10[2];;
17: var2.setLevel(var10[3]);
18: ;
19: var10[1] = var10[5];;
20: byte var14 = 64;;
21: var10[2] = var14;;
22: var10[3] = var10[4];;
23: DeflaterOutputStream var17 = null;
24: try {
25: var17 = new java2.util2.zip2.DeflaterOutputStream(var9, var5, var10[5]);
26: } catch(IllegalArgumentException e) {}
27: try {
28: var9.write(var10[2]);
29: }
30: catch(IOException e) {} // Declared exception;
31: var10[4] = var10[3];;
32: var10[5] = var10[1];;
33: var10[6] = var10[5];;
34: try {
35: var2.write(var10, var10[6], var10[0]);
36: }
37: catch(IOException e) {} // Declared exception;
38: ZipOutputStream var23 = new java2.util2.zip2.ZipOutputStream(var1);;
39: ZipOutputStream var24 = new java2.util2.zip2.ZipOutputStream(var9);;
40: var2.setComment(var3);
41: ;
42: var24.setMethod(var10[0]);
43: ;
44: String var27 = "?\u000FPe1P&<n[l\u000F-HU\u00133x";;
45: ZipEntry var28 = new java2.util2.zip2.ZipEntry(var27);;
46: ZipEntry var29 = new java2.util2.zip2.ZipEntry(var28);;
47: try {
48: var24.putNextEntry(var29);
49: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
50: try {
51: var6.flush();
52: }
53: catch(IOException e) {} // Declared exception;
54: int var32 = null;
55: var32 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var27);
56: ;
57: var24.setMethod(var0);
58: ;
Test case 8
1: ByteArrayOutputStream var0 = new java.io.ByteArrayOutputStream();;
2: Deflater var1 = new java.util.zip.Deflater();;
3: int var2 = 6;;
4: DeflaterOutputStream var3 = new java2.util2.zip2.DeflaterOutputStream(var0, var1, var2);;
5: int var4 = 1598;;
6: ByteArrayOutputStream var5 = new java.io.ByteArrayOutputStream(var4);;
7: DeflaterOutputStream var6 = new java2.util2.zip2.DeflaterOutputStream(var5, var1);;
8: var0.write(var4);
9: ;
10: String var8 = null;
11: var8 = var0.toString(var4);
12: ;
13: DeflaterOutputStream var9 = new java2.util2.zip2.DeflaterOutputStream(var0, var1);;
14: DeflaterOutputStream var10 = new java2.util2.zip2.DeflaterOutputStream(var9, var1);;
15: DeflaterOutputStream var11 = new java2.util2.zip2.DeflaterOutputStream(var9, var1);;
16: int var12 = null;
17: var12 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var8);
18: ;
19: ZipOutputStream var13 = new java2.util2.zip2.ZipOutputStream(var9);;
20: ZipOutputStream var14 = new java2.util2.zip2.ZipOutputStream(var0);;
21: byte[] var15 = new byte[11];;
22: var15[1] = var15[8];;
23: var15[2] = var15[10];;
24: var15[3] = var15[5];;
25: var15[4] = var15[4];;
26: var15[5] = var15[5];;
27: var15[6] = var15[6];;
28: try {
29: var14.closeEntry();
30: }
31: catch(IOException e) {} // Declared exception;
32: byte var23 = -90;;
33: var15[8] = var15[0];;
34: var15[9] = var15[0];;
35: var15[10] = var15[1];;
36: try {
37: var13.write(var15);
38: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
39: try {
40: var14.close();
41: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
42: try {
43: var6.write(var15[0]);
44: }
45: catch(IOException e) {} // Declared exception;
46: try {
47: var11.write(var2);
48: }
49: catch(IOException e) {} // Declared exception;
50: try {
51: var9.write(var2);
52: }
53: catch(IOException e) {} // Declared exception;
Test case 9
1: int var0 = 8;;
2: ByteArrayOutputStream var1 = new java.io.ByteArrayOutputStream(var0);;
3: ZipOutputStream var2 = new java2.util2.zip2.ZipOutputStream(var1);;
4: String var3 = "</test>";;
5: int var4 = null;
6: var4 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var3);
7: ;
8: Deflater var5 = var2.def;;
9: DeflaterOutputStream var6 = new java2.util2.zip2.DeflaterOutputStream(var2, var5, var0);;
10: int var7 = null;
11: var7 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var3);
12: ;
13: DeflaterOutputStream var8 = new java2.util2.zip2.DeflaterOutputStream(var2, var5, var0);;
14: byte[] var9 = new byte[7];;
15: var9[0] = var9[2];;
16: try {
17: var2.write(var9, var9[5], var9[1]);
18: }
19: catch(IOException e) {} // Declared exception;
20: var9[1] = var9[5];;
21: byte var13 = 64;;
22: var9[2] = var13;;
23: var9[3] = var9[4];;
24: DeflaterOutputStream var16 = null;
25: try {
26: var16 = new java2.util2.zip2.DeflaterOutputStream(var8, var5, var9[5]);
27: } catch(IllegalArgumentException e) {}
28: try {
29: var8.write(var9[2]);
30: }
31: catch(IOException e) {} // Declared exception;
32: var9[4] = var9[3];;
33: var9[5] = var9[1];;
34: var9[6] = var9[5];;
35: try {
36: var2.write(var9, var9[6], var9[0]);
37: }
38: catch(IOException e) {} // Declared exception;
39: ZipOutputStream var22 = new java2.util2.zip2.ZipOutputStream(var1);;
40: ZipOutputStream var23 = new java2.util2.zip2.ZipOutputStream(var8);;
41: var2.setComment(var3);
42: ;
43: var23.setMethod(var9[0]);
44: ;
45: String var26 = "?\u000FPe1P&<n[l\u000F-HU\u00133x";;
46: ZipEntry var27 = new java2.util2.zip2.ZipEntry(var26);;
47: ZipEntry var28 = new java2.util2.zip2.ZipEntry(var27);;
48: ZipEntry var29 = new java2.util2.zip2.ZipEntry(var28);;
49: try {
50: var23.putNextEntry(var29);
51: } catch(ZipException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
52: try {
53: var2.flush();
54: }
55: catch(IOException e) {} // Declared exception;
56: int var32 = null;
57: var32 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var26);
58: ;
59: var23.setMethod(var0);
60: ;
Test case 10
1: int var0 = 11;;
2: ByteArrayOutputStream var1 = new java.io.ByteArrayOutputStream(var0);;
3: ByteArrayOutputStream var2 = new java.io.ByteArrayOutputStream(var0);;
4: ZipOutputStream var3 = new java2.util2.zip2.ZipOutputStream(var2);;
5: String var4 = "attempt to write past end of STORED entry";;
6: var3.setComment(var4);
7: ;
8: ZipEntry var6 = new java2.util2.zip2.ZipEntry(var4);;
9: try {
10: var3.putNextEntry(var6);
11: }
12: catch(IOException e) {} // Declared exception;
13: DeflaterOutputStream var8 = new java2.util2.zip2.DeflaterOutputStream(var1);;
14: try {
15: var3.finish();
16: }
17: catch(IOException e) {} // Declared exception;
18: ByteArrayOutputStream var10 = new java.io.ByteArrayOutputStream(var0);;
19: ZipOutputStream var11 = new java2.util2.zip2.ZipOutputStream(var1);;
20: ZipOutputStream var12 = new java2.util2.zip2.ZipOutputStream(var10);;
21: Deflater var13 = null;
22: try {
23: var13 = new java.util.zip.Deflater(var0);
24: } catch(IllegalArgumentException e) {}
25: try {
26: var12.putNextEntry(var6);
27: }
28: catch(IOException e) {} // Declared exception;
29: DeflaterOutputStream var15 = null;
30: try {
31: var15 = new java2.util2.zip2.DeflaterOutputStream(var12, var13);
32: } catch(NullPointerException e) {}
33: try {
34: var15.flush();
35: } catch(NullPointerException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
36: ZipOutputStream var17 = new java2.util2.zip2.ZipOutputStream(var1);;
Test case 11
1: ByteArrayOutputStream var0 = new java.io.ByteArrayOutputStream();;
2: int var1 = 1355;;
3: var0.write(var1);
4: ;
5: int var3 = -332;;
6: String var4 = null;
7: var4 = var0.toString(var3);
8: ;
9: DeflaterOutputStream var5 = new java2.util2.zip2.DeflaterOutputStream(var0);;
10: Deflater var6 = var5.def;;
11: int var7 = null;
12: var7 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var4);
13: ;
14: DeflaterOutputStream var8 = null;
15: try {
16: var8 = new java2.util2.zip2.DeflaterOutputStream((OutputStream) null, var6);
17: } catch(NullPointerException e) {}
18: int var9 = 192;;
19: try {
20: var8.write(var9);
21: } catch(NullPointerException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
22: int var11 = null;
23: var11 = java2.util2.zip2.ZipOutputStream.getUTF8Length(var4);
24: ;
25: ZipOutputStream var12 = new java2.util2.zip2.ZipOutputStream(var0);;
26: ZipEntry var13 = new java2.util2.zip2.ZipEntry(var4);;
27: ZipEntry var14 = new java2.util2.zip2.ZipEntry(var13);;
28: try {
29: var12.putNextEntry(var14);
30: }
31: catch(IOException e) {} // Declared exception;
32: try {
33: var12.setMethod(var11);
34: } catch(IllegalArgumentException e) {} // Raised exception
35: try {
36: var8.deflate();
37: } catch(NullPointerException e) {} // Raised exceptioncatch(IOException e) {} // Declared exception
Source Code
1: /*
2: * @(#)ZipOutputStream.java 1.36 10/03/23
3: *
4: * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
5: * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6: */
7:
8: package java2.util2.zip2;
9:
10: import java.io.OutputStream;
11: import java.io.IOException;
12: import java.util.Vector;
13: import java.util.HashSet;
14:
15: import java.util.zip.ZipException;
16: import java.util.zip.Deflater;
17: import java.util.zip.CRC32;
18:
19: /**
20: * This class implements an output stream filter for writing files in the
21: * ZIP file format. Includes support for both compressed and uncompressed
22: * entries.
23: *
24: * @author David Connelly
25: * @version 1.36, 03/23/10
26: */
27: public
28: class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
29:
30: private static class XEntry {
31: public final ZipEntry entry;
32: public final long offset;
33: public final int flag;
34: public XEntry(ZipEntry entry, long offset) {
35: this.entry = entry;
36: this.offset = offset;
37: this.flag = (entry.method == DEFLATED &&
38: (entry.size == -1 ||
39: entry.csize == -1 ||
40: entry.crc == -1))
41: // store size, compressed size, and crc-32 in data descriptor
42: // immediately following the compressed entry data
43: ? 8
44: // store size, compressed size, and crc-32 in LOC header
45: : 0;
46: }
47: }
48:
49: private XEntry current;
50: private Vector<XEntry> xentries = new Vector<XEntry>();
51: private HashSet<String> names = new HashSet<String>();
52: private CRC32 crc = new CRC32();
53: private long written = 0;
54: private long locoff = 0;
55: private String comment;
56: private int method = DEFLATED;
57: private boolean finished;
58:
59: private boolean closed = false;
60:
61: private static int version(ZipEntry e) throws ZipException {
62: switch (e.method) {
63: case DEFLATED: return 20;
64: case STORED: return 10;
65: default: throw new ZipException("unsupported compression method");
66: }
67: }
68:
69: /**
70: * Checks to make sure that this stream has not been closed.
71: */
72: private void ensureOpen() throws IOException {
73: if (closed) {
74: throw new IOException("Stream closed");
75: }
76: }
77: /**
78: * Compression method for uncompressed (STORED) entries.
79: */
80: public static final int STORED = ZipEntry.STORED;
81:
82: /**
83: * Compression method for compressed (DEFLATED) entries.
84: */
85: public static final int DEFLATED = ZipEntry.DEFLATED;
86:
87: /**
88: * Creates a new ZIP output stream.
89: * @param out the actual output stream
90: */
91: public ZipOutputStream(OutputStream out) {
92: super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
93: usesDefaultDeflater = true;
94: }
95:
96: /**
97: * Sets the ZIP file comment.
98: * @param comment the comment string
99: * @exception IllegalArgumentException if the length of the specified
100: * ZIP file comment is greater than 0xFFFF bytes
101: */
102: public void setComment(String comment) {
103: if (comment != null && comment.length() > 0xffff/3
104: && getUTF8Length(comment) > 0xffff) {
105: throw new IllegalArgumentException("ZIP file comment too long.");
106: }
107: this.comment = comment;
108: }
109:
110: /**
111: * Sets the default compression method for subsequent entries. This
112: * default will be used whenever the compression method is not specified
113: * for an individual ZIP file entry, and is initially set to DEFLATED.
114: * @param method the default compression method
115: * @exception IllegalArgumentException if the specified compression method
116: * is invalid
117: */
118: public void setMethod(int method) {
119: if (method != DEFLATED && method != STORED) {
120: throw new IllegalArgumentException("invalid compression method");
121: }
122: this.method = method;
123: }
124:
125: /**
126: * Sets the compression level for subsequent entries which are DEFLATED.
127: * The default setting is DEFAULT_COMPRESSION.
128: * @param level the compression level (0-9)
129: * @exception IllegalArgumentException if the compression level is invalid
130: */
131: public void setLevel(int level) {
132: def.setLevel(level);
133: }
134:
135: /**
136: * Begins writing a new ZIP file entry and positions the stream to the
137: * start of the entry data. Closes the current entry if still active.
138: * The default compression method will be used if no compression method
139: * was specified for the entry, and the current time will be used if
140: * the entry has no set modification time.
141: * @param e the ZIP entry to be written
142: * @exception ZipException if a ZIP format error has occurred
143: * @exception IOException if an I/O error has occurred
144: */
145: public void putNextEntry(ZipEntry e) throws IOException {
146: ensureOpen();
147: if (current != null) {
148: closeEntry(); // close previous entry
149: }
150: if (e.time == -1) {
151: e.setTime(System.currentTimeMillis());
152: }
153: if (e.method == -1) {
154: e.method = method; // use default method
155: }
156: switch (e.method) {
157: case DEFLATED:
158: break;
159: case STORED:
160: // compressed size, uncompressed size, and crc-32 must all be
161: // set for entries using STORED compression method
162: if (e.size == -1) {
163: e.size = e.csize;
164: } else if (e.csize == -1) {
165: e.csize = e.size;
166: } else if (e.size != e.csize) {
167: throw new ZipException(
168: "STORED entry where compressed != uncompressed size");
169: }
170: if (e.size == -1 || e.crc == -1) {
171: throw new ZipException(
172: "STORED entry missing size, compressed size, or crc-32");
173: }
174: break;
175: default:
176: throw new ZipException("unsupported compression method");
177: }
178: if (! names.add(e.name)) {
179: throw new ZipException("duplicate entry: " + e.name);
180: }
181: current = new XEntry(e, written);
182: xentries.add(current);
183: writeLOC(current);
184: }
185:
186: /**
187: * Closes the current ZIP entry and positions the stream for writing
188: * the next entry.
189: * @exception ZipException if a ZIP format error has occurred
190: * @exception IOException if an I/O error has occurred
191: */
192: public void closeEntry() throws IOException {
193: ensureOpen();
194: if (current != null) {
195: ZipEntry e = current.entry;
196: switch (e.method) {
197: case DEFLATED:
198: def.finish();
199: while (!def.finished()) {
200: deflate();
201: }
202: if ((current.flag & 8) == 0) {
203: // verify size, compressed size, and crc-32 settings
204: if (e.size != def.getBytesRead()) {
205: throw new ZipException(
206: "invalid entry size (expected " + e.size +
207: " but got " + def.getBytesRead() + " bytes)");
208: }
209: if (e.csize != def.getBytesWritten()) {
210: throw new ZipException(
211: "invalid entry compressed size (expected " +
212: e.csize + " but got " + def.getBytesWritten() + " bytes)");
213: }
214: if (e.crc != crc.getValue()) {
215: throw new ZipException(
216: "invalid entry CRC-32 (expected 0x" +
217: Long.toHexString(e.crc) + " but got 0x" +
218: Long.toHexString(crc.getValue()) + ")");
219: }
220: } else {
221: e.size = def.getBytesRead();
222: e.csize = def.getBytesWritten();
223: e.crc = crc.getValue();
224: writeEXT(e);
225: }
226: def.reset();
227: written += e.csize;
228: break;
229: case STORED:
230: // we already know that both e.size and e.csize are the same
231: if (e.size != written - locoff) {
232: throw new ZipException(
233: "invalid entry size (expected " + e.size +
234: " but got " + (written - locoff) + " bytes)");
235: }
236: if (e.crc != crc.getValue()) {
237: throw new ZipException(
238: "invalid entry crc-32 (expected 0x" +
239: Long.toHexString(e.crc) + " but got 0x" +
240: Long.toHexString(crc.getValue()) + ")");
241: }
242: break;
243: default:
244: throw new ZipException("invalid compression method");
245: }
246: crc.reset();
247: current = null;
248: }
249: }
250:
251: /**
252: * Writes an array of bytes to the current ZIP entry data. This method
253: * will block until all the bytes are written.
254: * @param b the data to be written
255: * @param off the start offset in the data
256: * @param len the number of bytes that are written
257: * @exception ZipException if a ZIP file error has occurred
258: * @exception IOException if an I/O error has occurred
259: */
260: public synchronized void write(byte[] b, int off, int len)
261: throws IOException
262: {
263: ensureOpen();
264: if (off < 0 || len < 0 || off > b.length - len) {
265: throw new IndexOutOfBoundsException();
266: } else if (len == 0) {
267: return;
268: }
269:
270: if (current == null) {
271: throw new ZipException("no current ZIP entry");
272: }
273: ZipEntry entry = current.entry;
274: switch (entry.method) {
275: case DEFLATED:
276: super.write(b, off, len);
277: break;
278: case STORED:
279: written += len;
280: if (written - locoff > entry.size) {
281: throw new ZipException(
282: "attempt to write past end of STORED entry");
283: }
284: out.write(b, off, len);
285: break;
286: default:
287: throw new ZipException("invalid compression method");
288: }
289: crc.update(b, off, len);
290: }
291:
292: /**
293: * Finishes writing the contents of the ZIP output stream without closing
294: * the underlying stream. Use this method when applying multiple filters
295: * in succession to the same output stream.
296: * @exception ZipException if a ZIP file error has occurred
297: * @exception IOException if an I/O exception has occurred
298: */
299: public void finish() throws IOException {
300: ensureOpen();
301: if (finished) {
302: return;
303: }
304: if (current != null) {
305: closeEntry();
306: }
307: if (xentries.size() < 1) {
308: throw new ZipException("ZIP file must have at least one entry");
309: }
310: // write central directory
311: long off = written;
312: for (XEntry xentry : xentries)
313: writeCEN(xentry);
314: writeEND(off, written - off);
315: finished = true;
316: }
317:
318: /**
319: * Closes the ZIP output stream as well as the stream being filtered.
320: * @exception ZipException if a ZIP file error has occurred
321: * @exception IOException if an I/O error has occurred
322: */
323: public void close() throws IOException {
324: if (!closed) {
325: super.close();
326: closed = true;
327: }
328: }
329:
330: /*
331: * Writes local file (LOC) header for specified entry.
332: */
333: private void writeLOC(XEntry xentry) throws IOException {
334: ZipEntry e = xentry.entry;
335: int flag = xentry.flag;
336: writeInt(LOCSIG); // LOC header signature
337: writeShort(version(e)); // version needed to extract
338: writeShort(flag); // general purpose bit flag
339: writeShort(e.method); // compression method
340: writeInt(e.time); // last modification time
341: if ((flag & 8) == 8) {
342: // store size, uncompressed size, and crc-32 in data descriptor
343: // immediately following compressed entry data
344: writeInt(0);
345: writeInt(0);
346: writeInt(0);
347: } else {
348: writeInt(e.crc); // crc-32
349: writeInt(e.csize); // compressed size
350: writeInt(e.size); // uncompressed size
351: }
352: byte[] nameBytes = getUTF8Bytes(e.name);
353: writeShort(nameBytes.length);
354: writeShort(e.extra != null ? e.extra.length : 0);
355: writeBytes(nameBytes, 0, nameBytes.length);
356: if (e.extra != null) {
357: writeBytes(e.extra, 0, e.extra.length);
358: }
359: locoff = written;
360: }
361:
362: /*
363: * Writes extra data descriptor (EXT) for specified entry.
364: */
365: private void writeEXT(ZipEntry e) throws IOException {
366: writeInt(EXTSIG); // EXT header signature
367: writeInt(e.crc); // crc-32
368: writeInt(e.csize); // compressed size
369: writeInt(e.size); // uncompressed size
370: }
371:
372: /*
373: * Write central directory (CEN) header for specified entry.
374: * REMIND: add support for file attributes
375: */
376: private void writeCEN(XEntry xentry) throws IOException {
377: ZipEntry e = xentry.entry;
378: int flag = xentry.flag;
379: int version = version(e);
380: writeInt(CENSIG); // CEN header signature
381: writeShort(version); // version made by
382: writeShort(version); // version needed to extract
383: writeShort(flag); // general purpose bit flag
384: writeShort(e.method); // compression method
385: writeInt(e.time); // last modification time
386: writeInt(e.crc); // crc-32
387: writeInt(e.csize); // compressed size
388: writeInt(e.size); // uncompressed size
389: byte[] nameBytes = getUTF8Bytes(e.name);
390: writeShort(nameBytes.length);
391: writeShort(e.extra != null ? e.extra.length : 0);
392: byte[] commentBytes;
393: if (e.comment != null) {
394: commentBytes = getUTF8Bytes(e.comment);
395: writeShort(commentBytes.length);
396: } else {
397: commentBytes = null;
398: writeShort(0);
399: }
400: writeShort(0); // starting disk number
401: writeShort(0); // internal file attributes (unused)
402: writeInt(0); // external file attributes (unused)
403: writeInt(xentry.offset); // relative offset of local header
404: writeBytes(nameBytes, 0, nameBytes.length);
405: if (e.extra != null) {
406: writeBytes(e.extra, 0, e.extra.length);
407: }
408: if (commentBytes != null) {
409: writeBytes(commentBytes, 0, commentBytes.length);
410: }
411: }
412:
413: /*
414: * Writes end of central directory (END) header.
415: */
416: private void writeEND(long off, long len) throws IOException {
417: int count = xentries.size();
418: writeInt(ENDSIG); // END record signature
419: writeShort(0); // number of this disk
420: writeShort(0); // central directory start disk
421: writeShort(count); // number of directory entries on disk
422: writeShort(count); // total number of directory entries
423: writeInt(len); // length of central directory
424: writeInt(off); // offset of central directory
425: if (comment != null) { // zip file comment
426: byte[] b = getUTF8Bytes(comment);
427: writeShort(b.length);
428: writeBytes(b, 0, b.length);
429: } else {
430: writeShort(0);
431: }
432: }
433:
434: /*
435: * Writes a 16-bit short to the output stream in little-endian byte order.
436: */
437: private void writeShort(int v) throws IOException {
438: OutputStream out = this.out;
439: out.write((v >>> 0) & 0xff);
440: out.write((v >>> 8) & 0xff);
441: written += 2;
442: }
443:
444: /*
445: * Writes a 32-bit int to the output stream in little-endian byte order.
446: */
447: private void writeInt(long v) throws IOException {
448: OutputStream out = this.out;
449: out.write((int)((v >>> 0) & 0xff));
450: out.write((int)((v >>> 8) & 0xff));
451: out.write((int)((v >>> 16) & 0xff));
452: out.write((int)((v >>> 24) & 0xff));
453: written += 4;
454: }
455:
456: /*
457: * Writes an array of bytes to the output stream.
458: */
459: private void writeBytes(byte[] b, int off, int len) throws IOException {
460: super.out.write(b, off, len);
461: written += len;
462: }
463:
464: /*
465: * Returns the length of String's UTF8 encoding.
466: */
467: static int getUTF8Length(String s) {
468: int count = 0;
469: for (int i = 0; i < s.length(); i++) {
470: char ch = s.charAt(i);
471: if (ch <= 0x7f) {
472: count++;
473: } else if (ch <= 0x7ff) {
474: count += 2;
475: } else {
476: count += 3;
477: }
478: }
479: return count;
480: }
481:
482: /*
483: * Returns an array of bytes representing the UTF8 encoding
484: * of the specified String.
485: */
486: private static byte[] getUTF8Bytes(String s) {
487: char[] c = s.toCharArray();
488: int len = c.length;
489: // Count the number of encoded bytes...
490: int count = 0;
491: for (int i = 0; i < len; i++) {
492: int ch = c[i];
493: if (ch <= 0x7f) {
494: count++;
495: } else if (ch <= 0x7ff) {
496: count += 2;
497: } else {
498: count += 3;
499: }
500: }
501: // Now return the encoded bytes...
502: byte[] b = new byte[count];
503: int off = 0;
504: for (int i = 0; i < len; i++) {
505: int ch = c[i];
506: if (ch <= 0x7f) {
507: b[off++] = (byte)ch;
508: } else if (ch <= 0x7ff) {
509: b[off++] = (byte)((ch >> 6) | 0xc0);
510: b[off++] = (byte)((ch & 0x3f) | 0x80);
511: } else {
512: b[off++] = (byte)((ch >> 12) | 0xe0);
513: b[off++] = (byte)(((ch >> 6) & 0x3f) | 0x80);
514: b[off++] = (byte)((ch & 0x3f) | 0x80);
515: }
516: }
517: return b;
518: }
519: }