Class ChunkedInput<T>
- Type Parameters:
T- chunk type.
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
EventInput
- Author:
- Marek Potociar
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedChunkedInput(Type chunkType, InputStream inputStream, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, MessageBodyWorkers messageBodyWorkers, PropertiesDelegate propertiesDelegate) Package-private constructor used by theChunkedInputReader. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static ChunkParsercreateMultiParser(String... boundaries) Create a new chunk multi-parser that will split the response entity input stream based on multiple fixed boundary strings.static ChunkParsercreateParser(byte[] boundary) Create new chunk parser that will split the response entity input stream based on a fixed boundary sequence of bytes.static ChunkParsercreateParser(String boundary) Create new chunk parser that will split the response entity input stream based on a fixed boundary string.Get chunk data media type.Get the underlying chunk parser.booleanisClosed()Check if the chunked input has been closed.read()Read next chunk from the response stream and convert it to a Java instance using thechunk media type.voidsetChunkType(MediaType mediaType) Set custom chunk data media type.voidsetChunkType(String mediaType) Set custom chunk data media type from a string value.voidsetParser(ChunkParser parser) Set new chunk parser.Methods inherited from class jakarta.ws.rs.core.GenericType
equals, forInstance, getRawType, getType, hashCode, toString
-
Constructor Details
-
ChunkedInput
protected ChunkedInput(Type chunkType, InputStream inputStream, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, MessageBodyWorkers messageBodyWorkers, PropertiesDelegate propertiesDelegate) Package-private constructor used by theChunkedInputReader.- Parameters:
chunkType- chunk type.inputStream- response input stream.annotations- annotations associated with response entity.mediaType- response entity media type.headers- response headers.messageBodyWorkers- message body workers.propertiesDelegate- properties delegate for this request/response.
-
-
Method Details
-
createParser
Create new chunk parser that will split the response entity input stream based on a fixed boundary string.- Parameters:
boundary- chunk boundary.- Returns:
- new fixed boundary string-based chunk parser.
-
createParser
Create new chunk parser that will split the response entity input stream based on a fixed boundary sequence of bytes.- Parameters:
boundary- chunk boundary.- Returns:
- new fixed boundary sequence-based chunk parser.
-
createMultiParser
Create a new chunk multi-parser that will split the response entity input stream based on multiple fixed boundary strings.- Parameters:
boundaries- chunk boundaries.- Returns:
- new fixed boundary string-based chunk parser.
-
getParser
Get the underlying chunk parser.Note: Access to internal chunk parser is not a thread-safe operation and has to be explicitly synchronized in case the chunked input is used from multiple threads.
- Returns:
- underlying chunk parser.
-
setParser
Set new chunk parser.Note: Access to internal chunk parser is not a thread-safe operation and has to be explicitly synchronized in case the chunked input is used from multiple threads.
- Parameters:
parser- new chunk parser.
-
getChunkType
Get chunk data media type. Default chunk data media type is derived from the value of the response "Content-Type" header field. This default value may be manually overridden bysettinga custom non-nullchunk media type value.Note: Access to internal chunk media type is not a thread-safe operation and has to be explicitly synchronized in case the chunked input is used from multiple threads.
- Returns:
- media type specific to each chunk of data.
-
setChunkType
Set custom chunk data media type. By default, chunk data media type is derived from the value of the response "Content-Type" header field. Using this methods will override the default chunk media type value and set it to a custom non-nullchunk media type. Once this method is invoked, all subsequentchunk readswill use the newly set chunk media type when selecting the properMessageBodyReaderfor chunk de-serialization.Note: Access to internal chunk media type is not a thread-safe operation and has to be explicitly synchronized in case the chunked input is used from multiple threads.
- Parameters:
mediaType- custom chunk data media type. Must not benull.- Throws:
IllegalArgumentException- in case themediaTypeisnull.
-
setChunkType
Set custom chunk data media type from a string value.Note: Access to internal chunk media type is not a thread-safe operation and has to be explicitly synchronized in case the chunked input is used from multiple threads.
- Parameters:
mediaType- custom chunk data media type. Must not benull.- Throws:
IllegalArgumentException- in case themediaTypecannot be parsed into a validMediaTypeinstance or isnull.- See Also:
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isClosed
public boolean isClosed()Check if the chunked input has been closed.- Returns:
trueif this chunked input has been closed,falseotherwise.
-
read
Read next chunk from the response stream and convert it to a Java instance using thechunk media type. The method returnsnullif the underlying entity input stream has been closed (either implicitly or explicitly by calling theclose()method).Note: Access to internal chunk parser is not a thread-safe operation and has to be explicitly synchronized in case the chunked input is used from multiple threads.
- Returns:
- next streamed chunk or
nullif the underlying entity input stream has been closed while reading next chunk data. - Throws:
IllegalStateException- in case this chunked input has been closed.
-