Debian Codegraph @

src/org/tukaani/xz/CountingInputStream.java

raw symbols SCIP
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.IOException;
9
10 /**
11 * Counts the number of bytes read from an input stream.
12 * The {@code close()} method does nothing, that is, the underlying
13 * {@code InputStream} isn't closed.
14 */
15 class CountingInputStream extends CloseIgnoringInputStream {
16 private long size = 0;
17
18 public CountingInputStream(InputStream in) {
19 super(in);
20 }
21
22 @Override
23 public int read() throws IOException {
24 int ret = in.read();
25 if (ret != -1 && size >= 0)
26 ++size;
27
28 return ret;
29 }
30
31 @Override
32 public int read(byte[] b, int off, int len) throws IOException {
33 int ret = in.read(b, off, len);
34 if (ret > 0 && size >= 0)
35 size += ret;
36
37 return ret;
38 }
39
40 public long getSize() {
41 return size;
42 }
43 }