1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.compress.archivers.tar;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertNull;
24
25 import java.util.Random;
26
27 import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
28 import org.junit.Test;
29
30 public class BigFilesIT {
31
32 @Test
33 public void readFileBiggerThan8GByteStar() throws Exception {
34 readFileBiggerThan8GByte("/8.star.tar.gz");
35 }
36
37 @Test
38 public void readFileBiggerThan8GBytePosix() throws Exception {
39 readFileBiggerThan8GByte("/8.posix.tar.gz");
40 }
41
42 private void readFileBiggerThan8GByte(String name) throws Exception {
43 GzipCompressorInputStream in = null;
44 TarArchiveInputStream tin = null;
45 try {
46 in =
47 new GzipCompressorInputStream(BigFilesIT.class
48 .getResourceAsStream(name));
49 tin = new TarArchiveInputStream(in);
50 TarArchiveEntry e = tin.getNextTarEntry();
51 assertNotNull(e);
52 assertEquals(8200l * 1024 * 1024, e.getSize());
53
54 long read = 0;
55 Random r = new Random(System.currentTimeMillis());
56 int readNow;
57 byte[] buf = new byte[1024 * 1024];
58 while ((readNow = tin.read(buf, 0, buf.length)) > 0) {
59
60
61 for (int i = 0; i < 100; i++) {
62 int idx = r.nextInt(readNow);
63 assertEquals("testing byte " + (read + idx), 0, buf[idx]);
64 }
65 read += readNow;
66 }
67 assertEquals(8200l * 1024 * 1024, read);
68 assertNull(tin.getNextTarEntry());
69 } finally {
70 if (tin != null) {
71 tin.close();
72 }
73 if (in != null) {
74 in.close();
75 }
76 }
77 }
78
79 }