Package org.simpleframework.http.message
Class BoundaryConsumer
- java.lang.Object
-
- org.simpleframework.http.message.ArrayConsumer
-
- org.simpleframework.http.message.BoundaryConsumer
-
- All Implemented Interfaces:
ByteConsumer
class BoundaryConsumer extends ArrayConsumer
TheBoundaryConsumer
is used to consume a boundary for a multipart message. This ensures that the boundary complies with the multipart specification in that it ends with a carriage return and line feed. This consumer implementation can be used multiple times as its internal buffer can be cleared and reset.
-
-
Field Summary
Fields Modifier and Type Field Description private Allocator
allocator
This is used to allocate a buffer for for the boundary.private byte[]
boundary
This is the actual boundary value that is to be consumed.private Buffer
buffer
This is used to consume the contents of the consumed buffer.private static byte[]
LAST
This is the terminal token for a multipart boundary entity.private static byte[]
LINE
This is the terminal token for a multipart boundary line.private int
seek
This counts the number of characters read from the start.private static byte[]
TOKEN
This represents the start of the boundary line for the part.-
Fields inherited from class org.simpleframework.http.message.ArrayConsumer
array, chunk, count, done
-
-
Constructor Summary
Constructors Constructor Description BoundaryConsumer(Allocator allocator, byte[] boundary)
Constructor for theBoundaryConsumer
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
append(byte[] token)
This is used to append a token to the underlying buffer.void
clear()
This is used to clear the state of the of boundary consumer such that it can be reused.boolean
isEnd()
This is used to determine whether the boundary has been read from the underlying stream.protected void
process()
This does not perform any processing after the boundary has been consumed.protected int
scan()
This method is used to scan for the terminal token.private boolean
scan(byte[] data)
This is used to scan the specified token from the consumed bytes.-
Methods inherited from class org.simpleframework.http.message.ArrayConsumer
consume, isFinished, resize
-
-
-
-
Field Detail
-
LAST
private static final byte[] LAST
This is the terminal token for a multipart boundary entity.
-
LINE
private static final byte[] LINE
This is the terminal token for a multipart boundary line.
-
TOKEN
private static final byte[] TOKEN
This represents the start of the boundary line for the part.
-
allocator
private Allocator allocator
This is used to allocate a buffer for for the boundary.
-
buffer
private Buffer buffer
This is used to consume the contents of the consumed buffer.
-
boundary
private byte[] boundary
This is the actual boundary value that is to be consumed.
-
seek
private int seek
This counts the number of characters read from the start.
-
-
Constructor Detail
-
BoundaryConsumer
public BoundaryConsumer(Allocator allocator, byte[] boundary)
Constructor for theBoundaryConsumer
object. This is used to create a boundary consumer for validating boundaries and consuming them from a provided source. This is used to help in reading multipart messages by removing boundaries from the stream.- Parameters:
boundary
- this is the boundary value to be consumed
-
-
Method Detail
-
process
protected void process() throws java.io.IOException
This does not perform any processing after the boundary has been consumed. Because the boundary consumer is used only as a means to remove the boundary from the underlying stream there is no need to perform any processing of the value consumed.- Specified by:
process
in classArrayConsumer
- Throws:
java.io.IOException
-
scan
protected int scan() throws java.io.IOException
This method is used to scan for the terminal token. It searches for the token and returns the number of bytes in the buffer after the terminal token. Returning the excess bytes allows the consumer to reset the bytes within the consumer object.- Specified by:
scan
in classArrayConsumer
- Returns:
- this returns the number of excess bytes consumed
- Throws:
java.io.IOException
-
append
private void append(byte[] token) throws java.io.IOException
This is used to append a token to the underlying buffer. Adding various tokens ensures that the whole message is reconstructed and can be forwarded to any connected service if used as a proxy.- Parameters:
token
- this is the token that is to be appended- Throws:
java.io.IOException
-
scan
private boolean scan(byte[] data) throws java.io.IOException
This is used to scan the specified token from the consumed bytes. If the data scanned does not match the token provided then this will throw an exception to signify a bad boundary. This will return true only when the whole boundary has been consumed.- Parameters:
data
- this is the token to scan from the consumed bytes- Returns:
- this returns true of the token has been read
- Throws:
java.io.IOException
-
isEnd
public boolean isEnd()
This is used to determine whether the boundary has been read from the underlying stream. This is true only when the very last boundary has been read. This will be the boundary value that ends with the two-
characters.- Returns:
- this returns true with the terminal boundary is read
-
clear
public void clear()
This is used to clear the state of the of boundary consumer such that it can be reused. This is required as the multipart body may contain many parts, all delimited with the same boundary. Clearing allows the next boundary to be consumed.
-
-