org.nakedobjects.nos.remote.command.socket.ProfilingOutputStream Maven / Gradle / Ivy
package org.nakedobjects.nos.remote.command.socket;
import java.io.IOException;
import java.io.OutputStream;
public class ProfilingOutputStream extends OutputStream {
private final OutputStream wrapped;
private int bytes = 0;
private long end = 0;
private long start = 0;
public ProfilingOutputStream(final OutputStream wrapped) {
this.wrapped = wrapped;
}
private void end() {
end = System.currentTimeMillis();
}
public int getSize() {
return bytes;
}
public float getTime() {
return (end - start) / 1000.0f;
}
public void resetTimer() {
bytes = 0;
start = end = 0;
}
private void start() {
if(start == 0) {
start = System.currentTimeMillis();
}
}
public void write(byte[] b) throws IOException {
start();
bytes += b.length;
wrapped.write(b);
end();
}
public void write(byte[] b, int off, int len) throws IOException {
start();
bytes += len;
wrapped.write(b, off, len);
end();
}
public void write(int b) throws IOException {
start();
bytes++;
wrapped.write(b);
end();
}
}
// Copyright (c) Naked Objects Group Ltd.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy