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

io.muserver.ChunkedHttpOutputStream Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
package io.muserver;

import io.netty.buffer.Unpooled;

import java.io.IOException;
import java.io.OutputStream;

class ChunkedHttpOutputStream extends OutputStream {
    private final NettyResponseAdaptor response;

    private boolean isClosed = false;

    ChunkedHttpOutputStream(NettyResponseAdaptor response) {
        this.response = response;
    }

    @Override
    public void write(int b) throws IOException {
        write(new byte[]{(byte) b}, 0, 1);
    }

    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        if (isClosed) {
            throw new IOException("Cannot write to closed output stream");
        }
        response.write(Unpooled.copiedBuffer(b, off, len), true);
    }

    public void close() {
        isClosed = true;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy