1- package org .biojava .nbio .core .util ;
2-
3- import org .junit .Test ;
4- import static org .junit .Assert .*;
5-
6- import java .io .ByteArrayOutputStream ;
7- import java .io .InputStream ;
8-
9- public class TestUncompressInputStream {
10-
11- /**
12- * The file compress_text.txt.lzc is the output of:
13- * <code>
14- * cat compress_test.txt | compress > compress_test.txt.lzc
15- * </code>
16- * The original compress_test.txt contains text {@value #TEXT_IN_FILE}
17- */
18- private static final String TEST_FILE = "org/biojava/nbio/core/util/compress_test.txt.lzc" ;
19- private static final String TEXT_IN_FILE = "Test of biojava uncompress." ;
20-
21- @ Test
22- public void testUncompression () throws Exception {
23-
24- InputStream is = this .getClass ().getClassLoader ().getResourceAsStream (TEST_FILE );
25-
26- ByteArrayOutputStream baos = new ByteArrayOutputStream ();
27- UncompressInputStream .uncompress (is , baos );
28- String decompressedText = baos .toString ();
29-
30- assertEquals (TEXT_IN_FILE , decompressedText );
31-
32- }
33-
34- }
1+ package org .biojava .nbio .core .util ;
2+
3+ import java .io .BufferedInputStream ;
4+ import org .junit .Test ;
5+ import static org .junit .Assert .*;
6+
7+ import java .io .ByteArrayOutputStream ;
8+ import java .io .InputStream ;
9+ import org .junit .Assert ;
10+
11+ public class TestUncompressInputStream {
12+
13+ /**
14+ * The file compress_text.txt.lzc is the output of:
15+ * <code>
16+ * cat compress_test.txt | compress > compress_test.txt.lzc
17+ * </code>
18+ * The original compress_test.txt contains text {@value #TEXT_IN_FILE}
19+ */
20+ private static final String TEST_FILE = "org/biojava/nbio/core/util/compress_test.txt.lzc" ;
21+ private static final String TEXT_IN_FILE = "Test of biojava uncompress.\n " ;
22+
23+ private static final String BIGGER_TEST_FILE = "org/biojava/nbio/core/util/build-copy.xml.Z" ;
24+ private static final String ORIG_OF_BIGGER_TEST_FILE = "org/biojava/nbio/core/util/build.xml" ;
25+
26+ @ Test
27+ public void testUncompression () throws Exception {
28+
29+ InputStream is = this .getClass ().getClassLoader ().getResourceAsStream (TEST_FILE );
30+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
31+ UncompressInputStream .uncompress (is , baos );
32+ String decompressedText = baos .toString ();
33+
34+ assertEquals (TEXT_IN_FILE , decompressedText );
35+
36+ is = this .getClass ().getClassLoader ().getResourceAsStream (BIGGER_TEST_FILE );
37+ baos = new ByteArrayOutputStream ();
38+ UncompressInputStream .uncompress (is , baos );
39+
40+ ByteArrayOutputStream obaos = new ByteArrayOutputStream ();
41+ try (BufferedInputStream oin = new BufferedInputStream (
42+ this .getClass ().getClassLoader ()
43+ .getResourceAsStream (ORIG_OF_BIGGER_TEST_FILE ));) {
44+ byte [] buf = new byte [100000 ];
45+ int len ;
46+ while ((len = oin .read (buf )) >= 0 )
47+ obaos .write (buf , 0 , len );
48+ }
49+
50+ Assert .assertArrayEquals (baos .toByteArray (), obaos .toByteArray ());
51+ }
52+ }
0 commit comments