org.apache.http.io.SessionInputBuffer Java Examples

The following examples show how to use org.apache.http.io.SessionInputBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoundSessionInputBuffer.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link SessionInputBuffer} bounded to a given maximum length.
 *
 * @param buffer the buffer to wrap
 * @param length the maximum number of bytes to read (from the buffered stream).
 */
public BoundSessionInputBuffer(final SessionInputBuffer buffer, final long length) {
	super(new HttpTransportMetricsImpl(), BUFFER_SIZE, 0, null, null);
	this.bounded = new ContentLengthInputStream(buffer, length);
	this.input = new CountingInputStream(this.bounded);
	super.bind(this.input);
	this.length = length;
}
 
Example #2
Source File: InputStreamTestMocks.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public static String[] readCRLFSeparatedBlock(SessionInputBuffer input) throws IOException {
	CharArrayBuffer line = new CharArrayBuffer(128);
	List<String> ret = new ArrayList<>();
	for (;;) {
		if (input.readLine(line) == -1) break;
		if (line.length() == 0) break;
		ret.add(line.toString());
		line.clear();
	}
	return ret.toArray(new String[ret.size()]);
}
 
Example #3
Source File: InputStreamTestMocks.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public WarcRecord(SessionInputBuffer buffer) throws IOException {
	this.warcHeaders = readCRLFSeparatedBlock(buffer);
	if (this.warcHeaders.length == 0) throw new EOFException();
	long contentLength = contentLength(this.warcHeaders);
	if (contentLength == -1) throw new WarcFormatException("Can't find Content-Length");
	final HeaderGroup hg = toHeaderGroup(this.warcHeaders);
	date = WarcHeader.parseDate(WarcHeader.getFirstHeader(hg, WarcHeader.Name.WARC_DATE).getValue());
	uuid = WarcHeader.parseId(WarcHeader.getFirstHeader(hg, WarcHeader.Name.WARC_RECORD_ID).getValue());
	this.payload = new byte[(int)contentLength];
	for (int read = 0; read < contentLength; read ++) this.payload[read] = (byte)buffer.read();
}
 
Example #4
Source File: InputStreamTestMocks.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public HttpResponseWarcRecord(SessionInputBuffer buffer) throws IOException {
	super(buffer);
	buffer = warpSessionInputBuffer(new ByteArrayInputStream(this.payload));
	this.headers = readCRLFSeparatedBlock(buffer);
	long contentLength = contentLength(this.headers);
	InputStream blockStream = new ContentLengthInputStream(buffer, contentLength);
	this.entity = new byte[(int)contentLength];
	blockStream.read(this.entity);
	blockStream.close();
}
 
Example #5
Source File: ExtendedHttpClientBuilder.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
public GarbageAllergicHttpResponseParser(
    SessionInputBuffer buffer,
    LineParser lineParser,
    HttpResponseFactory responseFactory,
    MessageConstraints constraints
) {
  super(buffer, lineParser, responseFactory, constraints);
}
 
Example #6
Source File: CustomConnectionsHttpClientFactory.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
protected HttpMessageParser<HttpResponse> createResponseParser(
        final SessionInputBuffer buffer,
        final HttpResponseFactory responseFactory,
        final HttpParams params) {

  return new DefaultHttpResponseParser(
          buffer,
          new MyLineParser(),
          responseFactory,
          params);
}
 
Example #7
Source File: InputStreamTestMocks.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
public static SessionInputBuffer warpSessionInputBuffer(final InputStream input) {
	final SessionInputBufferImpl bufferImpl = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024, 0, null, null);
	bufferImpl.bind(input);
	return bufferImpl;
}
 
Example #8
Source File: InputStreamTestMocks.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
public InfoWarcRecord(SessionInputBuffer buffer) throws IOException {
	super(buffer);
	this.info = readCRLFSeparatedBlock(warpSessionInputBuffer(new ByteArrayInputStream(this.payload)));
}
 
Example #9
Source File: InputStreamTestMocks.java    From BUbiNG with Apache License 2.0 4 votes vote down vote up
public HttpRequestWarcRecord(SessionInputBuffer buffer) throws IOException {
	super(buffer);
	this.headers = readCRLFSeparatedBlock(warpSessionInputBuffer(new ByteArrayInputStream(this.payload)));
}
 
Example #10
Source File: HttpUtils.java    From MediaPlayerProxy with Apache License 2.0 4 votes vote down vote up
@Override
protected HttpMessageParser createResponseParser(final SessionInputBuffer buffer,
		final HttpResponseFactory responseFactory, final HttpParams params) {
	return new DefaultResponseParser(buffer, new IcyLineParser(), responseFactory, params);
}