Package org.simpleframework.http.message
Class PartBodyConsumer
- java.lang.Object
-
- org.simpleframework.http.message.PartBodyConsumer
-
- All Implemented Interfaces:
BodyConsumer
,ByteConsumer
class PartBodyConsumer extends java.lang.Object implements BodyConsumer
ThePartBodyConsumer
object is used to consume a part the contents of a multipart body. This will consume the part and add it to a part list, once the part has been consumed and added to the part list a terminal token is consumed, which is a carriage return and line feed.
-
-
Field Summary
Fields Modifier and Type Field Description private ContentConsumer
content
This is used to consume the content from the multipart upload.private static byte[]
LINE
This is the token that is consumed after the content body.private ByteConsumer
token
This is used to consume the final terminal token from the part.
-
Constructor Summary
Constructors Constructor Description PartBodyConsumer(Allocator allocator, Segment segment, byte[] boundary)
Constructor for thePartBodyConsumer
object.PartBodyConsumer(Allocator allocator, Segment segment, PartSeries series, byte[] boundary)
Constructor for thePartBodyConsumer
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
consume(ByteCursor cursor)
This is used to consume the part body from the cursor.Body
getBody()
This is used to acquire the body that has been consumed.boolean
isFinished()
This is used to determine whether the part body has been read from the cursor successfully.
-
-
-
Field Detail
-
LINE
private static final byte[] LINE
This is the token that is consumed after the content body.
-
content
private ContentConsumer content
This is used to consume the content from the multipart upload.
-
token
private ByteConsumer token
This is used to consume the final terminal token from the part.
-
-
Constructor Detail
-
PartBodyConsumer
public PartBodyConsumer(Allocator allocator, Segment segment, byte[] boundary)
Constructor for thePartBodyConsumer
object. This is used to create a consumer that reads the body of a part in a multipart request body. The terminal token must be provided so that the end of the part body can be determined.- Parameters:
allocator
- this is used to allocate the internal buffersegment
- this represents the headers for the part bodyboundary
- this is the message boundary for the body part
-
PartBodyConsumer
public PartBodyConsumer(Allocator allocator, Segment segment, PartSeries series, byte[] boundary)
Constructor for thePartBodyConsumer
object. This is used to create a consumer that reads the body of a part in a multipart request body. The terminal token must be provided so that the end of the part body can be determined.- Parameters:
allocator
- this is used to allocate the internal buffersegment
- this represents the headers for the part bodyseries
- this is the part list that this body belongs inboundary
- this is the message boundary for the body part
-
-
Method Detail
-
getBody
public Body getBody()
This is used to acquire the body that has been consumed. This will return a body which can be used to read the content of the message, also if the request is multipart upload then all of the parts are provided asAttachment
objects. Each part can then be read as an individual message.- Specified by:
getBody
in interfaceBodyConsumer
- Returns:
- the body that has been consumed by this instance
-
consume
public void consume(ByteCursor cursor) throws java.io.IOException
This is used to consume the part body from the cursor. This initially reads the body of the part, which represents the actual payload exposed via thePart
interface once the payload has been consumed the terminal is consumed.- Specified by:
consume
in interfaceByteConsumer
- Parameters:
cursor
- this is the cursor to consume the body from- Throws:
java.io.IOException
-
isFinished
public boolean isFinished()
This is used to determine whether the part body has been read from the cursor successfully. In order to determine if all of the bytes have been read successfully this will check to see of the terminal token had been consumed.- Specified by:
isFinished
in interfaceByteConsumer
- Returns:
- true if the part body and terminal have been read
-
-