Record Class TransferContext

java.lang.Object
java.lang.Record
com.vaadin.flow.server.streams.TransferContext
Record Components:
request - The current Vaadin request instance
response - The current Vaadin response instance
session - The current Vaadin session instance
fileName - The name of the file being transferred. Might be null if the file name is not known.
owningElement - The owner element that initiated the transfer. Can be used to get element's attributes or properties.
contentLength - the total number of bytes to be transferred or -1 if total number is unknown in advance, e.g. when reading from an input stream
exception - An exception that occurred during the transfer, or null.

public record TransferContext(VaadinRequest request, VaadinResponse response, VaadinSession session, String fileName, Element owningElement, long contentLength, Exception exception) extends Record
A context that is given to all data transfer progress listeners. Holds the references that may be needed for UI updates in listeners, e.g. showing a data transfer progress or a notification.
  • Constructor Details

    • TransferContext

      public TransferContext(VaadinRequest request, VaadinResponse response, VaadinSession session, String fileName, Element owningElement, long contentLength)
      Create a transfer context for data transfer progress listeners.
      Parameters:
      request - The current Vaadin request instance
      response - The current Vaadin response instance
      session - The current Vaadin session instance
      fileName - The name of the file being transferred. Might be null if the file name is not known.
      owningElement - The owner element that initiated the transfer. Can be used to get element's attributes or properties.
      contentLength - the total number of bytes to be transferred or -1 if total number is unknown in advance, e.g. when reading from an input stream
    • TransferContext

      public TransferContext(VaadinRequest request, VaadinResponse response, VaadinSession session, String fileName, Element owningElement, long contentLength, Exception exception)
      Creates an instance of a TransferContext record class.
      Parameters:
      request - the value for the request record component
      response - the value for the response record component
      session - the value for the session record component
      fileName - the value for the fileName record component
      owningElement - the value for the owningElement record component
      contentLength - the value for the contentLength record component
      exception - the value for the exception record component
  • Method Details

    • getOwningComponent

      public Component getOwningComponent()
      Get owner Component for this data transfer.

      The progress listener may change the component's state during donwload, e.g. disable or hide it during transfer or get the component's own data like id.

      Returns:
      owning component or null if none is defined
    • getUI

      public UI getUI()
      Get the current UI instance for this data transfer that can be used to make asynchronnous UI updates with UI.access(com.vaadin.flow.server.Command).
      Returns:
      Current UI instance
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • request

      public VaadinRequest request()
      Returns the value of the request record component.
      Returns:
      the value of the request record component
    • response

      public VaadinResponse response()
      Returns the value of the response record component.
      Returns:
      the value of the response record component
    • session

      public VaadinSession session()
      Returns the value of the session record component.
      Returns:
      the value of the session record component
    • fileName

      public String fileName()
      Returns the value of the fileName record component.
      Returns:
      the value of the fileName record component
    • owningElement

      public Element owningElement()
      Returns the value of the owningElement record component.
      Returns:
      the value of the owningElement record component
    • contentLength

      public long contentLength()
      Returns the value of the contentLength record component.
      Returns:
      the value of the contentLength record component
    • exception

      public Exception exception()
      Returns the value of the exception record component.
      Returns:
      the value of the exception record component