Mercurial Hosting > luan
comparison src/goodjava/io/CountingInputStream.java @ 1494:91c167099462
more io
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 03 May 2020 11:51:31 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1493:471ef3e6a84e | 1494:91c167099462 |
---|---|
1 package goodjava.io; | |
2 | |
3 import java.io.InputStream; | |
4 import java.io.IOException; | |
5 | |
6 | |
7 public final class CountingInputStream extends NoMarkInputStream { | |
8 private long count = 0; | |
9 | |
10 public CountingInputStream(InputStream in) { | |
11 super(in); | |
12 } | |
13 | |
14 public long count() { | |
15 return count; | |
16 } | |
17 | |
18 public int read() throws IOException { | |
19 int n = in.read(); | |
20 if( n != -1 ) | |
21 count++; | |
22 return n; | |
23 } | |
24 | |
25 public int read(byte[] b, int off, int len) throws IOException { | |
26 int n = in.read(b,off,len); | |
27 if( n != -1 ) | |
28 count += n; | |
29 return n; | |
30 } | |
31 | |
32 public long skip(long n) throws IOException { | |
33 n = in.skip(n); | |
34 if( n != -1 ) | |
35 count += n; | |
36 return n; | |
37 } | |
38 | |
39 } |