Class ByteArrayBody
java.lang.Object
org.apache.hc.client5.http.entity.mime.AbstractContentBody
org.apache.hc.client5.http.entity.mime.ByteArrayBody
- All Implemented Interfaces:
ContentBody
,ContentDescriptor
Binary body part backed by a byte array.
- Since:
- 4.1
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionByteArrayBody
(byte[] data, String filename) Creates a new ByteArrayBody.ByteArrayBody
(byte[] data, org.apache.hc.core5.http.ContentType contentType) Public constructor that creates a new ByteArrayBody.ByteArrayBody
(byte[] data, org.apache.hc.core5.http.ContentType contentType, String filename) -
Method Summary
Modifier and TypeMethodDescriptionThe body descriptors character set, defaulted appropriately for the MIME type.long
Returns the body descriptors content-length.void
writeTo
(OutputStream out) Methods inherited from class org.apache.hc.client5.http.entity.mime.AbstractContentBody
getContentType, getMediaType, getMimeType, getSubType
-
Field Details
-
data
private final byte[] dataThe contents of the file contained in this part. -
filename
The name of the file contained in this part.
-
-
Constructor Details
-
ByteArrayBody
public ByteArrayBody(byte[] data, org.apache.hc.core5.http.ContentType contentType, String filename) - Since:
- 4.3
-
ByteArrayBody
public ByteArrayBody(byte[] data, org.apache.hc.core5.http.ContentType contentType) Public constructor that creates a new ByteArrayBody.- Parameters:
data
- the array of byte.contentType
- theContentType
- Since:
- 5.2
-
ByteArrayBody
Creates a new ByteArrayBody.- Parameters:
data
- The contents of the file contained in this part.filename
- The name of the file contained in this part.
-
-
Method Details
-
getFilename
-
writeTo
- Throws:
IOException
-
getCharset
Description copied from interface:ContentDescriptor
The body descriptors character set, defaulted appropriately for the MIME type.
For
TEXT
types, this will be defaulted tous-ascii
. For other types, when the charset parameter is missing this property will be null.- Specified by:
getCharset
in interfaceContentDescriptor
- Overrides:
getCharset
in classAbstractContentBody
- Returns:
- Character set, which has been parsed from the
content-type definition. Not null for
TEXT
types, when unset will be set to defaultus-ascii
. For other types, when unset, null will be returned.
-
getContentLength
public long getContentLength()Description copied from interface:ContentDescriptor
Returns the body descriptors content-length.- Returns:
- Content length, if known, or -1, to indicate the absence of a content-length header.
-