01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18:
19: package org.columba.core.command;
20:
21: import java.io.FilterInputStream;
22: import java.io.IOException;
23: import java.io.InputStream;
24:
25: import org.columba.api.command.IWorkerStatusController;
26:
27: public class ProgressObservedInputStream extends FilterInputStream {
28:
29: private IWorkerStatusController status;
30:
31: private int read;
32:
33: /**
34: * Constructs the ProgressObservedInputStream.java.
35: *
36: * @param arg0
37: */
38: public ProgressObservedInputStream(InputStream arg0,
39: IWorkerStatusController theStatusController) {
40: this (arg0, theStatusController, false);
41: }
42:
43: /**
44: * Constructs the ProgressObservedInputStream.java.
45: *
46: * @param arg0
47: */
48: public ProgressObservedInputStream(InputStream arg0,
49: IWorkerStatusController theStatusController,
50: boolean relative) {
51: super (arg0);
52: this .status = theStatusController;
53:
54: if (!relative) {
55: try {
56: theStatusController.setProgressBarMaximum(arg0
57: .available());
58: } catch (IOException e) {
59: // nothing to do
60: }
61:
62: read = 0;
63: } else {
64: read = theStatusController.getProgressBarValue();
65: }
66: }
67:
68: /**
69: * @see java.io.InputStream#read()
70: */
71: @Override
72: public int read() throws IOException {
73: int result = super .read();
74: if (result != -1)
75: status.setProgressBarValue(++read);
76: return result;
77: }
78:
79: /**
80: * @see java.io.InputStream#read(byte[], int, int)
81: */
82: @Override
83: public int read(byte[] arg0, int arg1, int arg2) throws IOException {
84: int result = super.read(arg0, arg1, arg2);
85: read += result;
86: status.setProgressBarValue(read);
87:
88: return result;
89: }
90: }
|