class ByteBufferWriteChannelListener implements ChannelListener<StreamSinkChannel>{

    private final ByteBuffer buffer;

    public ByteBufferWriteChannelListener(ByteBuffer body) {
        this.buffer =body;
    }

    public void setup(StreamSinkChannel channel) {
        while(true) {
            try {
                int c = channel.write(this.buffer);
                if (this.buffer.hasRemaining() && c > 0) {
                    continue;
                }

                if (this.buffer.hasRemaining()) {
                    channel.getWriteSetter().set(this);
                    channel.resumeWrites();
                } else {
                    this.writeDone(channel);
                }
            } catch (IOException var3) {
                this.handleError(channel, var3);
            }

            return;
        }
    }

    protected void handleError(StreamSinkChannel channel, IOException e) {
        UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
        IoUtils.safeClose(channel);
    }

    public void handleEvent(StreamSinkChannel channel) {<FILL_FUNCTION_BODY>}

    public boolean hasRemaining() {
        return this.buffer.hasRemaining();
    }

    protected void writeDone(final StreamSinkChannel channel) {
        try {
            channel.shutdownWrites();
            if (!channel.flush()) {
                channel.getWriteSetter().set(ChannelListeners.flushingChannelListener(new ChannelListener<StreamSinkChannel>() {
                    public void handleEvent(StreamSinkChannel o) {
                        IoUtils.safeClose(channel);
                    }
                }, ChannelListeners.closingChannelExceptionHandler()));
                channel.resumeWrites();
            }
        } catch (IOException var3) {
            this.handleError(channel, var3);
        }

    }

}

        while(true) {
            try {
                int c = channel.write(this.buffer);
                if (this.buffer.hasRemaining() && c > 0) {
                    continue;
                }

                if (this.buffer.hasRemaining()) {
                    channel.resumeWrites();
                    return;
                }

                this.writeDone(channel);
            } catch (IOException var3) {
                this.handleError(channel, var3);
            }

            return;
        }
    
<no_super_class>