aboutsummaryrefslogtreecommitdiff
path: root/src/org/tukaani/xz/CloseIgnoringInputStream.java
blob: c29f268c64d65795e8045985921de71ca124fbcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * CloseIgnoringInputStream
 *
 * Author: Lasse Collin <lasse.collin@tukaani.org>
 *
 * This file has been put into the public domain.
 * You can do whatever you want with this file.
 */

package org.tukaani.xz;

import java.io.InputStream;
import java.io.FilterInputStream;

/**
 * An {@code InputStream} wrapper whose {@code close()} does nothing.
 * This is useful with raw decompressors if you want to call
 * {@code close()} to release memory allocated from an {@link ArrayCache}
 * but don't want to close the underlying {@code InputStream}.
 * For example:
 * <blockquote><pre>
 * InputStream rawdec = new LZMA2InputStream(
 *         new CloseIgnoringInputStream(myInputStream),
 *         myDictSize, null, myArrayCache);
 * doSomething(rawdec);
 * rawdec.close(); // This doesn't close myInputStream.
 * </pre></blockquote>
 * <p>
 * With {@link XZInputStream}, {@link SingleXZInputStream}, and
 * {@link SeekableXZInputStream} you can use their {@code close(boolean)}
 * method to avoid closing the underlying {@code InputStream}; with
 * those classes {@code CloseIgnoringInputStream} isn't needed.
 *
 * @since 1.7
 */
public class CloseIgnoringInputStream extends FilterInputStream {
    /**
     * Creates a new {@code CloseIgnoringInputStream}.
     */
    public CloseIgnoringInputStream(InputStream in) {
        super(in);
    }

    /**
     * This does nothing (doesn't call {@code in.close()}).
     */
    public void close() {}
}