01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: //
09: //
10:
11: package de.uka.ilkd.key.proof;
12:
13: import java.io.BufferedInputStream;
14: import java.io.IOException;
15: import java.io.InputStream;
16:
17: import de.uka.ilkd.key.util.ProgressMonitor;
18:
19: public class CountingBufferedInputStream extends BufferedInputStream {
20:
21: private int chars;
22: private int step = 0;
23: private ProgressMonitor monitor = ProgressMonitor.Empty
24: .getInstance();
25:
26: public CountingBufferedInputStream(InputStream in) {
27: super (in);
28: chars = 0;
29: step = 1;
30: }
31:
32: public CountingBufferedInputStream(InputStream in,
33: ProgressMonitor monitor, int step) {
34: this (in);
35: this .step = (step == 0 ? 1 : step);
36: this .monitor = monitor;
37: chars = 0;
38: }
39:
40: public CountingBufferedInputStream(InputStream in,
41: ProgressMonitor monitor, int step, int alreadyRead) {
42: this (in, monitor, step);
43: chars = alreadyRead;
44: }
45:
46: public CountingBufferedInputStream(InputStream in, int size,
47: int step) {
48: super (in, size);
49: this .step = (step == 0 ? 1 : step);
50: chars = 0;
51: }
52:
53: public int read() throws IOException {
54: chars++;
55: if (monitor != null && chars % step == 0) {
56: monitor.setProgress(chars);
57: }
58: return super .read();
59: }
60:
61: public int getNumberOfParsedChars() {
62: return chars;
63: }
64:
65: }
|