Interface StreamVariable
-
- All Superinterfaces:
Serializable
public interface StreamVariable extends Serializable
StreamVariable is a special kind of variable whose value is streamed to anOutputStreamprovided by thegetOutputStream()method. E.g. in web terminalsStreamVariablecan be used to send large files from browsers to the server without consuming large amounts of memory.Note, writing to the
OutputStreamis not synchronized by the terminal (to avoid stalls in other operations when e.g. streaming to a slow network service or file system). If UI is changed as a side effect of writing to the output stream, developer must handle synchronization manually.- Since:
- 6.5
- Author:
- Vaadin Ltd.
- See Also:
PaintTarget.addVariable(VariableOwner, String, StreamVariable)
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceStreamVariable.StreamingEndEventEvent passed tostreamingFinished(StreamingEndEvent)method the contents have been streamed to StreamVariable successfully.static interfaceStreamVariable.StreamingErrorEventEvent passed tostreamingFailed(StreamingErrorEvent)method when the streaming ended before the end of the input.static interfaceStreamVariable.StreamingEventstatic interfaceStreamVariable.StreamingProgressEventEvent passed toonProgress(StreamingProgressEvent)method during the streaming progresses.static interfaceStreamVariable.StreamingStartEventEvent passed tostreamingStarted(StreamingStartEvent)method before the streaming of the content toStreamVariablestarts.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description OutputStreamgetOutputStream()Invoked by the terminal when a new upload arrives, afterstreamingStarted(StreamingStartEvent)method has been called.booleanisInterrupted()If this method returns true while the content is being streamed the Terminal to stop receiving current upload.booleanlistenProgress()Whether theonProgress(StreamingProgressEvent)method should be called during the upload.voidonProgress(StreamVariable.StreamingProgressEvent event)This method is called by the terminal iflistenProgress()returns true when the streaming starts.voidstreamingFailed(StreamVariable.StreamingErrorEvent event)voidstreamingFinished(StreamVariable.StreamingEndEvent event)voidstreamingStarted(StreamVariable.StreamingStartEvent event)
-
-
-
Method Detail
-
getOutputStream
OutputStream getOutputStream()
Invoked by the terminal when a new upload arrives, afterstreamingStarted(StreamingStartEvent)method has been called. The terminal implementation will write the streamed variable to the returned output stream.- Returns:
- Stream to which the uploaded file should be written.
-
listenProgress
boolean listenProgress()
Whether theonProgress(StreamingProgressEvent)method should be called during the upload.onProgress(StreamingProgressEvent)is called in a synchronized block when the content is being received. This is potentially bit slow, so we are calling that method only if requested. The value is requested after thestreamingStarted(StreamingStartEvent)event, but not after reading each buffer.- Returns:
- true if this
StreamVariablewants to by notified during the upload of the progress of streaming. - See Also:
onProgress(StreamingProgressEvent)
-
onProgress
void onProgress(StreamVariable.StreamingProgressEvent event)
This method is called by the terminal iflistenProgress()returns true when the streaming starts.
-
streamingStarted
void streamingStarted(StreamVariable.StreamingStartEvent event)
-
streamingFinished
void streamingFinished(StreamVariable.StreamingEndEvent event)
-
streamingFailed
void streamingFailed(StreamVariable.StreamingErrorEvent event)
-
isInterrupted
boolean isInterrupted()
If this method returns true while the content is being streamed the Terminal to stop receiving current upload.Note, the usage of this method is not synchronized over the Application instance by the terminal like other methods. The implementation should only return a boolean field and especially not modify UI or implement a synchronization by itself.
- Returns:
- true if the streaming should be interrupted as soon as possible.
-
-