Class ChunkedInput<T>
- java.lang.Object
-
- javax.ws.rs.core.GenericType<T>
-
- org.glassfish.jersey.client.ChunkedInput<T>
-
- Type Parameters:
T- chunk type.
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ChunkedInput<T> extends javax.ws.rs.core.GenericType<T> implements java.io.CloseableResponse entity type used for receiving messages in "typed" chunks. This data type is useful for consuming partial responses from large or continuous data input streams.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classChunkedInput.AbstractBoundaryParserprivate static classChunkedInput.FixedBoundaryParserprivate static classChunkedInput.FixedMultiBoundaryParser
-
Field Summary
Fields Modifier and Type Field Description private java.lang.annotation.Annotation[]annotationsprivate java.util.concurrent.atomic.AtomicBooleanclosedprivate javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>headersprivate java.io.InputStreaminputStreamprivate static java.util.logging.LoggerLOGGERprivate javax.ws.rs.core.MediaTypemediaTypeprivate MessageBodyWorkersmessageBodyWorkersprivate ChunkParserparserprivate PropertiesDelegatepropertiesDelegate
-
Constructor Summary
Constructors Modifier Constructor Description protectedChunkedInput(java.lang.reflect.Type chunkType, java.io.InputStream inputStream, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers, MessageBodyWorkers messageBodyWorkers, PropertiesDelegate propertiesDelegate)Package-private constructor used by theChunkedInputReader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static ChunkParsercreateMultiParser(java.lang.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(java.lang.String boundary)Create new chunk parser that will split the response entity input stream based on a fixed boundary string.javax.ws.rs.core.MediaTypegetChunkType()Get chunk data media type.ChunkParsergetParser()Get the underlying chunk parser.booleanisClosed()Check if the chunked input has been closed.Tread()Read next chunk from the response stream and convert it to a Java instance using thechunk media type.voidsetChunkType(java.lang.String mediaType)Set custom chunk data media type from a string value.voidsetChunkType(javax.ws.rs.core.MediaType mediaType)Set custom chunk data media type.voidsetParser(ChunkParser parser)Set new chunk parser.
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
closed
private final java.util.concurrent.atomic.AtomicBoolean closed
-
parser
private ChunkParser parser
-
mediaType
private javax.ws.rs.core.MediaType mediaType
-
inputStream
private final java.io.InputStream inputStream
-
annotations
private final java.lang.annotation.Annotation[] annotations
-
headers
private final javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers
-
messageBodyWorkers
private final MessageBodyWorkers messageBodyWorkers
-
propertiesDelegate
private final PropertiesDelegate propertiesDelegate
-
-
Constructor Detail
-
ChunkedInput
protected ChunkedInput(java.lang.reflect.Type chunkType, java.io.InputStream inputStream, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.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 Detail
-
createParser
public static ChunkParser createParser(java.lang.String boundary)
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
public static ChunkParser createParser(byte[] boundary)
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
public static ChunkParser createMultiParser(java.lang.String... boundaries)
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
public ChunkParser 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
public void setParser(ChunkParser parser)
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
public javax.ws.rs.core.MediaType 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
public void setChunkType(javax.ws.rs.core.MediaType mediaType) throws java.lang.IllegalArgumentExceptionSet 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:
java.lang.IllegalArgumentException- in case themediaTypeisnull.
-
setChunkType
public void setChunkType(java.lang.String mediaType) throws java.lang.IllegalArgumentExceptionSet 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:
java.lang.IllegalArgumentException- in case themediaTypecannot be parsed into a validMediaTypeinstance or isnull.- See Also:
setChunkType(javax.ws.rs.core.MediaType)
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
isClosed
public boolean isClosed()
Check if the chunked input has been closed.- Returns:
trueif this chunked input has been closed,falseotherwise.
-
read
public T read() throws java.lang.IllegalStateException
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:
java.lang.IllegalStateException- in case this chunked input has been closed.
-
-