Class TransferUtil

java.lang.Object
com.vaadin.flow.server.communication.TransferUtil

public final class TransferUtil extends Object
Utility class with methods for handling transfer of upload and download requests.
  • Field Details

    • DEFAULT_BUFFER_SIZE

      public static int DEFAULT_BUFFER_SIZE
      Default buffer size for reading data from the input stream.

      Follows the default buffer size of the Java InputStream.transferTo(OutputStream).

  • Constructor Details

    • TransferUtil

      public TransferUtil()
  • Method Details

    • transfer

      public static long transfer(InputStream inputStream, OutputStream outputStream, TransferContext transferContext, Collection<TransferProgressListener> listeners) throws IOException
      Transfers data from the given input stream to the output stream while notifying the progress to the given listeners.
      Parameters:
      inputStream - the input stream to read from
      outputStream - the output stream to write to
      transferContext - the transfer request containing metadata about the transfer
      listeners - collection of listeners to notify about progress
      Returns:
      the number of bytes transferred
      Throws:
      IOException - if an I/O error occurs during the transfer
    • handleUpload

      public static void handleUpload(UploadHandler handler, VaadinRequest request, VaadinResponse response, VaadinSession session, Element owner)
      Handle upload request and call UploadHandler.handleUploadRequest(UploadEvent) correctly for xhr and multipart uploads.

      Fires internal events for the owner upload component to indicate that the upload has started and completed.

      For internal use only. May be renamed or removed in a future release.

      Parameters:
      handler - UploadHandler that should be called for this upload
      request - The VaadinRequest for this upload
      response - The VaadinResponse for this upload
      session - Current VaadinSession
      owner - The element that owns the request handler
    • extractFilenameFromXhrRequest

      public static String extractFilenameFromXhrRequest(VaadinRequest request)
      Extracts the filename from an XHR upload request.

      The filename is extracted from the X-Filename header, which is set by vaadin-upload. The filename is encoded using JavaScript's encodeURIComponent and decoded on the server using UrlUtil.decodeURIComponent(String) (RFC 3986).

      Parameters:
      request - the request to extract the filename from
      Returns:
      the decoded filename, or "unknown" if not present
    • extractContentTypeFromXhrRequest

      public static String extractContentTypeFromXhrRequest(VaadinRequest request)
      Extracts the content type from an XHR upload request.

      The content type is extracted from the Content-Type header.

      Parameters:
      request - the request to extract the content type from
      Returns:
      the content type, or "unknown" if not present