Class AbstractMultipartFormat
java.lang.Object
org.apache.hc.client5.http.entity.mime.AbstractMultipartFormat
- Direct Known Subclasses:
HttpRFC6532Multipart,HttpRFC7578Multipart,HttpStrictMultipart,LegacyMultipart
HttpMultipart represents a collection of MIME multipart encoded content bodies.
- Since:
- 4.3
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final String(package private) final Charset(package private) static final org.apache.hc.core5.util.ByteArrayBufferprivate StringThe epilogue to be included after the multipart content.(package private) static final org.apache.hc.core5.util.ByteArrayBufferprivate StringThe preamble to be included before the multipart content.(package private) static final org.apache.hc.core5.util.ByteArrayBuffer -
Constructor Summary
ConstructorsConstructorDescriptionAbstractMultipartFormat(String boundary) AbstractMultipartFormat(Charset charset, String boundary) Creates an instance with the specified settings.AbstractMultipartFormat(Charset charset, String boundary, String preamble, String epilogue) Constructs a new instance ofAbstractMultipartFormatwith the given charset, boundary, preamble, and epilogue. -
Method Summary
Modifier and TypeMethodDescription(package private) voiddoWriteTo(OutputStream out, boolean writeContent) Writes the multipart message to the specified output stream.(package private) static org.apache.hc.core5.util.ByteArrayBufferencode(Charset charset, CharSequence string) protected abstract voidformatMultipartHeader(MultipartPart part, OutputStream out) Write the multipart header fields; depends on the style.abstract List<MultipartPart> getParts()longDetermines the total length of the multipart content (content length of individual parts plus that of extra elements required to delimit the parts from one another).(package private) static booleanisLineBreak(char ch) (package private) static CharSequence(package private) static voidwriteBytes(CharSequence s, OutputStream out) (package private) static voidwriteBytes(CharSequence s, Charset charset, OutputStream out) (package private) static voidwriteBytes(org.apache.hc.core5.util.ByteArrayBuffer b, OutputStream out) (package private) static voidwriteField(MimeField field, OutputStream out) (package private) static voidwriteField(MimeField field, Charset charset, OutputStream out) voidwriteTo(OutputStream out) Writes out the content in the multipart/form encoding.
-
Field Details
-
preamble
The preamble to be included before the multipart content. -
epilogue
The epilogue to be included after the multipart content. -
FIELD_SEP
static final org.apache.hc.core5.util.ByteArrayBuffer FIELD_SEP -
CR_LF
static final org.apache.hc.core5.util.ByteArrayBuffer CR_LF -
TWO_HYPHENS
static final org.apache.hc.core5.util.ByteArrayBuffer TWO_HYPHENS -
charset
-
boundary
-
-
Constructor Details
-
AbstractMultipartFormat
Creates an instance with the specified settings.- Parameters:
charset- the character set to use. May benull, in which caseStandardCharsets.ISO_8859_1is used.boundary- to use - must not benull- Throws:
IllegalArgumentException- if charset is null or boundary is null
-
AbstractMultipartFormat
Constructs a new instance ofAbstractMultipartFormatwith the given charset, boundary, preamble, and epilogue.- Parameters:
charset- the charset to use.boundary- the boundary string to use.preamble- the preamble string to use. Can benull.epilogue- the epilogue string to use. Can benull.- Throws:
IllegalArgumentException- if the boundary string isnull.
-
AbstractMultipartFormat
-
-
Method Details
-
encode
-
writeBytes
static void writeBytes(org.apache.hc.core5.util.ByteArrayBuffer b, OutputStream out) throws IOException - Throws:
IOException
-
writeBytes
- Throws:
IOException
-
writeBytes
- Throws:
IOException
-
isLineBreak
static boolean isLineBreak(char ch) -
stripLineBreaks
-
writeField
- Throws:
IOException
-
writeField
- Throws:
IOException
-
getParts
-
doWriteTo
Writes the multipart message to the specified output stream.If
writeContentistrue, the content of each part will also be written.If
preambleis notnull, it will be written before the first boundary. Ifepilogueis notnull, it will be written after the last boundary.- Parameters:
out- the output stream to write the message to.writeContent- whether to write the content of each part.- Throws:
IOException- if an I/O error occurs.
-
formatMultipartHeader
protected abstract void formatMultipartHeader(MultipartPart part, OutputStream out) throws IOException Write the multipart header fields; depends on the style.- Throws:
IOException
-
writeTo
Writes out the content in the multipart/form encoding. This method produces slightly different formatting depending on its compatibility mode.- Throws:
IOException
-
getTotalLength
public long getTotalLength()Determines the total length of the multipart content (content length of individual parts plus that of extra elements required to delimit the parts from one another). If any of the @{link BodyPart}s contained in this object is of a streaming entity of unknown length the total length is also unknown.This method buffers only a small amount of data in order to determine the total length of the entire entity. The content of individual parts is not buffered.
- Returns:
- total length of the multipart entity if known,
-1otherwise.
-