Class StrutsInMemoryUploadedFile

java.lang.Object
org.apache.struts2.dispatcher.multipart.StrutsInMemoryUploadedFile
All Implemented Interfaces:
Serializable, UploadedFile

public class StrutsInMemoryUploadedFile extends Object implements UploadedFile
In-memory backed 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:
  • Method Details

    • getInputStream

      public InputStream getInputStream()
      Description copied from interface: UploadedFile
      Streams 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 whatever UploadedFile.getContent() exposes.
      Specified by:
      getInputStream in interface UploadedFile
      Returns:
      an input stream over the uploaded content
    • isMissing

      public boolean isMissing()
      Description copied from interface: UploadedFile
      Indicates 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 when UploadedFile.getContent() is null.
      Specified by:
      isMissing in interface UploadedFile
      Returns:
      true if there is no content backing this upload
    • length

      public Long length()
      Specified by:
      length in interface UploadedFile
      Returns:
      size of the content of file/stream/array
    • getName

      public String getName()
      Specified by:
      getName in interface UploadedFile
      Returns:
      a local name of the file
    • isFile

      public boolean isFile()
      Specified by:
      isFile in interface UploadedFile
      Returns:
      indicates if this is a real file or maybe just in-memory stream
    • delete

      public boolean delete()
      Specified by:
      delete in interface UploadedFile
      Returns:
      removes a local copy of the uploaded file/stream
    • getAbsolutePath

      public String getAbsolutePath()
      Specified by:
      getAbsolutePath in interface UploadedFile
      Returns:
      an absolute path of the file if possible
    • getContent

      public File getContent()
      Specified by:
      getContent in interface UploadedFile
      Returns:
      content of the upload file
    • getContentType

      public String getContentType()
      Specified by:
      getContentType in interface UploadedFile
      Returns:
      content type of the uploaded file
    • getOriginalName

      public String getOriginalName()
      Specified by:
      getOriginalName in interface UploadedFile
      Returns:
      original file name from upload source
    • getInputName

      public String getInputName()
      Description copied from interface: UploadedFile
      Represents a name of the input file, eg.: "myFile" in case of
      Specified by:
      getInputName in interface UploadedFile
      Returns:
      name of the input file field
    • toString

      public String toString()
      Overrides:
      toString in class Object