Top Description Fields Constructors Methods
org.apache.hc.client5.http.entity.mime

pack-priv abstract Class AbstractMultipartFormat

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.hc.client5.http.entity.mime.HttpRFC6532Multipart, org.apache.hc.client5.http.entity.mime.HttpRFC7578Multipart, org.apache.hc.client5.http.entity.mime.HttpStrictMultipart, org.apache.hc.client5.http.entity.mime.LegacyMultipart
Imports
java.io.ByteArrayOutputStream, .IOException, .OutputStream, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .StandardCharsets, java.util.List, org.apache.hc.core5.util.Args, .ByteArrayBuffer

HttpMultipart represents a collection of MIME multipart encoded content bodies.
Since
4.3

Field Summary

Modifier and TypeField and Description
pack-priv final String
pack-priv final Charset
pack-priv static final ByteArrayBuffer
private String
epilogue

The epilogue to be included after the multipart content.

pack-priv static final ByteArrayBuffer
private String
preamble

The preamble to be included before the multipart content.

pack-priv static final ByteArrayBuffer

Constructor Summary

AccessConstructor and Description
public
AbstractMultipartFormat(final Charset
the character set to use. May be null, in which case StandardCharsets#ISO_8859_1 is used.
charset
,
final String
to use - must not be null
boundary
)

Creates an instance with the specified settings.

public
AbstractMultipartFormat(final Charset
the charset to use.
charset
,
final String
the boundary string to use.
boundary
,
final String
the preamble string to use. Can be null.
preamble
,
final String
the epilogue string to use. Can be null.
epilogue
)

Constructs a new instance of AbstractMultipartFormat with the given charset, boundary, preamble, and epilogue.

public

Method Summary

Modifier and TypeMethod and Description
pack-priv void
doWriteTo(final OutputStream
the output stream to write the message to.
out
,
final boolean
whether to write the content of each part.
writeContent
)

Writes the multipart message to the specified output stream.

pack-priv static ByteArrayBuffer
encode(final Charset charset, final CharSequence string)

protected abstract void
formatMultipartHeader(final MultipartPart part, final OutputStream out)

Write the multipart header fields; depends on the style.

public abstract List<MultipartPart>
public long

Returns:

total length of the multipart entity if known, -1 otherwise.
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).

pack-priv static boolean
isLineBreak(final char ch)

pack-priv static CharSequence
pack-priv static void
pack-priv static void
writeBytes(final CharSequence s, final Charset charset, final OutputStream out)

pack-priv static void
writeBytes(final CharSequence s, final OutputStream out)

pack-priv static void
writeField(final MimeField field, final OutputStream out)

pack-priv static void
writeField(final MimeField field, final Charset charset, final OutputStream out)

public void
writeTo(final OutputStream out)

Writes out the content in the multipart/form encoding.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

boundaryback to summary
pack-priv final String boundary
charsetback to summary
pack-priv final Charset charset
CR_LFback to summary
pack-priv static final ByteArrayBuffer CR_LF
epilogueback to summary
private String epilogue

The epilogue to be included after the multipart content.

FIELD_SEPback to summary
pack-priv static final ByteArrayBuffer FIELD_SEP
preambleback to summary
private String preamble

The preamble to be included before the multipart content.

TWO_HYPHENSback to summary
pack-priv static final ByteArrayBuffer TWO_HYPHENS

Constructor Detail

AbstractMultipartFormatback to summary
public AbstractMultipartFormat(final Charset charset, final String boundary)

Creates an instance with the specified settings.

Parameters
charset:Charset

the character set to use. May be null, in which case StandardCharsets#ISO_8859_1 is used.

boundary:String

to use - must not be null

Exceptions
IllegalArgumentException:
if charset is null or boundary is null
AbstractMultipartFormatback to summary
public AbstractMultipartFormat(final Charset charset, final String boundary, final String preamble, final String epilogue)

Constructs a new instance of AbstractMultipartFormat with the given charset, boundary, preamble, and epilogue.

Parameters
charset:Charset

the charset to use.

boundary:String

the boundary string to use.

preamble:String

the preamble string to use. Can be null.

epilogue:String

the epilogue string to use. Can be null.

Exceptions
IllegalArgumentException:
if the boundary string is null.
AbstractMultipartFormatback to summary
public AbstractMultipartFormat(final String boundary)

Method Detail

doWriteToback to summary
pack-priv void doWriteTo(final OutputStream out, final boolean writeContent) throws IOException

Writes the multipart message to the specified output stream.

If writeContent is true, the content of each part will also be written.

If preamble is not null, it will be written before the first boundary. If epilogue is not null, it will be written after the last boundary.

Parameters
out:OutputStream

the output stream to write the message to.

writeContent:boolean

whether to write the content of each part.

Exceptions
IOException:
if an I/O error occurs.
encodeback to summary
pack-priv static ByteArrayBuffer encode(final Charset charset, final CharSequence string)
formatMultipartHeaderback to summary
protected abstract void formatMultipartHeader(final MultipartPart part, final OutputStream out) throws IOException

Write the multipart header fields; depends on the style.

getPartsback to summary
public abstract List<MultipartPart> getParts()
getTotalLengthback to summary
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:long

total length of the multipart entity if known, -1 otherwise.

isLineBreakback to summary
pack-priv static boolean isLineBreak(final char ch)
stripLineBreaksback to summary
pack-priv static CharSequence stripLineBreaks(final CharSequence s)
writeBytesback to summary
pack-priv static void writeBytes(final ByteArrayBuffer b, final OutputStream out) throws IOException
writeBytesback to summary
pack-priv static void writeBytes(final CharSequence s, final Charset charset, final OutputStream out) throws IOException
writeBytesback to summary
pack-priv static void writeBytes(final CharSequence s, final OutputStream out) throws IOException
writeFieldback to summary
pack-priv static void writeField(final MimeField field, final OutputStream out) throws IOException
writeFieldback to summary
pack-priv static void writeField(final MimeField field, final Charset charset, final OutputStream out) throws IOException
writeToback to summary
public void writeTo(final OutputStream out) throws IOException

Writes out the content in the multipart/form encoding. This method produces slightly different formatting depending on its compatibility mode.