public VertxHttpResponse(final HttpServerResponse response, final ResteasyProviderFactory providerFactory, final HttpMethod method) { outputHeaders = new MultivaluedMapImpl<String, Object>(); this.method = method; os = (method == null || !method.equals(HttpMethod.HEAD)) ? new ChunkOutputStream(this, 1000) : null; this.response = response; this.providerFactory = providerFactory; response.exceptionHandler(t -> vertxException = t); response.closeHandler(v -> vertxException = new IOException("Connection closed")); }
@Override public void close() throws IOException { flush(); super.close(); }
@Override public void write(int b) throws IOException { if (buffer.length() >= chunkSize - 1) { flush(); } buffer.appendByte((byte) b); }
public VertxHttpResponse(HttpServerResponse response, ResteasyProviderFactory providerFactory, HttpMethod method) { outputHeaders = new MultivaluedMapImpl<String, Object>(); this.method = method; os = (method == null || !method.equals(HttpMethod.HEAD)) ? new ChunkOutputStream(this, 1000) : null; this.response = response; this.providerFactory = providerFactory; response.exceptionHandler(t -> vertxException = t); response.closeHandler(v -> vertxException = new IOException("Connection closed")); }
@Override public void write(byte[] b, int off, int len) throws IOException { int dataLengthLeftToWrite = len; int dataToWriteOffset = off; int spaceLeftInCurrentChunk; while ((spaceLeftInCurrentChunk = chunkSize - buffer.length()) < dataLengthLeftToWrite) { buffer.appendBytes(b, dataToWriteOffset, spaceLeftInCurrentChunk); dataToWriteOffset = dataToWriteOffset + spaceLeftInCurrentChunk; dataLengthLeftToWrite = dataLengthLeftToWrite - spaceLeftInCurrentChunk; flush(); } if (dataLengthLeftToWrite > 0) { buffer.appendBytes(b, dataToWriteOffset, dataLengthLeftToWrite); } }
@Override public void close() throws IOException { flush(); super.close(); }
@Override public void write(int b) throws IOException { if (buffer.length() >= chunkSize - 1) { flush(); } buffer.appendByte((byte) b); }
@Override public void write(byte[] b, int off, int len) throws IOException { int dataLengthLeftToWrite = len; int dataToWriteOffset = off; int spaceLeftInCurrentChunk; while ((spaceLeftInCurrentChunk = chunkSize - buffer.length()) < dataLengthLeftToWrite) { buffer.appendBytes(b, dataToWriteOffset, spaceLeftInCurrentChunk); dataToWriteOffset = dataToWriteOffset + spaceLeftInCurrentChunk; dataLengthLeftToWrite = dataLengthLeftToWrite - spaceLeftInCurrentChunk; flush(); } if (dataLengthLeftToWrite > 0) { buffer.appendBytes(b, dataToWriteOffset, dataLengthLeftToWrite); } }