@Override public void flush() throws IOException { final SocketHolder socketHolder = ensureOpen(); this.outbuffer.flush(socketHolder.getOutputStream()); }
protected boolean awaitInput(final int timeout) throws IOException { if (this.inBuffer.hasBufferedData()) { return true; } fillInputBuffer(timeout); return this.inBuffer.hasBufferedData(); }
protected InputStream createContentInputStream( final long len, final SessionInputBuffer buffer, final InputStream inputStream) { if (len > 0) { return new ContentLengthInputStream(buffer, inputStream, len); } else if (len == 0) { return EmptyInputStream.INSTANCE; } else if (len == ContentLengthStrategy.CHUNKED) { return new ChunkedInputStream(buffer, inputStream, this.h1Config); } else { return new IdentityInputStream(buffer, inputStream); } }
private int fillInputBuffer(final int timeout) throws IOException { final SocketHolder socketHolder = ensureOpen(); final Socket socket = socketHolder.getSocket(); final int oldtimeout = socket.getSoTimeout(); try { socket.setSoTimeout(timeout); return this.inBuffer.fillBuffer(socketHolder.getInputStream()); } finally { socket.setSoTimeout(oldtimeout); } }
@Override public boolean isDataAvailable(final int timeout) throws IOException { ensureOpen(); try { return awaitInput(timeout); } catch (final SocketTimeoutException ex) { return false; } }
/** * Read some bytes from the stream. * @param b The byte array that will hold the contents from the stream. * @return The number of bytes returned or -1 if the end of stream has been * reached. * @throws IOException in case of an I/O error */ @Override public int read (final byte[] b) throws IOException { return read(b, 0, b.length); }
/** * Writes the array. If the array does not fit within the buffer, it is * not split, but rather written out as one large chunk. */ @Override public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Must be called to ensure the internal cache is flushed and the closing * chunk is written. * @throws IOException in case of an I/O error */ public void finish() throws IOException { if (!this.wroteLastChunk) { flushCache(); writeClosingChunk(); this.wroteLastChunk = true; } }
@Override public int read(final byte[] b, final InputStream inputStream) throws IOException { if (b == null) { return 0; } return read(b, 0, b.length, inputStream); }
@Override public void write(final byte[] b, final OutputStream outputStream) throws IOException { if (b == null) { return; } write(b, 0, b.length, outputStream); }
/** * Read more bytes from the stream. * @param b The byte array to put the new data in. * @return The number of bytes read into the buffer. * @throws IOException If an IO problem occurs * @see java.io.InputStream#read(byte[]) */ @Override public int read(final byte[] b) throws IOException { return read(b, 0, b.length); }
private int fillInputBuffer(final int timeout) throws IOException { final SocketHolder socketHolder = ensureOpen(); final Socket socket = socketHolder.getSocket(); final int oldtimeout = socket.getSoTimeout(); try { socket.setSoTimeout(timeout); return this.inBuffer.fillBuffer(socketHolder.getInputStream()); } finally { socket.setSoTimeout(oldtimeout); } }
@Override public void flush() throws IOException { final SocketHolder socketHolder = ensureOpen(); this.outbuffer.flush(socketHolder.getOutputStream()); }
protected InputStream createContentInputStream( final long len, final SessionInputBuffer buffer, final InputStream inputStream) { if (len > 0) { return new ContentLengthInputStream(buffer, inputStream, len); } else if (len == 0) { return EmptyInputStream.INSTANCE; } else if (len == ContentLengthStrategy.CHUNKED) { return new ChunkedInputStream(buffer, inputStream, this.h1Config); } else { return new IdentityInputStream(buffer, inputStream); } }
@Override public boolean isDataAvailable(final int timeout) throws IOException { ensureOpen(); try { return awaitInput(timeout); } catch (final SocketTimeoutException ex) { return false; } }
protected boolean awaitInput(final int timeout) throws IOException { if (this.inBuffer.hasBufferedData()) { return true; } fillInputBuffer(timeout); return this.inBuffer.hasBufferedData(); }
/** * Read some bytes from the stream. * @param b The byte array that will hold the contents from the stream. * @return The number of bytes returned or -1 if the end of stream has been * reached. * @throws IOException in case of an I/O error */ @Override public int read (final byte[] b) throws IOException { return read(b, 0, b.length); }
/** * Writes the array. If the array does not fit within the buffer, it is * not split, but rather written out as one large chunk. */ @Override public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Must be called to ensure the internal cache is flushed and the closing * chunk is written. * @throws IOException in case of an I/O error */ public void finish() throws IOException { if (!this.wroteLastChunk) { flushCache(); writeClosingChunk(); this.wroteLastChunk = true; } }
@Override public int read(final byte[] b, final InputStream inputStream) throws IOException { if (b == null) { return 0; } return read(b, 0, b.length, inputStream); }