Created
September 20, 2018 12:32
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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