Top Description Fields Constructors Methods
org.springframework.web.multipart

pack-priv Class MultipartFileResource

extends AbstractResource
Class Inheritance
Imports
java.io.IOException, .InputStream, org.springframework.core.io.AbstractResource, org.springframework.lang.Nullable, org.springframework.util.Assert

Adapt MultipartFile to org.springframework.core.io.Resource, exposing the content as InputStream and also overriding contentLength() as well as getFilename().
Author
Rossen Stoyanchev
Since
5.1
See Also
MultipartFile#getResource()

Field Summary

Modifier and TypeField and Description
private final MultipartFile

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public long
contentLength()

Overrides org.springframework.core.io.AbstractResource.contentLength.

Implements org.springframework.core.io.Resource.contentLength.

This method reads the entire InputStream to determine the content length.

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides org.springframework.core.io.AbstractResource.equals.

This implementation compares description strings.

public boolean
exists()

Overrides org.springframework.core.io.AbstractResource.exists.

Implements org.springframework.core.io.Resource.exists.

This implementation always returns true.

public String
getDescription()

Implements org.springframework.core.io.Resource.getDescription.

This implementation returns a description that has the Multipart name.

public String
getFilename()

Overrides org.springframework.core.io.AbstractResource.getFilename.

Implements org.springframework.core.io.Resource.getFilename.

This implementation always returns null, assuming that this resource type does not have a filename.

public InputStream
getInputStream()

Implements org.springframework.core.io.InputStreamSource.getInputStream.

This implementation throws IllegalStateException if attempting to read the underlying stream multiple times.

public int
hashCode()

Overrides org.springframework.core.io.AbstractResource.hashCode.

This implementation returns the description's hash code.

public boolean
isOpen()

Overrides org.springframework.core.io.AbstractResource.isOpen.

Overrides default org.springframework.core.io.Resource.isOpen.

This implementation always returns true.

Inherited from org.springframework.core.io.AbstractResource:
createRelativegetFilegetFileForLastModifiedCheckgetURIgetURLisFileisReadablelastModifiedreadableChanneltoString

Field Detail

multipartFileback to summary
private final MultipartFile multipartFile

Constructor Detail

MultipartFileResourceback to summary
public MultipartFileResource(MultipartFile multipartFile)

Method Detail

contentLengthback to summary
public long contentLength()

Overrides org.springframework.core.io.AbstractResource.contentLength.

Implements org.springframework.core.io.Resource.contentLength.

Doc from org.springframework.core.io.AbstractResource.contentLength.

This method reads the entire InputStream to determine the content length.

For a custom subclass of InputStreamResource, we strongly recommend overriding this method with a more optimal implementation, e.g. checking File length, or possibly simply returning -1 if the stream can only be read once.

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides org.springframework.core.io.AbstractResource.equals.

Doc from org.springframework.core.io.AbstractResource.equals.

This implementation compares description strings.

Parameters
other:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
existsback to summary
public boolean exists()

Overrides org.springframework.core.io.AbstractResource.exists.

Implements org.springframework.core.io.Resource.exists.

This implementation always returns true.

Annotations
@Override
getDescriptionback to summary
public String getDescription()

Implements org.springframework.core.io.Resource.getDescription.

This implementation returns a description that has the Multipart name.

Annotations
@Override
getFilenameback to summary
public String getFilename()

Overrides org.springframework.core.io.AbstractResource.getFilename.

Implements org.springframework.core.io.Resource.getFilename.

Doc from org.springframework.core.io.AbstractResource.getFilename.

This implementation always returns null, assuming that this resource type does not have a filename.

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream() throws IOException, IllegalStateException

Implements org.springframework.core.io.InputStreamSource.getInputStream.

This implementation throws IllegalStateException if attempting to read the underlying stream multiple times.

Returns:InputStream

Doc from org.springframework.core.io.InputStreamSource.getInputStream.

the input stream for the underlying resource (must not be null)

Annotations
@Override
Exceptions
IOException:

Doc from org.springframework.core.io.InputStreamSource.getInputStream.

if the content stream could not be opened

hashCodeback to summary
public int hashCode()

Overrides org.springframework.core.io.AbstractResource.hashCode.

Doc from org.springframework.core.io.AbstractResource.hashCode.

This implementation returns the description's hash code.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object

Annotations
@Override
isOpenback to summary
public boolean isOpen()

Overrides org.springframework.core.io.AbstractResource.isOpen.

Overrides default org.springframework.core.io.Resource.isOpen.

This implementation always returns true.

Annotations
@Override