Class TransferUtil
java.lang.Object
com.vaadin.flow.server.communication.TransferUtil
Utility class with methods for handling transfer of upload and download
requests.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intDefault buffer size for reading data from the input stream. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringExtracts the content type from an XHR upload request.static StringExtracts the filename from an XHR upload request.static voidhandleUpload(UploadHandler handler, VaadinRequest request, VaadinResponse response, VaadinSession session, Element owner) Handle upload request and callUploadHandler.handleUploadRequest(UploadEvent)correctly for xhr and multipart uploads.static longtransfer(InputStream inputStream, OutputStream outputStream, TransferContext transferContext, Collection<TransferProgressListener> listeners) Transfers data from the given input stream to the output stream while notifying the progress to the given listeners.
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static int DEFAULT_BUFFER_SIZEDefault 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 fromoutputStream- the output stream to write totransferContext- the transfer request containing metadata about the transferlisteners- 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 callUploadHandler.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 uploadrequest- The VaadinRequest for this uploadresponse- The VaadinResponse for this uploadsession- Current VaadinSessionowner- The element that owns the request handler
-
extractFilenameFromXhrRequest
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
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
-