当前位置: 首页>>代码示例>>Java>>正文


Java SessionInputBufferImpl类代码示例

本文整理汇总了Java中org.apache.http.impl.io.SessionInputBufferImpl的典型用法代码示例。如果您正苦于以下问题:Java SessionInputBufferImpl类的具体用法?Java SessionInputBufferImpl怎么用?Java SessionInputBufferImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SessionInputBufferImpl类属于org.apache.http.impl.io包,在下文中一共展示了SessionInputBufferImpl类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: withBody

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
/**
 * Set the body of the request by providing an InputStream
 *
 * @param body the bytes of the body
 * @param contentLength how long the body is supposed to be
 */
public EventBuilder withBody(InputStream body, int contentLength) {
    Objects.requireNonNull(body, "body");
    if (contentLength < 0) {
        throw new IllegalArgumentException("Invalid contentLength");
    }
    // This is for safety. Because we concatenate events, an input stream shorter than content length will cause
    // the implementation to continue reading through to the next http request. We need to avoid a sort of
    // buffer overrun.
    // FIXME: Make InputStream handling simpler.
    SessionInputBufferImpl sib = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 65535);
    sib.bind(body);
    this.body = new ContentLengthInputStream(sib, contentLength);
    this.contentLength = contentLength;
    return this;
}
 
开发者ID:fnproject,项目名称:fdk-java,代码行数:22,代码来源:FnTestHarness.java

示例2: BHttpConnectionBase

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
/**
 * Creates new instance of BHttpConnectionBase.
 *
 * @param buffersize buffer size. Must be a positive number.
 * @param fragmentSizeHint fragment size hint.
 * @param chardecoder decoder to be used for decoding HTTP protocol elements.
 *   If <code>null</code> simple type cast will be used for byte to char conversion.
 * @param charencoder encoder to be used for encoding HTTP protocol elements.
 *   If <code>null</code> simple type cast will be used for char to byte conversion.
 * @param constraints Message constraints. If <code>null</code>
 *   {@link MessageConstraints#DEFAULT} will be used.
 * @param incomingContentStrategy incoming content length strategy. If <code>null</code>
 *   {@link LaxContentLengthStrategyHC4#INSTANCE} will be used.
 * @param outgoingContentStrategy outgoing content length strategy. If <code>null</code>
 *   {@link StrictContentLengthStrategyHC4#INSTANCE} will be used.
 */
protected BHttpConnectionBase(
        final int buffersize,
        final int fragmentSizeHint,
        final CharsetDecoder chardecoder,
        final CharsetEncoder charencoder,
        final MessageConstraints constraints,
        final ContentLengthStrategy incomingContentStrategy,
        final ContentLengthStrategy outgoingContentStrategy) {
    super();
    Args.positive(buffersize, "Buffer size");
    final HttpTransportMetricsImpl inTransportMetrics = new HttpTransportMetricsImpl();
    final HttpTransportMetricsImpl outTransportMetrics = new HttpTransportMetricsImpl();
    this.inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1,
            constraints != null ? constraints : MessageConstraints.DEFAULT, chardecoder);
    this.outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, fragmentSizeHint,
            charencoder);
    this.connMetrics = new HttpConnectionMetricsImpl(inTransportMetrics, outTransportMetrics);
    this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
        LaxContentLengthStrategyHC4.INSTANCE;
    this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
        StrictContentLengthStrategyHC4.INSTANCE;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:39,代码来源:BHttpConnectionBase.java

示例3: unchunkResponse

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
/**
 * Converts chunked response data (returned by in the request body) <br>
 * into a single piece, regular byte array.
 * 
 * @param content Chunked data byte array
 * @return Unchunked (regular) byte array
 */
public byte[] unchunkResponse(byte[] content) {
  SessionInputBufferImpl buffer =
      new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024);
  buffer.bind(new ByteArrayInputStream(content));

  try {
    if (content != null && content.length > 0) {
      return IOUtils.toByteArray(new ChunkedInputStream(buffer));
    }
  } catch (IOException e) {
    LOG.error("Cannot write chunked input stream to byte array!", e);
  }
  return content;
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:22,代码来源:MessageUtils.java

示例4: withBody

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
public FnHttpEventBuilder withBody(InputStream body, int contentLength) {
    Objects.requireNonNull(body, "body");
    if (contentLength < 0) {
        throw new IllegalArgumentException("Invalid contentLength");
    }
    // This is for safety. Because we concatenate events, an input stream shorter than content length will cause
    // the implementation to continue reading through to the next http request. We need to avoid a sort of
    // buffer overrun.
    // FIXME: Make InputStream handling simpler.
    SessionInputBufferImpl sib = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 65535);
    sib.bind(body);
    this.bodyStream = new ContentLengthInputStream(sib, contentLength);
    this.contentLength = contentLength;
    return this;
}
 
开发者ID:fnproject,项目名称:fdk-java,代码行数:16,代码来源:FnHttpEventBuilder.java

示例5: parseExpectedResponse

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
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();
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:35,代码来源:ResponseCommand.java

