Class PartList
HttpPart instances that also implements HttpBody for
URL-encoded form submission.
Use this class to send a application/x-www-form-urlencoded request body, or to represent
a collection of query parameters, form fields, or path variables.
Create instances via the static factory methods:
See Also:
- Since:
- 9.2.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic PartListempty()Creates an emptyPartList.longReturns the content length in bytes, or-1if unknown.Returns the MIME content type of this body, e.g.Returns the first part with the given name (case-sensitive), ornull if absent.getParts()Returns the parts in this list.booleanisEmpty()Returnstrue if this list is empty.booleanReturnstrueif this body can be written more than once.iterator()static PartListCreates aPartListfrom the given list of parts.static PartListCreates aPartListfrom the given parts.static PartListCreates aPartListfrom alternating name/value string pairs.intsize()Returns the number of parts in this list.toString()voidwriteTo(OutputStream out) Writes the body content to the given output stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
empty
Creates an emptyPartList.- Returns:
- A new instance. Never
null .
-
of
Creates aPartListfrom the given parts.- Parameters:
parts- The parts. Must not benull .- Returns:
- A new instance. Never
null .
-
of
Creates aPartListfrom the given list of parts.- Parameters:
parts- The parts. Must not benull .- Returns:
- A new instance. Never
null .
-
ofPairs
Creates aPartListfrom alternating name/value string pairs.The number of arguments must be even.
- Parameters:
pairs- Alternating name/value strings. Must not benull . Length must be even.- Returns:
- A new instance. Never
null . - Throws:
IllegalArgumentException- If the number of arguments is odd.
-
getParts
Returns the parts in this list.- Returns:
- An unmodifiable list of parts. Never
null .
-
getFirst
Returns the first part with the given name (case-sensitive), ornull if absent.- Parameters:
name- The part name. Must not benull .- Returns:
- The first matching part, or
null if absent.
-
size
Returns the number of parts in this list.- Returns:
- The number of parts.
-
isEmpty
Returnstrue if this list is empty.- Returns:
true if empty.
-
iterator
-
getContentType
Description copied from interface:HttpBodyReturns the MIME content type of this body, e.g."application/json; charset=UTF-8".- Specified by:
getContentTypein interfaceHttpBody- Returns:
- The content type, or
null if unknown.
-
getContentLength
Description copied from interface:HttpBodyReturns the content length in bytes, or-1if unknown.Implementations that buffer content may return the exact length; streaming implementations should return
-1to cause the transport to use chunked transfer encoding.- Specified by:
getContentLengthin interfaceHttpBody- Returns:
- The content length, or
-1if unknown.
-
isRepeatable
Description copied from interface:HttpBodyReturnstrueif this body can be written more than once.Streaming bodies backed by a one-shot
InputStreamshould returnfalse. Buffered bodies (byte arrays, strings, files) should returntrue.- Specified by:
isRepeatablein interfaceHttpBody- Returns:
trueif repeatable.
-
writeTo
Description copied from interface:HttpBodyWrites the body content to the given output stream.Implementations must not close
out.- Specified by:
writeToin interfaceHttpBody- Parameters:
out- The stream to write to. Nevernull .- Throws:
IOException- If an I/O error occurs.
-
toString
-