Class AbstractMultipartFormat
- java.lang.Object
-
- org.apache.hc.client5.http.entity.mime.AbstractMultipartFormat
-
- Direct Known Subclasses:
HttpRFC6532Multipart,HttpRFC7578Multipart,HttpStrictMultipart,LegacyMultipart
abstract class AbstractMultipartFormat extends java.lang.ObjectHttpMultipart represents a collection of MIME multipart encoded content bodies.- Since:
- 4.3
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Stringboundary(package private) java.nio.charset.Charsetcharset(package private) static org.apache.hc.core5.util.ByteArrayBufferCR_LFprivate java.lang.StringepilogueThe epilogue to be included after the multipart content.(package private) static org.apache.hc.core5.util.ByteArrayBufferFIELD_SEPprivate java.lang.StringpreambleThe preamble to be included before the multipart content.(package private) static org.apache.hc.core5.util.ByteArrayBufferTWO_HYPHENS
-
Constructor Summary
Constructors Constructor Description AbstractMultipartFormat(java.lang.String boundary)AbstractMultipartFormat(java.nio.charset.Charset charset, java.lang.String boundary)Creates an instance with the specified settings.AbstractMultipartFormat(java.nio.charset.Charset charset, java.lang.String boundary, java.lang.String preamble, java.lang.String epilogue)Constructs a new instance ofAbstractMultipartFormatwith the given charset, boundary, preamble, and epilogue.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) voiddoWriteTo(java.io.OutputStream out, boolean writeContent)Writes the multipart message to the specified output stream.(package private) static org.apache.hc.core5.util.ByteArrayBufferencode(java.nio.charset.Charset charset, java.lang.CharSequence string)protected abstract voidformatMultipartHeader(MultipartPart part, java.io.OutputStream out)Write the multipart header fields; depends on the style.abstract java.util.List<MultipartPart>getParts()longgetTotalLength()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).(package private) static booleanisLineBreak(char ch)(package private) static java.lang.CharSequencestripLineBreaks(java.lang.CharSequence s)(package private) static voidwriteBytes(java.lang.CharSequence s, java.io.OutputStream out)(package private) static voidwriteBytes(java.lang.CharSequence s, java.nio.charset.Charset charset, java.io.OutputStream out)(package private) static voidwriteBytes(org.apache.hc.core5.util.ByteArrayBuffer b, java.io.OutputStream out)(package private) static voidwriteField(MimeField field, java.io.OutputStream out)(package private) static voidwriteField(MimeField field, java.nio.charset.Charset charset, java.io.OutputStream out)voidwriteTo(java.io.OutputStream out)Writes out the content in the multipart/form encoding.
-
-
-
Field Detail
-
preamble
private java.lang.String preamble
The preamble to be included before the multipart content.
-
epilogue
private java.lang.String 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
final java.nio.charset.Charset charset
-
boundary
final java.lang.String boundary
-
-
Constructor Detail
-
AbstractMultipartFormat
public AbstractMultipartFormat(java.nio.charset.Charset charset, java.lang.String boundary)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:
java.lang.IllegalArgumentException- if charset is null or boundary is null
-
AbstractMultipartFormat
public AbstractMultipartFormat(java.nio.charset.Charset charset, java.lang.String boundary, java.lang.String preamble, java.lang.String epilogue)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:
java.lang.IllegalArgumentException- if the boundary string isnull.
-
AbstractMultipartFormat
public AbstractMultipartFormat(java.lang.String boundary)
-
-
Method Detail
-
encode
static org.apache.hc.core5.util.ByteArrayBuffer encode(java.nio.charset.Charset charset, java.lang.CharSequence string)
-
writeBytes
static void writeBytes(org.apache.hc.core5.util.ByteArrayBuffer b, java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
writeBytes
static void writeBytes(java.lang.CharSequence s, java.nio.charset.Charset charset, java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
writeBytes
static void writeBytes(java.lang.CharSequence s, java.io.OutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
isLineBreak
static boolean isLineBreak(char ch)
-
stripLineBreaks
static java.lang.CharSequence stripLineBreaks(java.lang.CharSequence s)
-
writeField
static void writeField(MimeField field, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
writeField
static void writeField(MimeField field, java.nio.charset.Charset charset, java.io.OutputStream out) throws java.io.IOException
- Throws:
java.io.IOException
-
getParts
public abstract java.util.List<MultipartPart> getParts()
-
doWriteTo
void doWriteTo(java.io.OutputStream out, boolean writeContent) throws java.io.IOExceptionWrites 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:
java.io.IOException- if an I/O error occurs.
-
formatMultipartHeader
protected abstract void formatMultipartHeader(MultipartPart part, java.io.OutputStream out) throws java.io.IOException
Write the multipart header fields; depends on the style.- Throws:
java.io.IOException
-
writeTo
public void writeTo(java.io.OutputStream out) throws java.io.IOExceptionWrites out the content in the multipart/form encoding. This method produces slightly different formatting depending on its compatibility mode.- Throws:
java.io.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.
-
-