Class HttpContent
- java.lang.Object
-
- net.lenni0451.commons.httpclient.content.HttpContent
-
- Direct Known Subclasses:
ByteArrayContent,FileContent,URLEncodedFormContent
public abstract class HttpContent extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]content
-
Constructor Summary
Constructors Constructor Description HttpContent(ContentType contentType)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static HttpContentbytes(byte[] content)Create a new content from the given bytes.static HttpContentbytes(byte[] content, int offset, int length)Create a new content from the given bytes.protected abstract byte[]compute()static HttpContentfile(java.io.File file)Create a new content from the given file.static HttpContentform(java.lang.String key, java.lang.String value)Create a new content from the given form data.static HttpContentform(java.util.Map<java.lang.String,java.lang.String> form)Create a new content from the given form data.byte[]getAsBytes()java.lang.StringgetAsString()java.lang.StringgetAsString(java.nio.charset.Charset charset)Get the content as a string with the given charset.abstract intgetContentLength()ContentTypegetContentType()static HttpContentstring(java.lang.String content)Create a new content from the given string.static HttpContentstring(java.lang.String content, java.nio.charset.Charset charset)Create a new content from the given string.
-
-
-
Constructor Detail
-
HttpContent
public HttpContent(ContentType contentType)
-
-
Method Detail
-
bytes
public static HttpContent bytes(byte[] content)
Create a new content from the given bytes.- Parameters:
content- The bytes to send- Returns:
- The created content
-
bytes
public static HttpContent bytes(byte[] content, int offset, int length)
Create a new content from the given bytes.- Parameters:
content- The bytes to sendoffset- The offset to start reading fromlength- The length of the bytes to read- Returns:
- The created content
-
string
public static HttpContent string(java.lang.String content)
Create a new content from the given string.- Parameters:
content- The string to send- Returns:
- The created content
-
string
public static HttpContent string(java.lang.String content, java.nio.charset.Charset charset)
Create a new content from the given string.- Parameters:
content- The string to sendcharset- The charset to use- Returns:
- The created content
-
file
public static HttpContent file(java.io.File file)
Create a new content from the given file.- Parameters:
file- The file to send- Returns:
- The created content
-
form
public static HttpContent form(java.lang.String key, java.lang.String value)
Create a new content from the given form data.- Parameters:
key- The keyvalue- The value- Returns:
- The created content
-
form
public static HttpContent form(java.util.Map<java.lang.String,java.lang.String> form)
Create a new content from the given form data.- Parameters:
form- The form data- Returns:
- The created content
-
getContentType
public ContentType getContentType()
- Returns:
- The content type
-
getAsBytes
@Nonnull public byte[] getAsBytes() throws java.io.IOException- Returns:
- The content as bytes
- Throws:
java.io.IOException- If an I/O error occurs
-
getAsString
@Nonnull public java.lang.String getAsString() throws java.io.IOException- Returns:
- The content as a UTF-8 string
- Throws:
java.io.IOException- If an I/O error occurs
-
getAsString
@Nonnull public java.lang.String getAsString(java.nio.charset.Charset charset) throws java.io.IOExceptionGet the content as a string with the given charset.- Parameters:
charset- The charset to use- Returns:
- The content as a string
- Throws:
java.io.IOException- If an I/O error occurs
-
getContentLength
public abstract int getContentLength()
- Returns:
- The content length
-
compute
@Nonnull protected abstract byte[] compute() throws java.io.IOException- Returns:
- The content
- Throws:
java.io.IOException- If an I/O error occurs
-
-