Class ChunkedInput.AbstractBoundaryParser

java.lang.Object
org.glassfish.jersey.client.ChunkedInput.AbstractBoundaryParser
All Implemented Interfaces:
ChunkParser
Direct Known Subclasses:
ChunkedInput.FixedBoundaryParser, ChunkedInput.FixedMultiBoundaryParser
Enclosing class:
ChunkedInput<T>

private abstract static class ChunkedInput.AbstractBoundaryParser extends Object implements ChunkParser
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) abstract byte[]
    getDelimiter(byte b, int pos, byte[] delimiterBuffer)
    Selects a delimiter which corresponds to delimiter buffer.
    (package private) abstract byte[]
    getDelimiter(int pos, byte[] delimiterBuffer)
    Selects a delimiter which corresponds to delimiter buffer.
    (package private) abstract int
    Returns a delimiter buffer size depending on the selected strategy.
    private static int
    matchTail(byte[] buffer, int offset, int length, byte[] pattern)
    Tries to find an element intersection between two arrays in a way that intersecting elements must be at the tail of the first array and at the beginning of the second array.
    byte[]
    Invoked by ChunkedInput to get the data for the next chunk.

    Methods inherited from class java.lang.Object

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

    • AbstractBoundaryParser

      private AbstractBoundaryParser()
  • Method Details

    • readChunk

      public byte[] readChunk(InputStream in) throws IOException
      Description copied from interface: ChunkParser
      Invoked by ChunkedInput to get the data for the next chunk.
      Specified by:
      readChunk in interface ChunkParser
      Parameters:
      in - response entity input stream.
      Returns:
      next chunk data represented as an array of bytes, or null if no more chunks are available.
      Throws:
      IOException - in case reading from the response entity fails.
    • getDelimiter

      abstract byte[] getDelimiter(byte b, int pos, byte[] delimiterBuffer)
      Selects a delimiter which corresponds to delimiter buffer. Method automatically appends b param on the pos position of delimiterBuffer array and then starts the selection process with a newly created array.
      Parameters:
      b - byte which will be added on the pos position of delimiterBuffer array
      pos - number of bytes from the delimiter buffer which will be used in processing
      delimiterBuffer - current content of the delimiter buffer
      Returns:
      delimiter which corresponds to delimiterBuffer
    • getDelimiter

      abstract byte[] getDelimiter(int pos, byte[] delimiterBuffer)
      Selects a delimiter which corresponds to delimiter buffer.
      Parameters:
      pos - position of the last read byte
      delimiterBuffer - number of bytes from the delimiter buffer which will be used in processing
      Returns:
      delimiter which corresponds to delimiterBuffer
    • getDelimiterBufferSize

      abstract int getDelimiterBufferSize()
      Returns a delimiter buffer size depending on the selected strategy.

      If a strategy has multiple registered delimiters, then the delimiter buffer should be a length of the longest delimiter.

      Returns:
      length of the delimiter buffer
    • matchTail

      private static int matchTail(byte[] buffer, int offset, int length, byte[] pattern)
      Tries to find an element intersection between two arrays in a way that intersecting elements must be at the tail of the first array and at the beginning of the second array.

      For example, consider the following two arrays:

       a1: {a, b, c, d, e}
       a2: {d, e, f, g}
       
      In this example, the intersection of tail of a1 with head of a2 is {d, e} and consists of 2 overlapping elements.

      The method takes the first array represented as a sub-array in buffer demarcated by an offset and length. The second array is a fixed pattern to be matched. The method then compares the tail of the array in the buffer with the head of the pattern and returns the number of intersecting elements, or zero in case the two arrays do not intersect tail to head.
      Parameters:
      buffer - byte buffer containing the array whose tail to intersect.
      offset - start of the array to be tail-matched in the buffer.
      length - length of the array to be tail-matched.
      pattern - pattern to be head-matched.
      Returns:
      0 if any part of the tail of the array in the buffer does not match any part of the head of the pattern, otherwise returns number of overlapping elements.