gnu.inet.http

Class ByteArrayResponseBodyReader

Implemented Interfaces:
ResponseBodyReader

public class ByteArrayResponseBodyReader
extends java.lang.Object
implements ResponseBodyReader

Simple response body reader that stores content in a byte array.

Field Summary

protected byte[]
content
The content.
protected int
len
The length of the buffer.
protected int
pos
The position in the content at which the next write will occur.

Constructor Summary

ByteArrayResponseBodyReader()
Constructs a new byte array response body reader.
ByteArrayResponseBodyReader(int size)
Constructs a new byte array response body reader with the specified initial buffer size.

Method Summary

boolean
accept(Request request, Response response)
This reader accepts all responses.
void
close()
void
read(byte[] buffer, int offset, int length)
byte[]
toByteArray()
Retrieves the content of this reader as a byte array.

Field Details

content

protected byte[] content
The content.

len

protected int len
The length of the buffer.

pos

protected int pos
The position in the content at which the next write will occur.

Constructor Details

ByteArrayResponseBodyReader

public ByteArrayResponseBodyReader()
Constructs a new byte array response body reader.

ByteArrayResponseBodyReader

public ByteArrayResponseBodyReader(int size)
Constructs a new byte array response body reader with the specified initial buffer size.
Parameters:
size - the initial buffer size

Method Details

accept

public boolean accept(Request request,
                      Response response)
This reader accepts all responses.
Specified by:
accept in interface ResponseBodyReader

close

public void close()
Specified by:
close in interface ResponseBodyReader

read

public void read(byte[] buffer,
                 int offset,
                 int length)
Specified by:
read in interface ResponseBodyReader

toByteArray

public byte[] toByteArray()
Retrieves the content of this reader as a byte array. The size of the returned array is the number of bytes read.