示例6: setInput

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
protected void setInput(final InputStream input) {
	final SessionInputBufferImpl bufferImpl = new SessionInputBufferImpl(metrics, BUFFER_SIZE, 0, null, null);
	bufferImpl.bind(input);
	this.buffer = bufferImpl;
	this.payload = null;
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:7,代码来源:AbstractWarcReader.java

示例7: warpSessionInputBuffer

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
public static SessionInputBuffer warpSessionInputBuffer(final InputStream input) {
	final SessionInputBufferImpl bufferImpl = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024, 0, null, null);
	bufferImpl.bind(input);
	return bufferImpl;
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:6,代码来源:InputStreamTestMocks.java

示例8: run

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
/** {@inheritDoc} */
public boolean run() {
    boolean success = false;
    String error = null;
    try {
        String bu = context.getSpecification().getBaseUrl();
        if (bu.startsWith("https")) {
            return true;
        }
        URI uri = new URI(bu);
        String host = uri.getHost();

        context.acquireRequestPermit();
        Socket socket = new Socket(host, HTTP_PORT);
        OutputStream os = socket.getOutputStream();
        String request = "GET " + rawUri + " HTTP/1.1\n"
                         + "Host: " + host + "\n"
                         + "Accept: application/rdap+json\n\n";
        os.write(request.getBytes("UTF-8"));
        InputStream is  = socket.getInputStream();
        SessionInputBufferImpl sibl =
            new SessionInputBufferImpl(
                new HttpTransportMetricsImpl(),
                BUFFER_SIZE
            );
        sibl.bind(is);
        DefaultHttpResponseParser dhrp =
            new DefaultHttpResponseParser(sibl);
        HttpResponse hr = dhrp.parse();
        HttpEntity he = hr.getEntity();
        /* It is assumed that this class is used to produce
         * invalid requests. The error codes aren't checked here;
         * it's just for confirming that the content (if present)
         * is JSON. With some servers, e.g. Jetty, it's not
         * possible to do things like setting the content type in
         * this sort of situation, so that is explicitly not
         * checked. */
        if ((he == null) || (he.getContentLength() == 0)) {
            success = true;
        } else {
            InputStream isc = he.getContent();
            InputStreamReader iscr = new InputStreamReader(isc, "UTF-8");
            new Gson().fromJson(iscr, Map.class);
            success = true;
        }
    } catch (Exception e) {
        error = e.toString();
    }

    Result nr = new Result(proto);
    nr.setPath(rawUri);
    nr.setCode("content");
    if (success) {
        nr.setStatus(Status.Success);
    } else if (!nr.getStatusSet()) {
        nr.setStatus(Status.Failure);
    }
    String prefix = (expectedSuccess) ? "content" : "error content";
    nr.setInfo(success ? prefix + " is empty or JSON"
                       : prefix + " is not empty or JSON: " + error);
    context.addResult(nr);

    return success;
}
 
开发者ID:APNIC-net,项目名称:rdap-conformance,代码行数:65,代码来源:RawURIRequest.java

示例9: parseRequest

import org.apache.http.impl.io.SessionInputBufferImpl; //导入依赖的package包/类
private HttpRequest parseRequest(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)));
  DefaultHttpRequestParser defaultHttpRequestParser = new DefaultHttpRequestParser(buffer);
  LinkedListMultimap<String, String> queryParameters = LinkedListMultimap.create();

  String method = "";
  String url = "";
  LinkedListMultimap<String, String> headers = LinkedListMultimap.create();
  String body = null;
  String server = null;
  try {
    org.apache.http.HttpRequest httpRequest = defaultHttpRequestParser.parse();
    method = httpRequest.getRequestLine().getMethod();
    url = httpRequest.getRequestLine().getUri();
    if (url.startsWith("#")) {
      url = "" + evaluator.evaluate(url);
    }
    Matcher matcher = Pattern.compile("(https?://[^/]+)(/.*)").matcher(url);
    if (matcher.matches()) {
      server = matcher.group(1);
      url = matcher.group(2);
    }

    if (url.contains("?")) {
      String[] urlAndQueryParameters = url.split("\\?");
      url = urlAndQueryParameters[0];
      for (String queryParameter : urlAndQueryParameters[1].split("&")) {
        String[] parameter = queryParameter.split("=");

        queryParameters.put(parameter[0], parameter[1]);
      }
    }

    for (Header header : httpRequest.getAllHeaders()) {
      headers.put(header.getName(), header.getValue());
    }

    if (buffer.hasBufferedData()) {
      body = "";

      while (buffer.hasBufferedData()) {
        body += (char) buffer.read();
      }
    }

  } catch (IOException | HttpException e) {
    e.printStackTrace();
  }


  return new HttpRequest(method, url, headers, body, server, queryParameters);
}
 
开发者ID:HuygensING,项目名称:timbuctoo,代码行数:58,代码来源:RequestCommand.java


注:本文中的org.apache.http.impl.io.SessionInputBufferImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。