Skip to content

Instantly share code, notes, and snippets.

@guss77
Created September 20, 2018 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guss77/38e937bb6d47bbd0b151636400299518 to your computer and use it in GitHub Desktop.
Save guss77/38e937bb6d47bbd0b151636400299518 to your computer and use it in GitHub Desktop.
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