All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nakedobjects.nos.remote.command.socket.ProfilingOutputStream Maven / Gradle / Ivy

There is a newer version: 3.0.3
Show newest version
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