Class BoundaryConsumer

java.lang.Object
org.simpleframework.http.message.ArrayConsumer
org.simpleframework.http.message.BoundaryConsumer
All Implemented Interfaces:
ByteConsumer

class BoundaryConsumer extends ArrayConsumer
The BoundaryConsumer 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
    This is used to allocate a buffer for for the boundary.
    private byte[]
    This is the actual boundary value that is to be consumed.
    private Buffer
    This is used to consume the contents of the consumed buffer.
    private static final byte[]
    This is the terminal token for a multipart boundary entity.
    private static final byte[]
    This is the terminal token for a multipart boundary line.
    private int
    This counts the number of characters read from the start.
    private static final byte[]
    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 the BoundaryConsumer object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    append(byte[] token)
    This is used to append a token to the underlying buffer.
    void
    This is used to clear the state of the of boundary consumer such that it can be reused.
    boolean
    This is used to determine whether the boundary has been read from the underlying stream.
    protected void
    This does not perform any processing after the boundary has been consumed.
    protected int
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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 Details

    • BoundaryConsumer

      public BoundaryConsumer(Allocator allocator, byte[] boundary)
      Constructor for the BoundaryConsumer 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 Details

    • process

      protected void process() throws 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 class ArrayConsumer
      Throws:
      IOException
    • scan

      protected int scan() throws 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 class ArrayConsumer
      Returns:
      this returns the number of excess bytes consumed
      Throws:
      IOException
    • append

      private void append(byte[] token) throws 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:
      IOException
    • scan

      private boolean scan(byte[] data) throws 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:
      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.