Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An output stream implementation over a Vert.x `Buffer` instance - like `ByteArrayOutputStream` but a bit Vert.xified.
import java.io.IOException;
import java.io.OutputStream;
import io.vertx.core.buffer.Buffer;
public class VertxBufferOutputStream extends OutputStream {
private Buffer buffer;
public BufferOutputStream() {
this.buffer = Buffer.buffer();
}
@Override
public void write(int b) throws IOException {
buffer.appendByte((byte)(b & 0xFF));
}
@Override
public void write(byte[] b) throws IOException {
buffer.appendBytes(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
buffer.appendBytes(b, off, len);
}
public Buffer getBuffer() {
return this.buffer.copy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment