Refine search
protected void init(final OutputStream outstream, int buffersize, final HttpParams params) { if (outstream == null) { throw new IllegalArgumentException("Input stream may not be null"); } if (buffersize <= 0) { throw new IllegalArgumentException("Buffer size may not be negative or zero"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.outstream = outstream; this.buffer = new ByteArrayBuffer(buffersize); this.charset = HttpProtocolParams.getHttpElementCharset(params); this.ascii = this.charset.equalsIgnoreCase(HTTP.US_ASCII) || this.charset.equalsIgnoreCase(HTTP.ASCII); this.metrics = new HttpTransportMetricsImpl(); }
public void write(final byte[] b, int off, int len) throws IOException { if (b == null) { return; } // Do not want to buffer largish chunks // if the byte array is larger then MAX_CHUNK // write it directly to the output stream if (len > MAX_CHUNK || len > this.buffer.capacity()) { // flush the buffer flushBuffer(); // write directly to the out stream this.outstream.write(b, off, len); this.metrics.incrementBytesTransferred(len); } else { // Do not let the buffer grow unnecessarily int freecapacity = this.buffer.capacity() - this.buffer.length(); if (len > freecapacity) { // flush the buffer flushBuffer(); } // buffer this.buffer.append(b, off, len); } }
protected void flushBuffer() throws IOException { int len = this.buffer.length(); if (len > 0) { this.outstream.write(this.buffer.buffer(), 0, len); this.buffer.clear(); this.metrics.incrementBytesTransferred(len); } }
return 0; if (hasBufferedData()) { final int chunk = Math.min(len, this.bufferlen - this.bufferpos); System.arraycopy(this.buffer, this.bufferpos, b, off, chunk); final int read = streamRead(b, off, len); if (read > 0) { this.metrics.incrementBytesTransferred(read); while (!hasBufferedData()) { final int noRead = fillBuffer(); if (noRead == -1) {
private ExpectedResult parseExpectedResponse(Element element, Evaluator evaluator, ResultRecorder resultRecorder) { String contents = getTextAndRemoveIndent(element); contents = replaceVariableReferences(evaluator, contents, resultRecorder); SessionInputBufferImpl buffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), contents.length()); buffer.bind(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8))); DefaultHttpResponseParser defaultHttpResponseParser = new DefaultHttpResponseParser(buffer); ExpectedResult.ExpectedResultBuilder builder = expectedResult(); String body = null; try { HttpResponse httpResponse = defaultHttpResponseParser.parse(); StatusLine statusLine = httpResponse.getStatusLine(); builder.withStatus(statusLine.getStatusCode()); for (Header header : httpResponse.getAllHeaders()) { builder.withHeader(header.getName(), header.getValue()); } if (buffer.hasBufferedData()) { body = ""; while (buffer.hasBufferedData()) { body += (char) buffer.read(); } } builder.withBody(body); } catch (IOException | HttpException e) { e.printStackTrace(); } return builder.build(); }
super(); Args.positive(buffersize, "Buffer size"); final HttpTransportMetricsImpl inTransportMetrics = new HttpTransportMetricsImpl(); final HttpTransportMetricsImpl outTransportMetrics = new HttpTransportMetricsImpl(); this.inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1, messageConstraints != null ? messageConstraints : MessageConstraints.DEFAULT, chardecoder); this.outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, fragmentSizeHint,
/** * @since 4.1 */ protected HttpTransportMetricsImpl createTransportMetrics() { return new HttpTransportMetricsImpl(); }
String s = "HTTP/1.1 200 OK\r\n" + "Content-Length: 100\r\n" + "Content-Type: text/plain\r\n" + "Server: some-server\r\n" + "\r\n"; SessionInputBufferImpl sessionInputBuffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 2048); sessionInputBuffer.bind(new ByteArrayInputStream(s.getBytes(Consts.ASCII))); DefaultHttpResponseParser responseParser = new DefaultHttpResponseParser(sessionInputBuffer); HttpResponse response = responseParser.parse(); System.out.println(response);
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull private static SessionInputBufferImpl sessionInputBufferFrom (final @Nonnull InputStream is) { final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl(); final SessionInputBufferImpl sib = new SessionInputBufferImpl(metrics, 100); sib.bind(is); return sib; }
protected int fillBuffer() throws IOException { // compact the buffer if necessary if (this.bufferpos > 0) { int len = this.bufferlen - this.bufferpos; if (len > 0) { System.arraycopy(this.buffer, this.bufferpos, this.buffer, 0, len); } this.bufferpos = 0; this.bufferlen = len; } int l; int off = this.bufferlen; int len = this.buffer.length - off; l = this.instream.read(this.buffer, off, len); if (l == -1) { return -1; } else { this.bufferlen = off + l; this.metrics.incrementBytesTransferred(l); return l; } }
public int fillBuffer() throws IOException { // compact the buffer if necessary if (this.bufferpos > 0) { final int len = this.bufferlen - this.bufferpos; if (len > 0) { System.arraycopy(this.buffer, this.bufferpos, this.buffer, 0, len); } this.bufferpos = 0; this.bufferlen = len; } final int l; final int off = this.bufferlen; final int len = this.buffer.length - off; l = streamRead(this.buffer, off, len); if (l == -1) { return -1; } else { this.bufferlen = off + l; this.metrics.incrementBytesTransferred(l); return l; } }
protected void flushBuffer() throws IOException { int len = this.buffer.length(); if (len > 0) { this.outstream.write(this.buffer.buffer(), 0, len); this.buffer.clear(); this.metrics.incrementBytesTransferred(len); } }
return 0; if (hasBufferedData()) { final int chunk = Math.min(len, this.bufferlen - this.bufferpos); System.arraycopy(this.buffer, this.bufferpos, b, off, chunk); final int read = streamRead(b, off, len); if (read > 0) { this.metrics.incrementBytesTransferred(read); while (!hasBufferedData()) { final int noRead = fillBuffer(); if (noRead == -1) {
SessionInputBufferImpl buffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), contents.length()); buffer.bind(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8))); DefaultHttpRequestParser defaultHttpRequestParser = new DefaultHttpRequestParser(buffer); LinkedListMultimap<String, String> queryParameters = LinkedListMultimap.create(); if (buffer.hasBufferedData()) { body = "";
super(); Args.positive(buffersize, "Buffer size"); final HttpTransportMetricsImpl inTransportMetrics = new HttpTransportMetricsImpl(); final HttpTransportMetricsImpl outTransportMetrics = new HttpTransportMetricsImpl(); this.inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1, messageConstraints != null ? messageConstraints : MessageConstraints.DEFAULT, chardecoder); this.outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, fragmentSizeHint,
/** * @since 4.1 */ protected HttpTransportMetricsImpl createTransportMetrics() { return new HttpTransportMetricsImpl(); }
byte[] content = getContent(packet.getData()); if (content.length > 0) { InputStream byteIS = new ByteArrayInputStream(content); SessionInputBufferImpl contentBuf = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), content.length); contentBuf.bind(byteIS); ChunkedInputStream chunkedIS = new ChunkedInputStream(contentBuf); GZIPInputStream gzipIS = new GZIPInputStream(chunkedIS); while (gzipIS.available() != 0) { byte[] buf = new byte[128]; gzipIS.read(buf); contentBuilder.append(new String(buf, "UTF-8")); } gzipIS.close(); String contentString = contentBuilder.toString(); }
HttpEventCodec(Map<String, String> env, InputStream input, OutputStream output) { this.env = env; SessionInputBufferImpl sib = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 65535); sib.bind(Objects.requireNonNull(input)); this.sib = sib; SessionOutputBufferImpl sob = new SessionOutputBufferImpl(new HttpTransportMetricsImpl(), 65535); sob.bind(output); this.sob = sob; parser = new DefaultHttpRequestParserFactory(null, null).create(sib, MessageConstraints.custom().setMaxHeaderCount(65535).setMaxLineLength(65535).build()); }
/** * Reads from the channel to the destination. * * @param dst destination. * @return number of bytes transferred. * * @since 4.3 */ protected int readFromChannel(final ByteBuffer dst) throws IOException { final int bytesRead = this.channel.read(dst); if (bytesRead > 0) { this.metrics.incrementBytesTransferred(bytesRead); } return bytesRead; }
public int fillBuffer() throws IOException { // compact the buffer if necessary if (this.bufferpos > 0) { final int len = this.bufferlen - this.bufferpos; if (len > 0) { System.arraycopy(this.buffer, this.bufferpos, this.buffer, 0, len); } this.bufferpos = 0; this.bufferlen = len; } final int l; final int off = this.bufferlen; final int len = this.buffer.length - off; l = streamRead(this.buffer, off, len); if (l == -1) { return -1; } else { this.bufferlen = off + l; this.metrics.incrementBytesTransferred(l); return l; } }