| 1 | // SPDX-License-Identifier: 0BSD |
| 2 | // SPDX-FileCopyrightText: The XZ for Java authors and contributors |
| 3 | // SPDX-FileContributor: Lasse Collin <[email protected]> |
| 4 | |
| 5 | package org.tukaani.xz; |
| 6 | |
| 7 | import java.io.InputStream; |
| 8 | import java.io.FilterInputStream; |
| 9 | |
| 10 | /** |
| 11 | * An {@code InputStream} wrapper whose {@code close()} does nothing. |
| 12 | * This is useful with raw decompressors if you want to call |
| 13 | * {@code close()} to release memory allocated from an {@link ArrayCache} |
| 14 | * but don't want to close the underlying {@code InputStream}. |
| 15 | * For example: |
| 16 | * <blockquote><pre> |
| 17 | * InputStream rawdec = new LZMA2InputStream( |
| 18 | * new CloseIgnoringInputStream(myInputStream), |
| 19 | * myDictSize, null, myArrayCache); |
| 20 | * doSomething(rawdec); |
| 21 | * rawdec.close(); // This doesn't close myInputStream. |
| 22 | * </pre></blockquote> |
| 23 | * <p> |
| 24 | * With {@link XZInputStream}, {@link SingleXZInputStream}, and |
| 25 | * {@link SeekableXZInputStream} you can use their {@code close(boolean)} |
| 26 | * method to avoid closing the underlying {@code InputStream}; with |
| 27 | * those classes {@code CloseIgnoringInputStream} isn't needed. |
| 28 | * |
| 29 | * @since 1.7 |
| 30 | */ |
| 31 | public class CloseIgnoringInputStream extends FilterInputStream { |
| 32 | /** |
| 33 | * Creates a new {@code CloseIgnoringInputStream}. |
| 34 | */ |
| 35 | public CloseIgnoringInputStream(InputStream in) { |
| 36 | super(in); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * This does nothing (doesn't call {@code in.close()}). |
| 41 | */ |
| 42 | @Override |
| 43 | public void close() {} |
| 44 | } |