Package org.glassfish.jersey.client
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 java.lang.Object implements ChunkParser
-
-
Constructor Summary
Constructors Modifier Constructor Description private
AbstractBoundaryParser()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 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
getDelimiterBufferSize()
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[]
readChunk(java.io.InputStream in)
Invoked byChunkedInput
to get the data for the next chunk.
-
-
-
Method Detail
-
readChunk
public byte[] readChunk(java.io.InputStream in) throws java.io.IOException
Description copied from interface:ChunkParser
Invoked byChunkedInput
to get the data for the next chunk.- Specified by:
readChunk
in interfaceChunkParser
- 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:
java.io.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 appendsb
param on thepos
position ofdelimiterBuffer
array and then starts the selection process with a newly created array.- Parameters:
b
- byte which will be added on thepos
position ofdelimiterBuffer
arraypos
- number of bytes from the delimiter buffer which will be used in processingdelimiterBuffer
- 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 bytedelimiterBuffer
- 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 ofa1
with head ofa2
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 thebuffer
.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.
-
-