/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull private static SessionOutputBufferImpl sessionOutputBufferFrom (final @Nonnull OutputStream os) { final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl(); final SessionOutputBufferImpl sob = new SessionOutputBufferImpl(metrics, 100); sob.bind(os); return sob; }
protected void doFlush() throws IOException { this.outbuffer.flush(); }
@Override public void flush() throws IOException { flushBuffer(); flushStream(); }
flushBuffer(); writeEncoded(cbuf); write(CRLF);
protected void ensureOpen() throws IOException { final Socket socket = this.socketHolder.get(); if (socket == null) { throw new ConnectionClosedException("Connection is closed"); } if (!this.inbuffer.isBound()) { this.inbuffer.bind(getSocketInputStream(socket)); } if (!this.outbuffer.isBound()) { this.outbuffer.bind(getSocketOutputStream(socket)); } }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { if (b == null) { return; } // Do not want to buffer large-ish chunks // if the byte array is larger then MIN_CHUNK_LIMIT // write it directly to the output stream if (len > this.fragementSizeHint || len > this.buffer.capacity()) { // flush the buffer flushBuffer(); // write directly to the out stream streamWrite(b, off, len); this.metrics.incrementBytesTransferred(len); } else { // Do not let the buffer grow unnecessarily final int freecapacity = this.buffer.capacity() - this.buffer.length(); if (len > freecapacity) { // flush the buffer flushBuffer(); } // buffer this.buffer.append(b, off, len); } }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return {@code true}. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); this.socketHolder.set(socket); this.inbuffer.bind(null); this.outbuffer.bind(null); }
this.inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1, messageConstraints != null ? messageConstraints : MessageConstraints.DEFAULT, chardecoder); this.outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, fragmentSizeHint, charencoder); this.messageConstraints = messageConstraints;
private void flushBuffer() throws IOException { final int len = this.buffer.length(); if (len > 0) { streamWrite(this.buffer.buffer(), 0, len); this.buffer.clear(); this.metrics.incrementBytesTransferred(len); } }
@Override public void write(final int b) throws IOException { if (this.fragementSizeHint > 0) { if (this.buffer.isFull()) { flushBuffer(); } this.buffer.append(b); } else { flushBuffer(); this.outstream.write(b); } }
private void writeEncoded(final CharBuffer cbuf) throws IOException { if (!cbuf.hasRemaining()) { return; } if (this.bbuf == null) { this.bbuf = ByteBuffer.allocate(1024); } this.encoder.reset(); while (cbuf.hasRemaining()) { final CoderResult result = this.encoder.encode(cbuf, this.bbuf, true); handleEncodingResult(result); } final CoderResult result = this.encoder.flush(this.bbuf); handleEncodingResult(result); this.bbuf.clear(); }
flushBuffer(); writeEncoded(cbuf); write(CRLF);
protected void ensureOpen() throws IOException { final Socket socket = this.socketHolder.get(); Asserts.check(socket != null, "Connection is not open"); if (!this.inbuffer.isBound()) { this.inbuffer.bind(getSocketInputStream(socket)); } if (!this.outbuffer.isBound()) { this.outbuffer.bind(getSocketOutputStream(socket)); } }
@Override public void flush() throws IOException { flushBuffer(); flushStream(); }
public void write(final byte[] b, final int off, final int len) throws IOException { if (b == null) { return; } // Do not want to buffer large-ish chunks // if the byte array is larger then MIN_CHUNK_LIMIT // write it directly to the output stream if (len > this.fragementSizeHint || len > this.buffer.capacity()) { // flush the buffer flushBuffer(); // write directly to the out stream streamWrite(b, off, len); this.metrics.incrementBytesTransferred(len); } else { // Do not let the buffer grow unnecessarily final int freecapacity = this.buffer.capacity() - this.buffer.length(); if (len > freecapacity) { // flush the buffer flushBuffer(); } // buffer this.buffer.append(b, off, len); } }
/** * Binds this connection to the given {@link Socket}. This socket will be * used by the connection to send and receive data. * <p> * After this method's execution the connection status will be reported * as open and the {@link #isOpen()} will return {@code true}. * * @param socket the socket. * @throws IOException in case of an I/O error. */ protected void bind(final Socket socket) throws IOException { Args.notNull(socket, "Socket"); this.socketHolder.set(socket); this.inbuffer.bind(null); this.outbuffer.bind(null); }
this.inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1, messageConstraints != null ? messageConstraints : MessageConstraints.DEFAULT, chardecoder); this.outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, fragmentSizeHint, charencoder); this.messageConstraints = messageConstraints;
private void flushBuffer() throws IOException { final int len = this.buffer.length(); if (len > 0) { streamWrite(this.buffer.buffer(), 0, len); this.buffer.clear(); this.metrics.incrementBytesTransferred(len); } }
@Override public void write(final int b) throws IOException { if (this.fragementSizeHint > 0) { if (this.buffer.isFull()) { flushBuffer(); } this.buffer.append(b); } else { flushBuffer(); this.outstream.write(b); } }