~ubuntu-branches/debian/stretch/libcommons-compress-java/stretch

« back to all changes in this revision

Viewing changes to src/test/java/org/apache/commons/compress/compressors/LZMATestCase.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2015-08-31 23:22:38 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20150831232238-gz3ynyvs68tok1a3
Tags: 1.10-1
* New upstream release
* Updated the OSGi metadata

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
package org.apache.commons.compress.compressors;
20
20
 
 
21
import java.io.BufferedInputStream;
21
22
import java.io.File;
22
23
import java.io.FileInputStream;
23
24
import java.io.FileOutputStream;
 
25
import java.io.IOException;
24
26
import java.io.InputStream;
25
27
 
26
28
import org.apache.commons.compress.AbstractTestCase;
27
29
import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream;
28
30
import org.apache.commons.compress.utils.IOUtils;
 
31
import org.junit.Test;
29
32
 
30
33
public final class LZMATestCase extends AbstractTestCase {
31
34
 
 
35
    @Test
32
36
    public void testLZMAUnarchive() throws Exception {
33
37
        final File input = getFile("bla.tar.lzma");
34
38
        final File output = new File(dir, "bla.tar");
35
39
        final InputStream is = new FileInputStream(input);
36
40
        try {
37
41
            final CompressorInputStream in = new LZMACompressorInputStream(is);
38
 
            FileOutputStream out = null;
39
 
            try {
40
 
                out = new FileOutputStream(output);
41
 
                IOUtils.copy(in, out);
42
 
            } finally {
43
 
                if (out != null) {
44
 
                    out.close();
45
 
                }
46
 
                in.close();
 
42
            copy(in, output);
 
43
        } finally {
 
44
            is.close();
 
45
        }
 
46
    }
 
47
 
 
48
    @Test
 
49
    public void testLZMAUnarchiveWithAutodetection() throws Exception {
 
50
        final File input = getFile("bla.tar.lzma");
 
51
        final File output = new File(dir, "bla.tar");
 
52
        final InputStream is = new BufferedInputStream(new FileInputStream(input));
 
53
        try {
 
54
            final CompressorInputStream in = new CompressorStreamFactory()
 
55
                .createCompressorInputStream(is);
 
56
            copy(in, output);
 
57
        } finally {
 
58
            is.close();
 
59
        }
 
60
    }
 
61
 
 
62
    private void copy(InputStream in, File output) throws IOException {
 
63
        FileOutputStream out = null;
 
64
        try {
 
65
            out = new FileOutputStream(output);
 
66
            IOUtils.copy(in, out);
 
67
        } finally {
 
68
            if (out != null) {
 
69
                out.close();
47
70
            }
48
 
        } finally {
49
 
            is.close();
 
71
            in.close();
50
72
        }
51
73
    }
52
74
}