|
1 |
| -/** |
2 |
| - * Copyright (C) 2000 - 2009 Silverpeas |
3 |
| - * |
4 |
| - * This program is free software: you can redistribute it and/or modify |
5 |
| - * it under the terms of the GNU Affero General Public License as |
6 |
| - * published by the Free Software Foundation, either version 3 of the |
7 |
| - * License, or (at your option) any later version. |
8 |
| - * |
9 |
| - * As a special exception to the terms and conditions of version 3.0 of |
10 |
| - * the GPL, you may redistribute this Program in connection with Free/Libre |
11 |
| - * Open Source Software ("FLOSS") applications as described in Silverpeas's |
12 |
| - * FLOSS exception. You should have recieved a copy of the text describing |
13 |
| - * the FLOSS exception, and it is also available here: |
14 |
| - * "http://repository.silverpeas.com/legal/licensing" |
15 |
| - * |
16 |
| - * This program is distributed in the hope that it will be useful, |
17 |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 |
| - * GNU Affero General Public License for more details. |
20 |
| - * |
21 |
| - * You should have received a copy of the GNU Affero General Public License |
22 |
| - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
23 |
| - */ |
24 |
| -package com.silverpeas.openoffice.windows.webdav; |
25 |
| - |
26 |
| -import java.beans.PropertyChangeListener; |
27 |
| -import java.io.FilterInputStream; |
28 |
| -import java.io.IOException; |
29 |
| -import java.io.InputStream; |
30 |
| - |
31 |
| -/** |
32 |
| - * @author ehugonnet |
33 |
| - */ |
34 |
| -public class MonitoredInputStream extends FilterInputStream { |
35 |
| - |
36 |
| - private int nbread = 0; |
37 |
| - private int size = 0; |
38 |
| - private InputStreamMonitor monitor; |
39 |
| - |
40 |
| - public MonitoredInputStream(InputStream stream) { |
41 |
| - super(stream); |
42 |
| - this.monitor = new InputStreamMonitor(); |
43 |
| - try { |
44 |
| - size = stream.available(); |
45 |
| - } catch (IOException ioe) { |
46 |
| - size = 0; |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - @Override |
51 |
| - public void close() throws IOException { |
52 |
| - super.close(); |
53 |
| - } |
54 |
| - |
55 |
| - @Override |
56 |
| - public int read(byte[] b) throws IOException { |
57 |
| - int nr = in.read(b); |
58 |
| - if (nr > 0) { |
59 |
| - monitor.setProgress(nbread += nr); |
60 |
| - } |
61 |
| - return nr; |
62 |
| - } |
63 |
| - |
64 |
| - @Override |
65 |
| - public int read(byte[] b, int off, int len) throws IOException { |
66 |
| - int nr = in.read(b, off, len); |
67 |
| - if (nr > 0) { |
68 |
| - monitor.setProgress(nbread += nr); |
69 |
| - } |
70 |
| - return nr; |
71 |
| - } |
72 |
| - |
73 |
| - @Override |
74 |
| - public synchronized void reset() throws IOException { |
75 |
| - in.reset(); |
76 |
| - nbread = size - in.available(); |
77 |
| - monitor.setProgress(nbread); |
78 |
| - } |
79 |
| - |
80 |
| - @Override |
81 |
| - public long skip(long n) throws IOException { |
82 |
| - long nr = in.skip(n); |
83 |
| - if (nr > 0) { |
84 |
| - monitor.setProgress(nbread += nr); |
85 |
| - } |
86 |
| - return nr; |
87 |
| - } |
88 |
| - |
89 |
| - @Override |
90 |
| - public int read() throws IOException { |
91 |
| - int c = in.read(); |
92 |
| - if (c >= 0) { |
93 |
| - monitor.setProgress(++nbread); |
94 |
| - } |
95 |
| - return c; |
96 |
| - } |
97 |
| - |
98 |
| - public void addPropertyChangeListener(PropertyChangeListener listener) { |
99 |
| - monitor.addPropertyChangeListener(listener); |
100 |
| - } |
101 |
| - |
102 |
| - public void removePropertyChangeListener(PropertyChangeListener listener) { |
103 |
| - monitor.removePropertyChangeListener(listener); |
104 |
| - } |
105 |
| -} |
| 1 | +/** |
| 2 | + * Copyright (C) 2000 - 2009 Silverpeas |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Affero General Public License as |
| 6 | + * published by the Free Software Foundation, either version 3 of the |
| 7 | + * License, or (at your option) any later version. |
| 8 | + * |
| 9 | + * As a special exception to the terms and conditions of version 3.0 of |
| 10 | + * the GPL, you may redistribute this Program in connection with Free/Libre |
| 11 | + * Open Source Software ("FLOSS") applications as described in Silverpeas's |
| 12 | + * FLOSS exception. You should have recieved a copy of the text describing |
| 13 | + * the FLOSS exception, and it is also available here: |
| 14 | + * "http://repository.silverpeas.com/legal/licensing" |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Affero General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public License |
| 22 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | + */ |
| 24 | +package com.silverpeas.openoffice.windows.webdav; |
| 25 | + |
| 26 | +import java.beans.PropertyChangeListener; |
| 27 | +import java.io.FilterInputStream; |
| 28 | +import java.io.IOException; |
| 29 | +import java.io.InputStream; |
| 30 | + |
| 31 | +/** |
| 32 | + * @author ehugonnet |
| 33 | + */ |
| 34 | +public class MonitoredInputStream extends FilterInputStream { |
| 35 | + |
| 36 | + private int nbread = 0; |
| 37 | + private int size = 0; |
| 38 | + private InputStreamMonitor monitor; |
| 39 | + |
| 40 | + public MonitoredInputStream(InputStream stream) { |
| 41 | + super(stream); |
| 42 | + this.monitor = new InputStreamMonitor(); |
| 43 | + try { |
| 44 | + size = stream.available(); |
| 45 | + } catch (IOException ioe) { |
| 46 | + size = 0; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public void close() throws IOException { |
| 52 | + super.close(); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public int read(byte[] b) throws IOException { |
| 57 | + int nr = in.read(b); |
| 58 | + if (nr > 0) { |
| 59 | + monitor.setProgress(nbread += nr); |
| 60 | + } |
| 61 | + return nr; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public int read(byte[] b, int off, int len) throws IOException { |
| 66 | + int nr = in.read(b, off, len); |
| 67 | + if (nr > 0) { |
| 68 | + monitor.setProgress(nbread += nr); |
| 69 | + } |
| 70 | + return nr; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public synchronized void reset() throws IOException { |
| 75 | + in.reset(); |
| 76 | + nbread = size - in.available(); |
| 77 | + monitor.setProgress(nbread); |
| 78 | + } |
| 79 | + |
| 80 | + @Override |
| 81 | + public long skip(long n) throws IOException { |
| 82 | + long nr = in.skip(n); |
| 83 | + if (nr > 0) { |
| 84 | + monitor.setProgress(nbread += nr); |
| 85 | + } |
| 86 | + return nr; |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public int read() throws IOException { |
| 91 | + int c = in.read(); |
| 92 | + if (c >= 0) { |
| 93 | + monitor.setProgress(++nbread); |
| 94 | + } |
| 95 | + return c; |
| 96 | + } |
| 97 | + |
| 98 | + public void addPropertyChangeListener(PropertyChangeListener listener) { |
| 99 | + monitor.addPropertyChangeListener(listener); |
| 100 | + } |
| 101 | + |
| 102 | + public void removePropertyChangeListener(PropertyChangeListener listener) { |
| 103 | + monitor.removePropertyChangeListener(listener); |
| 104 | + } |
| 105 | +} |
0 commit comments