Class PasteFileHandler

java.lang.Object
com.vaadin.flow.component.clipboard.PasteFileHandler
All Implemented Interfaces:
Serializable

public final class PasteFileHandler extends Object implements Serializable
Factory for paste-aware UploadHandlers that group the parallel fetch uploads of a single paste gesture and surface the result to application code. Two flavours are offered, both producing an UploadHandler suitable for Clipboard.onFilePaste:
  • inMemory(SerializableConsumer) — a single per-file callback that receives every file as a PasteFile, with PasteFile.newPaste() flagging the first file of each paste.
  • session() — a three-step session listener: onStart fires once per paste with the declared file count, onFile fires per file, and onComplete fires once after the last file has been delivered.
Each paste runs in its own session: pastes that overlap in transit (the tail of an older paste's uploads arriving after a newer paste has started) still run through their own onStart / onFile / onComplete lifecycle. Sessions live in memory until they receive all the files the browser declared in Clipboard.PASTE_FILE_COUNT_HEADER; a paste whose upload fails mid-flight stays open indefinitely (rare in practice, since uploads are small, but worth knowing if an application keeps a process alive for months).

Application code that wants "show the latest paste only" semantics tracks the highest paste id seen and filters in its own callbacks — the handler does not drop any files on the application's behalf, so a slow tail upload from an earlier paste still arrives at the listener.

See Also:
  • Method Details

    • inMemory

      public static UploadHandler inMemory(SerializableConsumer<PasteFile> consumer)
      Builds an UploadHandler that reads each upload fully into memory, packages it as a PasteFile, and delivers it to the supplied consumer on the UI thread.
      Parameters:
      consumer - invoked for each accepted file on the UI thread, not null
      Returns:
      an upload handler suitable for Clipboard.onFilePaste
    • session

      public static PasteFileHandler.SessionBuilder session()
      Starts a session-style handler builder that emits onStart once per paste before any file, onFile per file, and onComplete once the paste's declared file count has been delivered. Any callback may be omitted.
      Returns:
      a fresh, unconfigured session builder