Class StrutsInMemoryUploadedFile
- All Implemented Interfaces:
Serializable,UploadedFile
UploadedFile for small multipart uploads that Commons FileUpload kept
in memory (DiskFileItem.isInMemory() == true).
The content is held as a byte array and is written to a temporary file only the first time a
caller demands a File through getContent() or getAbsolutePath() (lazy
materialization). Callers reading through getInputStream() never touch the disk. The
temporary file uses the secure upload_<uuid>.tmp naming and ignores the user-supplied
original filename.
Clustered deployments: the target temporary path is resolved on the node that
created this instance. If an un-materialized instance is serialized (for example, session
replication) and deserialized on another node, a later getContent() materializes to that
originating node's path, which may not exist on the new node. Read via getInputStream(),
which never touches disk, when content must survive cross-node replication.
- Since:
- 7.3.0
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbooleandelete()Represents a name of the input file, eg.: "myFile" in case ofStreams the uploaded content without forcing it to disk.getName()booleanisFile()booleanIndicates whether this upload has no content available (for example, the upload failed).length()toString()
-
Method Details
-
getInputStream
Description copied from interface:UploadedFileStreams the uploaded content without forcing it to disk. Implementations backed by in-memory bytes can return the bytes directly; file-backed implementations stream the file. The default reads whateverUploadedFile.getContent()exposes.- Specified by:
getInputStreamin interfaceUploadedFile- Returns:
- an input stream over the uploaded content
-
isMissing
public boolean isMissing()Description copied from interface:UploadedFileIndicates whether this upload has no content available (for example, the upload failed). Implementations that hold their content in memory should override this to answer WITHOUT materializing the content to disk. The default reports missing whenUploadedFile.getContent()isnull.- Specified by:
isMissingin interfaceUploadedFile- Returns:
- true if there is no content backing this upload
-
length
- Specified by:
lengthin interfaceUploadedFile- Returns:
- size of the content of file/stream/array
-
getName
- Specified by:
getNamein interfaceUploadedFile- Returns:
- a local name of the file
-
isFile
public boolean isFile()- Specified by:
isFilein interfaceUploadedFile- Returns:
- indicates if this is a real file or maybe just in-memory stream
-
delete
public boolean delete()- Specified by:
deletein interfaceUploadedFile- Returns:
- removes a local copy of the uploaded file/stream
-
getAbsolutePath
- Specified by:
getAbsolutePathin interfaceUploadedFile- Returns:
- an absolute path of the file if possible
-
getContent
- Specified by:
getContentin interfaceUploadedFile- Returns:
- content of the upload file
-
getContentType
- Specified by:
getContentTypein interfaceUploadedFile- Returns:
- content type of the uploaded file
-
getOriginalName
- Specified by:
getOriginalNamein interfaceUploadedFile- Returns:
- original file name from upload source
-
getInputName
Description copied from interface:UploadedFileRepresents a name of the input file, eg.: "myFile" in case of- Specified by:
getInputNamein interfaceUploadedFile- Returns:
- name of the input file field
-
toString
-