Package org.simpleframework.http.message
Class PartConsumer
- java.lang.Object
-
- org.simpleframework.http.message.PartConsumer
-
- All Implemented Interfaces:
ByteConsumer
class PartConsumer extends java.lang.Object implements ByteConsumer
ThePartConsumerobject is used to consume a part from a part list. A part consists of a header and a body, which can be either a simple chunk of data or another part list. This must be able to cope with either a simple body or a part list.
-
-
Field Summary
Fields Modifier and Type Field Description private BodyConsumerbodyThis is used to consume the body data from the part.private ByteConsumercurrentThis is the current consumer used to read from the cursor.private PartFactoryfactoryThis is used to determine what type the body data is.private SegmentConsumerheaderThis is used to consume the header message of the part.private PartSeriesseriesThis is used to add the consumed parts to when finished.private byte[]terminalThis is the terminal token that ends the part payload.
-
Constructor Summary
Constructors Constructor Description PartConsumer(Allocator allocator, PartSeries series, byte[] terminal, long length)Constructor for thePartConsumerobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconsume(ByteCursor cursor)This is used to consume the part body from the cursor.private BodyConsumergetConsumer()This is used to create a new body consumer used to consume the part body from for the list.booleanisFinished()This is used to determine whether the part body has been read from the cursor successfully.
-
-
-
Field Detail
-
header
private SegmentConsumer header
This is used to consume the header message of the part.
-
body
private BodyConsumer body
This is used to consume the body data from the part.
-
factory
private PartFactory factory
This is used to determine what type the body data is.
-
series
private PartSeries series
This is used to add the consumed parts to when finished.
-
current
private ByteConsumer current
This is the current consumer used to read from the cursor.
-
terminal
private byte[] terminal
This is the terminal token that ends the part payload.
-
-
Constructor Detail
-
PartConsumer
public PartConsumer(Allocator allocator, PartSeries series, byte[] terminal, long length)
Constructor for thePartConsumerobject. This is used to create a consumer used to read the contents of a part and the boundary that terminates the content. Any parts that are created by this are added to the provided part list.- Parameters:
allocator- this is the allocator used to creat buffersseries- this is the part list used to store the partsterminal- this is the terminal token for the partlength- this is the length of the parent part series
-
-
Method Detail
-
getConsumer
private BodyConsumer getConsumer()
This is used to create a new body consumer used to consume the part body from for the list. This will ensure that the part data is created based on the part header consumed. The types of part supported are part lists and part body.- Returns:
- this returns a consumed for the part content
-
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 thePartinterface once the payload has been consumed the terminal is consumed.- Specified by:
consumein 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:
isFinishedin interfaceByteConsumer- Returns:
- true if the part body and terminal have been read
-
-