1 package nom.tam.util.test;
4 import static org.junit.Assert.assertEquals;
5 import junit.framework.JUnit4TestAdapter;
7 import nom.tam.util.BufferedFile;
8 import nom.tam.util.BufferedDataInputStream;
9 import java.io.FileInputStream;
11 public class BigFileTest {
14 public void test() throws Exception {
16 // First create a 3 GB file.
17 String fname = System.getenv("BIGFILETEST");
19 System.out.println("BIGFILETEST environment not set. Returning without test");
22 System.out.println("Big file test. Takes quite a while.");
23 byte[] buf = new byte[100000000]; // 100 MB
24 BufferedFile bf = new BufferedFile(fname, "rw");
27 for (int i = 0; i < 30; i += 1) {
28 bf.write(buf); // 30 x 100 MB = 3 GB.
30 bf.write(new byte[]{sample});
35 // Now try to skip within the file.
36 bf = new BufferedFile(fname, "r");
37 long skip = 2500000000L; // 2.5 G
39 long val1 = bf.skipBytes(skip);
40 long val2 = bf.getFilePointer();
44 assertEquals("SkipResult", skip, val1);
45 assertEquals("SkipPos", skip, val2);
46 assertEquals("SkipVal", (int) sample, val);
48 BufferedDataInputStream bdis = new BufferedDataInputStream(
49 new FileInputStream(fname));
50 val1 = bdis.skipBytes(skip);
53 assertEquals("SSkipResult", skip, val1);
54 assertEquals("SSkipVal", (int) sample, val);
55 } catch (Exception e) {
56 e.printStackTrace(System.err);