Package org.glassfish.jersey.server
Class ChunkedOutput<T>
- java.lang.Object
-
- jakarta.ws.rs.core.GenericType<T>
-
- org.glassfish.jersey.server.ChunkedOutput<T>
-
- Type Parameters:
T- chunk type.
- All Implemented Interfaces:
Closeable,AutoCloseable
public class ChunkedOutput<T> extends GenericType<T> implements Closeable
Used for sending messages in "typed" chunks. Useful for long running processes, which needs to produce partial responses.- Author:
- Pavel Bucek, Martin Matula, Marek Potociar
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classChunkedOutput.Builder<Y>Builder that allows to create a new ChunkedOutput based on the given configuration options.static classChunkedOutput.TypedBuilder<Y>Builder that allows to create a new ChunkedOutput based on the given configuration options.
-
Constructor Summary
Constructors Modifier Constructor Description protectedChunkedOutput()Create newChunkedOutput.protectedChunkedOutput(byte[] chunkDelimiter)Create newChunkedOutputwith a custom chunk delimiter.protectedChunkedOutput(byte[] chunkDelimiter, jakarta.inject.Provider<AsyncContext> asyncContextProvider)Create newChunkedOutputwith a custom chunk delimiter.ChunkedOutput(Type chunkType)CreateChunkedOutputwith specified type.ChunkedOutput(Type chunkType, byte[] chunkDelimiter)Create newChunkedOutputwith a custom chunk delimiter.ChunkedOutput(Type chunkType, String chunkDelimiter)Create newChunkedOutputwith a custom chunk delimiter.protectedChunkedOutput(String chunkDelimiter)Create newChunkedOutputwith a custom chunk delimiter.protectedChunkedOutput(ChunkedOutput.Builder<T> builder)Create newChunkedOutputbased on builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ChunkedOutput.Builder<T>builder()Returns a builder to create a ChunkedOutput with custom configuration.static <T> ChunkedOutput.TypedBuilder<T>builder(Type chunkType)Returns a builder to create a ChunkedOutput with custom configuration.voidclose()Close this response - it will be finalized and underlying connections will be closed or made available for another response.booleanequals(Object obj)protected voidflushQueue()inthashCode()booleanisClosed()Get state information.protected voidonClose(Exception e)Executed only in case of close being triggered by client.StringtoString()voidwrite(T chunk)Write a chunk.-
Methods inherited from class jakarta.ws.rs.core.GenericType
forInstance, getRawType, getType
-
-
-
-
Constructor Detail
-
ChunkedOutput
protected ChunkedOutput()
Create newChunkedOutput.
-
ChunkedOutput
protected ChunkedOutput(ChunkedOutput.Builder<T> builder)
Create newChunkedOutputbased on builder.- Parameters:
builder- the builder to use
-
ChunkedOutput
public ChunkedOutput(Type chunkType)
CreateChunkedOutputwith specified type.- Parameters:
chunkType- chunk type. Must not be {code null}.
-
ChunkedOutput
protected ChunkedOutput(byte[] chunkDelimiter)
Create newChunkedOutputwith a custom chunk delimiter.- Parameters:
chunkDelimiter- custom chunk delimiter bytes. Must not be {code null}.- Since:
- 2.4.1
-
ChunkedOutput
protected ChunkedOutput(byte[] chunkDelimiter, jakarta.inject.Provider<AsyncContext> asyncContextProvider)Create newChunkedOutputwith a custom chunk delimiter.- Parameters:
chunkDelimiter- custom chunk delimiter bytes. Must not be {code null}.- Since:
- 2.4.1
-
ChunkedOutput
public ChunkedOutput(Type chunkType, byte[] chunkDelimiter)
Create newChunkedOutputwith a custom chunk delimiter.- Parameters:
chunkType- chunk type. Must not be {code null}.chunkDelimiter- custom chunk delimiter bytes. Must not be {code null}.- Since:
- 2.4.1
-
ChunkedOutput
protected ChunkedOutput(String chunkDelimiter)
Create newChunkedOutputwith a custom chunk delimiter.- Parameters:
chunkDelimiter- custom chunk delimiter string. Must not be {code null}.- Since:
- 2.4.1
-
-
Method Detail
-
builder
public static <T> ChunkedOutput.Builder<T> builder()
Returns a builder to create a ChunkedOutput with custom configuration.- Returns:
- builder
-
builder
public static <T> ChunkedOutput.TypedBuilder<T> builder(Type chunkType)
Returns a builder to create a ChunkedOutput with custom configuration.- Parameters:
chunkType- chunk type. Must not be {code null}.- Returns:
- builder
-
write
public void write(T chunk) throws IOException
Write a chunk.- Parameters:
chunk- a chunk instance to be written.- Throws:
IOException- if this response is closed or when encountered any problem during serializing or writing a chunk.
-
flushQueue
protected void flushQueue() throws IOException- Throws:
IOException
-
close
public void close() throws IOExceptionClose this response - it will be finalized and underlying connections will be closed or made available for another response.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
isClosed
public boolean isClosed()
Get state information. Please note thatChunkedOutputcan be closed by the client side - client can close connection from its side.- Returns:
- true when closed, false otherwise.
-
onClose
protected void onClose(Exception e)
Executed only in case of close being triggered by client.- Parameters:
e- Exception causing the close
-
equals
public boolean equals(Object obj)
- Overrides:
equalsin classGenericType<T>
-
hashCode
public int hashCode()
- Overrides:
hashCodein classGenericType<T>
-
toString
public String toString()
- Overrides:
toStringin classGenericType<T>
-
-