public class MockMultipartFile
extends java.lang.Object
implements org.springframework.web.multipart.MultipartFile
MultipartFile
interface.
Useful in conjunction with a MockMultipartHttpServletRequest
for testing application controllers that access multipart uploads.
MockMultipartHttpServletRequest| Constructor and Description |
|---|
MockMultipartFile(java.lang.String name,
byte[] content)
Create a new MockMultipartFile with the given content.
|
MockMultipartFile(java.lang.String name,
java.io.InputStream contentStream)
Create a new MockMultipartFile with the given content.
|
MockMultipartFile(java.lang.String name,
java.lang.String originalFilename,
java.lang.String contentType,
byte[] content)
Create a new MockMultipartFile with the given content.
|
MockMultipartFile(java.lang.String name,
java.lang.String originalFilename,
java.lang.String contentType,
java.io.InputStream contentStream)
Create a new MockMultipartFile with the given content.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getBytes() |
java.lang.String |
getContentType() |
java.io.InputStream |
getInputStream() |
java.lang.String |
getName() |
java.lang.String |
getOriginalFilename() |
long |
getSize() |
boolean |
isEmpty() |
void |
transferTo(java.io.File dest) |
public MockMultipartFile(java.lang.String name,
byte[] content)
name - the name of the filecontent - the content of the filepublic MockMultipartFile(java.lang.String name,
java.io.InputStream contentStream)
throws java.io.IOException
name - the name of the filecontentStream - the content of the file as streamjava.io.IOException - if reading from the stream failedpublic MockMultipartFile(java.lang.String name,
java.lang.String originalFilename,
java.lang.String contentType,
byte[] content)
name - the name of the fileoriginalFilename - the original filename (as on the client's machine)contentType - the content type (if known)content - the content of the filepublic MockMultipartFile(java.lang.String name,
java.lang.String originalFilename,
java.lang.String contentType,
java.io.InputStream contentStream)
throws java.io.IOException
name - the name of the fileoriginalFilename - the original filename (as on the client's machine)contentType - the content type (if known)contentStream - the content of the file as streamjava.io.IOException - if reading from the stream failedpublic java.lang.String getName()
getName in interface org.springframework.web.multipart.MultipartFilepublic java.lang.String getOriginalFilename()
getOriginalFilename in interface org.springframework.web.multipart.MultipartFilepublic java.lang.String getContentType()
getContentType in interface org.springframework.web.multipart.MultipartFilepublic boolean isEmpty()
isEmpty in interface org.springframework.web.multipart.MultipartFilepublic long getSize()
getSize in interface org.springframework.web.multipart.MultipartFilepublic byte[] getBytes()
throws java.io.IOException
getBytes in interface org.springframework.web.multipart.MultipartFilejava.io.IOExceptionpublic java.io.InputStream getInputStream()
throws java.io.IOException
getInputStream in interface org.springframework.core.io.InputStreamSourcegetInputStream in interface org.springframework.web.multipart.MultipartFilejava.io.IOExceptionpublic void transferTo(java.io.File dest)
throws java.io.IOException,
java.lang.IllegalStateException
transferTo in interface org.springframework.web.multipart.MultipartFilejava.io.IOExceptionjava.lang.IllegalStateException