public final class ByteArrayContent extends AbstractInputStreamContentConcrete implementation of AbstractInputStreamContent that generates repeatable input streams based on the contents of byte array.
Sample use:
static void setJsonContent(HttpRequest request, byte[] json) {
request.setContent(new ByteArrayContent("application/json", json));
}
Implementation is not thread-safe.
Static Methods
fromString(String type, String contentString)
public static ByteArrayContent fromString(String type, String contentString)Returns a new instance with the UTF-8 encoding (using StringUtils#getBytesUtf8(String)) of the given content string.
Sample use:
static void setJsonContent(HttpRequest request, String json) {
request.setContent(ByteArrayContent.fromString("application/json", json));
}
| Name | Description |
type |
Stringcontent type or |
contentString |
Stringcontent string |
| Type | Description |
ByteArrayContent |
Constructors
ByteArrayContent(String type, byte[] array)
public ByteArrayContent(String type, byte[] array)Constructor from byte array content that has already been encoded.
| Name | Description |
type |
Stringcontent type or |
array |
byte[]byte array content |
ByteArrayContent(String type, byte[] array, int offset, int length)
public ByteArrayContent(String type, byte[] array, int offset, int length)Constructor from byte array content that has already been encoded, specifying a range of bytes to read from the input byte array.
| Name | Description |
type |
Stringcontent type or |
array |
byte[]byte array content |
offset |
intstarting offset into the byte array |
length |
intof bytes to read from byte array |
Methods
getInputStream()
public InputStream getInputStream()Return an input stream for the specific implementation type of AbstractInputStreamContent. If the specific implementation will return true for #retrySupported() this should be a factory function which will create a new InputStream from the source data whenever invoked.
| Type | Description |
InputStream |
getLength()
public long getLength()| Type | Description |
long |
retrySupported()
public boolean retrySupported()| Type | Description |
boolean |
setCloseInputStream(boolean closeInputStream)
public ByteArrayContent setCloseInputStream(boolean closeInputStream)Sets whether the input stream should be closed at the end of #writeTo. Default is
true. Subclasses should override by calling super.
| Name | Description |
closeInputStream |
boolean |
| Type | Description |
ByteArrayContent |
setType(String type)
public ByteArrayContent setType(String type)Sets the content type or null for none. Subclasses should override by calling super.
| Name | Description |
type |
String |
| Type | Description |
ByteArrayContent |