org.glassfish.jersey.client
Class ChunkedInput<T>

java.lang.Object
  extended by javax.ws.rs.core.GenericType<T>
      extended by org.glassfish.jersey.client.ChunkedInput<T>
Type Parameters:
T - chunk type.
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
EventInput

public class ChunkedInput<T>
extends GenericType<T>
implements Closeable

Response 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.

Author:
Marek Potociar (marek.potociar at oracle.com)

Constructor Summary
protected ChunkedInput(Type chunkType, InputStream inputStream, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,String> headers, MessageBodyWorkers messageBodyWorkers, org.glassfish.jersey.internal.PropertiesDelegate propertiesDelegate)
          Package-private constructor used by the ChunkedInputReader.
 
Method Summary
 void close()
           
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.
static ChunkParser createParser(String boundary)
          Create new chunk parser that will split the response entity input stream based on a fixed boundary string.
 MediaType getChunkType()
          Get chunk data media type.
 ChunkParser getParser()
          Get the underlying chunk parser.
 boolean isClosed()
          Check if the chunked input has been closed.
 T read()
          Read next chunk from the response stream and convert it to a Java instance using the chunk media type.
 void setChunkType(MediaType mediaType)
          Set custom chunk data media type.
 void setChunkType(String mediaType)
          Set custom chunk data media type from a string value.
 void setParser(ChunkParser parser)
          Set new chunk parser.
 
Methods inherited from class javax.ws.rs.core.GenericType
equals, getRawType, getType, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChunkedInput

protected ChunkedInput(Type chunkType,
                       InputStream inputStream,
                       Annotation[] annotations,
                       MediaType mediaType,
                       MultivaluedMap<String,String> headers,
                       MessageBodyWorkers messageBodyWorkers,
                       org.glassfish.jersey.internal.PropertiesDelegate propertiesDelegate)
Package-private constructor used by the ChunkedInputReader.

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(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.

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 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 by setting a custom non-null chunk 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(MediaType mediaType)
                  throws IllegalArgumentException
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-null chunk media type. Once this method is invoked, all subsequent chunk reads will use the newly set chunk media type when selecting the proper MessageBodyReader for 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 be null.
Throws:
IllegalArgumentException - in case the mediaType is null.

setChunkType

public void setChunkType(String mediaType)
                  throws IllegalArgumentException
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 be null.
Throws:
IllegalArgumentException - in case the mediaType cannot be parsed into a valid MediaType instance or is null.
See Also:
setChunkType(javax.ws.rs.core.MediaType)

close

public void close()
Specified by:
close in interface Closeable

isClosed

public boolean isClosed()
Check if the chunked input has been closed.

Returns:
true if this chunked input has been closed, false otherwise.

read

public T read()
       throws IllegalStateException
Read next chunk from the response stream and convert it to a Java instance using the chunk media type. The method returns null if the underlying entity input stream has been closed (either implicitly or explicitly by calling the close() 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 null if the underlying entity input stream has been closed while reading next chunk data.
Throws:
IllegalStateException - in case this chunked input has been closed.


Copyright © 2007-2013, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.