3 TrakEM2 plugin for ImageJ(C).
4 Copyright (C) 2005, 2006 Albert Cardona and Rodney Douglas.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.txt )
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 You may contact Albert Cardona at acardona at ini.phys.ethz.ch
20 Institute of Neuroinformatics, University of Zurich / ETH, Switzerland.
23 package ini
.trakem2
.io
;
25 import java
.io
.BufferedInputStream
;
26 import java
.io
.InputStream
;
27 import java
.io
.IOException
;
30 /** A class to monitor an input stream for speed and total byte download. */
31 public class LoggingInputStream
extends BufferedInputStream
{
35 private long accum_time
= 0;
36 private long accum_bytes
= 0;
38 public LoggingInputStream(InputStream in
) {
40 last
= System
.currentTimeMillis();
43 public int read() throws IOException
{
49 public int read(byte[] b
) throws IOException
{
50 int m
= super.read(b
);
55 public int read(byte[] b
, int off
, int len
) throws IOException
{
56 int m
= super.read(b
, off
, len
);
61 /** Put the counter to zero. */
62 public void resetInfo() { // to work perfect, this would need a synchronized clause, but no such perfection is needed, and there are perfomance issues.
64 last
= System
.currentTimeMillis();
69 * [0] = current time in ms
70 * [1] = elapsed time in ms since last call to getInfo(long[])
71 * [2] = n_bytes_read since last call to getInfo(long[])
72 * [3] = accumulated time in ms since last call to resetInfo()
73 * [4] = accumulated bytes since last call to resetInfo()
75 * So current speed = info[2]/info[1] Kb/s
77 public void getInfo(long[] info
) {
78 long now
= System
.currentTimeMillis();
79 accum_time
+= now
- last
;
82 info
[1] = now
- last
; // elapsed time
84 info
[3] = accum_time
; // total time since last call to resetInfo()
85 info
[4] = accum_bytes
; // total bytes since last call to resetInfo()