public abstract class HttpContent
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
content |
| Constructor and Description |
|---|
HttpContent(ContentType contentType) |
| Modifier and Type | Method and Description |
|---|---|
static HttpContent |
bytes(byte[] content)
Create a new content from the given bytes.
|
static HttpContent |
bytes(byte[] content,
int offset,
int length)
Create a new content from the given bytes.
|
protected abstract byte[] |
compute() |
static HttpContent |
file(java.io.File file)
Create a new content from the given file.
|
static HttpContent |
form(java.util.Map<java.lang.String,java.lang.String> form)
Create a new content from the given form data.
|
static HttpContent |
form(java.lang.String key,
java.lang.String value)
Create a new content from the given form data.
|
byte[] |
getAsBytes() |
java.lang.String |
getAsString() |
java.lang.String |
getAsString(java.nio.charset.Charset charset)
Get the content as a string with the given charset.
|
abstract int |
getContentLength() |
ContentType |
getContentType() |
static HttpContent |
string(java.lang.String content)
Create a new content from the given string.
|
static HttpContent |
string(java.lang.String content,
java.nio.charset.Charset charset)
Create a new content from the given string.
|
public HttpContent(ContentType contentType)
public static HttpContent bytes(@Nonnull byte[] content)
content - The bytes to sendpublic static HttpContent bytes(@Nonnull byte[] content, int offset, int length)
content - The bytes to sendoffset - The offset to start reading fromlength - The length of the bytes to readpublic static HttpContent string(@Nonnull java.lang.String content)
content - The string to sendpublic static HttpContent string(@Nonnull java.lang.String content, @Nonnull java.nio.charset.Charset charset)
content - The string to sendcharset - The charset to usepublic static HttpContent file(@Nonnull java.io.File file)
file - The file to sendpublic static HttpContent form(@Nonnull java.lang.String key, @Nonnull java.lang.String value)
key - The keyvalue - The valuepublic static HttpContent form(@Nonnull java.util.Map<java.lang.String,java.lang.String> form)
form - The form datapublic ContentType getContentType()
public byte[] getAsBytes()
throws java.io.IOException
java.io.IOException - If an I/O error occurspublic java.lang.String getAsString()
throws java.io.IOException
java.io.IOException - If an I/O error occurspublic java.lang.String getAsString(@Nonnull
java.nio.charset.Charset charset)
throws java.io.IOException
charset - The charset to usejava.io.IOException - If an I/O error occurspublic abstract int getContentLength()
protected abstract byte[] compute()
throws java.io.IOException
java.io.IOException - If an I/O error occurs