public void run() {
        logger.entering("run", this);
        began_at = System.currentTimeMillis();
        final byte[] buffer = new byte[bufferSize];
        int cursor = 0;
        boolean input_ended = false;
        final Timer in_timer = new Timer(), out_timer = new Timer();
        try {
            while (exception == null && !input_ended) {
                final int space_remaining = buffer.length - cursor;
                    if (!ingress_paused() && !input_ended && space_remaining > 0) {
                        in_timer.begin();
                        try {
                            final int bytesRead = instream.read(buffer, cursor, space_remaining);
                            if (bytesRead == -1) {
                                input_ended = true;
                            } else {
                                cursor += bytesRead;
                                bytes_in += bytesRead;
                            }
                        } finally {
                            read_ms += in_timer.end();
                            ++read_count;
                        }
                    }
                    if (!egress_paused() && cursor > 0) {
                        out_timer.begin();
                        outstream.write(buffer, 0, cursor);
                        outstream.flush();
                        write_ms += out_timer.end();
                        bytes_out += cursor;
                        cursor = 0;
                        ++write_count;
                    }
            }
        } catch (IOException e) {
            onException(e);
        } finally {
            ended_at = System.currentTimeMillis();
        }
        logger.leaving("run", this);
    }