Java 类org.apache.http.message.BasicLineFormatter 实例源码

项目:BUbiNG    文件:AbstractWarcRecord.java   
@Override
public void write(OutputStream output, ByteArraySessionOutputBuffer buffer) throws IOException {

    buffer.reset();
    final InputStream payload = writePayload(buffer);
    final long contentLength = buffer.contentLength();

    this.warcHeaders.updateHeader(new WarcHeader(WarcHeader.Name.CONTENT_LENGTH, Long.toString(contentLength)));

    Util.toOutputStream(BasicLineFormatter.formatProtocolVersion(WarcRecord.PROTOCOL_VERSION, null), output);
    output.write(ByteArraySessionOutputBuffer.CRLF);
    writeHeaders(this.warcHeaders, output);
    output.write(ByteArraySessionOutputBuffer.CRLF);
    ByteStreams.copy(payload, output);
    output.write(ByteArraySessionOutputBuffer.CRLFCRLF);
}
项目:lams    文件:AbstractMessageWriter.java   
/**
 * Creates an instance of AbstractMessageWriter.
 *
 * @param buffer the session output buffer.
 * @param formatter the line formatter.
 * @param params HTTP parameters.
 */
public AbstractMessageWriter(final SessionOutputBuffer buffer,
                             final LineFormatter formatter,
                             final HttpParams params) {
    super();
    if (buffer == null) {
        throw new IllegalArgumentException("Session input buffer may not be null");
    }
    this.sessionBuffer = buffer;
    this.lineBuf = new CharArrayBuffer(128);
    this.lineFormatter = (formatter != null) ?
        formatter : BasicLineFormatter.DEFAULT;
}
项目:BUbiNG    文件:AbstractWarcRecord.java   
protected static void writeHeaders(final HeaderGroup headers, final OutputStream output) throws IOException {
    for (final HeaderIterator it = headers.iterator(); it.hasNext();) {
        final org.apache.http.Header header = it.nextHeader();
        Util.toOutputStream(BasicLineFormatter.formatHeader(header, null), output);
        output.write(ByteArraySessionOutputBuffer.CRLF);
    }
}
项目:Bastion    文件:ResponsePrinter.java   
private void writeHeaders(Writer writer, BasicLineFormatter formatter) {
    response.getHeaders().forEach(apiHeader -> {
        try {
            writer.append(BasicLineFormatter.formatHeader(new BasicHeader(apiHeader.getName(), apiHeader.getValue()), formatter)).append("\r\n");
        } catch (IOException exception) {
            throw new IllegalStateException(exception);
        }
    });
}
项目:Bastion    文件:HttpRequestPrinter.java   
private void writeHeadSection(Writer writer) throws IOException {
    RequestExecutor executor = new RequestExecutor(request, BastionFactory.getDefaultBastionFactory().getConfiguration());
    URL url = new URL(executor.getResolvedUrl());
    BasicLineFormatter formatter = new BasicLineFormatter();
    writeRequestLine(url, writer, formatter);
    writeHeaders(url, executor.getHeaders(), writer, formatter);
    writer.append("\r\n");
}
项目:Bastion    文件:HttpRequestPrinter.java   
private void writeHeaders(URL url, Collection<ApiHeader> headers, Writer writer, BasicLineFormatter formatter) throws IOException {
    writer.append(BasicLineFormatter.formatHeader(new BasicHeader("Host", url.getHost()), formatter)).append("\r\n");
    headers.forEach(apiHeader -> {
        try {
            writer.append(BasicLineFormatter.formatHeader(new BasicHeader(apiHeader.getName(), apiHeader.getValue()), formatter)).append("\r\n");
        } catch (IOException exception) {
            throw new IllegalStateException(exception);
        }
    });
}
项目:Bastion    文件:ResponsePrinter.java   
private void writeHeadSection(Writer writer) throws IOException {
    BasicLineFormatter formatter = new BasicLineFormatter();
    writeStatusLine(writer, formatter);
    writeHeaders(writer, formatter);
    writer.append("\r\n");
}
项目:Bastion    文件:ResponsePrinter.java   
private void writeStatusLine(Writer writer, BasicLineFormatter formatter) throws IOException {
    String statusLine = BasicLineFormatter.formatStatusLine(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1),
            response.getStatusCode(), response.getStatusText()), formatter);
    writer.append(statusLine).append("\r\n");
}
项目:Bastion    文件:HttpRequestPrinter.java   
private void writeRequestLine(URL url, Writer writer, BasicLineFormatter formatter) throws IOException {
    BasicRequestLine requestLine = new BasicRequestLine(request.method().getValue(), url.getFile(), new ProtocolVersion("HTTP", 1, 1));
    writer.append(BasicLineFormatter.formatRequestLine(requestLine, formatter)).append("\r\n");
}