public class MockMultipartFile extends 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(String name,
byte[] content)
Create a new MockMultipartFile with the given content.
|
MockMultipartFile(String name,
InputStream contentStream)
Create a new MockMultipartFile with the given content.
|
MockMultipartFile(String name,
String originalFilename,
String contentType,
byte[] content)
Create a new MockMultipartFile with the given content.
|
MockMultipartFile(String name,
String originalFilename,
String contentType,
InputStream contentStream)
Create a new MockMultipartFile with the given content.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getBytes() |
String |
getContentType() |
InputStream |
getInputStream() |
String |
getName() |
String |
getOriginalFilename() |
long |
getSize() |
boolean |
isEmpty() |
void |
transferTo(File dest) |
public MockMultipartFile(String name, byte[] content)
name - the name of the filecontent - the content of the filepublic MockMultipartFile(String name, InputStream contentStream) throws IOException
name - the name of the filecontentStream - the content of the file as streamIOException - if reading from the stream failedpublic MockMultipartFile(String name, String originalFilename, 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(String name, String originalFilename, String contentType, InputStream contentStream) throws 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 streamIOException - if reading from the stream failedpublic String getName()
getName in interface org.springframework.web.multipart.MultipartFilepublic String getOriginalFilename()
getOriginalFilename in interface org.springframework.web.multipart.MultipartFilepublic 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 IOException
getBytes in interface org.springframework.web.multipart.MultipartFileIOExceptionpublic InputStream getInputStream() throws IOException
getInputStream in interface org.springframework.core.io.InputStreamSourcegetInputStream in interface org.springframework.web.multipart.MultipartFileIOExceptionpublic void transferTo(File dest) throws IOException, IllegalStateException
transferTo in interface org.springframework.web.multipart.MultipartFileIOExceptionIllegalStateException