aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files/NoCloseInputStream.java
blob: 493f6ca4ee16f945e70c037217d47941f7979c0a (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
package cgeo.geocaching.files;

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

/**
 * Filter input stream that doesn't forward close() calls. Needed to parse multiple XML documents by SAX XML parser from
 * one input stream (e.g. ZipInputStream) because SAX parser closes stream.
 */
public class NoCloseInputStream extends FilterInputStream {
    private static final ClosedInputStream closedInputStream = new ClosedInputStream();

    public NoCloseInputStream(final InputStream in) {
        super(in);
    }

    @Override
    public void close() throws IOException {
        in = closedInputStream;
    }


    private static class ClosedInputStream extends InputStream {
        @Override
        public int read() throws IOException {
            throw new IOException("Stream already closed.");
        }
    }
}