MockMultipartFile
org.springframework.mock.web
Class MockMultipartFile
java.lang.Object

org.springframework.mock.web.MockMultipartFile
- All Implemented Interfaces:
- MultipartFile
public class MockMultipartFileextends Objectimplements MultipartFile
Mock implementation of the MultipartFile interface.
Useful in conjunction with a MockMultipartHttpServletRequest for testing application controllers that access multipart uploads.
- Since:
- 2.0
- Author:
- Juergen Hoeller, Eric Crampton
- See Also:
- MockMultipartHttpServletRequest
| Constructor Summary | |
|---|---|
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. |
|
| Method Summary | |
|---|---|
byte[] |
getBytes() Return the contents of the file as an array of bytes. |
String |
getContentType() Return the content type of the file. |
InputStream |
getInputStream() Return an InputStream to read the contents of the file from. |
String |
getName() Return the name of the parameter in the multipart form. |
String |
getOriginalFilename() Return the original filename in the client's filesystem. |
long |
getSize() Return the size of the file in bytes. |
boolean |
isEmpty() Return whether the uploaded file is empty, that is, either no file has been chosen in the multipart form or the chosen file has no content. |
void |
transferTo(File dest) Transfer the received file to the given destination file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
MockMultipartFile
public MockMultipartFile(String name,
byte[] content)
- Create a new MockMultipartFile with the given content.
- Parameters:
name- the name of the filecontent- the content of the file
MockMultipartFile
public MockMultipartFile(String name,
InputStream contentStream)
throws IOException
- Create a new MockMultipartFile with the given content.
- Parameters:
name- the name of the filecontentStream- the content of the file as stream- Throws:
IOException- if reading from the stream failed
MockMultipartFile
public MockMultipartFile(String name,
String originalFilename,
String contentType,
byte[] content)
- Create a new MockMultipartFile with the given content.
- Parameters:
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 file
MockMultipartFile
public MockMultipartFile(String name,
String originalFilename,
String contentType,
InputStream contentStream)
throws IOException
- Create a new MockMultipartFile with the given content.
- Parameters:
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 stream- Throws:
IOException- if reading from the stream failed
| Method Detail |
|---|
getName
public String getName()
- Description copied from interface:
MultipartFile - Return the name of the parameter in the multipart form.
-
- Specified by:
getNamein interfaceMultipartFile
-
- Returns:
- the name of the parameter (never
nullor empty)
getOriginalFilename
public String getOriginalFilename()
- Description copied from interface:
MultipartFile - Return the original filename in the client's filesystem.
This may contain path information depending on the browser used, but it typically will not with any other than Opera.
-
- Specified by:
getOriginalFilenamein interfaceMultipartFile
-
- Returns:
- the original filename, or the empty String if no file has been chosen in the multipart form
getContentType
public String getContentType()
- Description copied from interface:
MultipartFile - Return the content type of the file.
-
- Specified by:
getContentTypein interfaceMultipartFile
-
- Returns:
- the content type, or
nullif not defined (or no file has been chosen in the multipart form)
isEmpty
public boolean isEmpty()
- Description copied from interface:
MultipartFile - Return whether the uploaded file is empty, that is, either no file has been chosen in the multipart form or the chosen file has no content.
-
- Specified by:
isEmptyin interfaceMultipartFile
-
getSize
public long getSize()
- Description copied from interface:
MultipartFile - Return the size of the file in bytes.
-
- Specified by:
getSizein interfaceMultipartFile
-
- Returns:
- the size of the file, or 0 if empty
getBytes
public byte[] getBytes()
throws IOException
- Description copied from interface:
MultipartFile - Return the contents of the file as an array of bytes.
-
- Specified by:
getBytesin interfaceMultipartFile
-
- Returns:
- the contents of the file as bytes, or an empty byte array if empty
- Throws:
IOException- in case of access errors (if the temporary store fails)
getInputStream
public InputStream getInputStream()
throws IOException
- Description copied from interface:
MultipartFile - Return an InputStream to read the contents of the file from. The user is responsible for closing the stream.
-
- Specified by:
getInputStreamin interfaceMultipartFile
-
- Returns:
- the contents of the file as stream, or an empty stream if empty
- Throws:
IOException- in case of access errors (if the temporary store fails)
transferTo
public void transferTo(File dest)
throws IOException,
IllegalStateException
- Description copied from interface:
MultipartFile - Transfer the received file to the given destination file.
This may either move the file in the filesystem, copy the file in thefilesystem, or save memory-held contents to the destination file.If the destination file already exists, it will be deleted first.
If the file has been moved in the filesystem, this operation cannotbe invoked again. Therefore, call this method just once to be able towork with any storage mechanism.
-
- Specified by:
transferToin interfaceMultipartFile
-
- Parameters:
dest- the destination file- Throws:
IOException- in case of reading or writing errorsIllegalStateException- if the file has already been movedin the filesystem and is not available anymore for another transfer
MockMultipartFile的更多相关文章
- WebView介绍
本文主要对WebView进行介绍,包括webView 4个可以定制的点.设置WebView back键响应.控制网页的链接仍在webView中跳转.显示页面加载进度.处理https请求.利用addJa ...
- SpringMVC 测试 mockMVC
SpringMVC测试框架 基于RESTful风格的SpringMVC的测试,我们可以测试完整的Spring MVC流程,即从URL请求到控制器处理,再到视图渲染都可以测试. 一 MockMvcBui ...
- sonar + jacoco + mockMvc 模拟session 用户登录 配合SpringSecurity 权限 快速测试代码覆盖率.
遇到mock 测试简直就是神器,特别是要做代码覆盖率,直接测试controller就好了,缺点,虽然可以回滚事务,但是依赖数据库数据,解决,根据SpringBoot ,再建立一个专门跑单元测试的数据库 ...
- Spring Boot 2.x 编写 RESTful API (五) 单元测试
用Spring Boot编写RESTful API 学习笔记 概念 驱动模块 被测模块 桩模块 替代尚未开发完毕的子模块 替代对环境依赖较大的子模块 (例如数据访问层) 示例 测试 Service @ ...
- SpringBoot文件的上传与下载
⒈文件实体类 package cn.coreqi.security.entities; public class FileInfo { private String path; public File ...
- 读取Excel文件存储在实体类中
1.Maven文件 <!--读取Excel的架包--> <dependency> <groupId>org.apache.poi</groupId> & ...
- JavaEE进阶集锦(持续更新中)
1.影响Servlet生命周期的注解:@PostConstruct和@PreDestroy @PostConstruct:被修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次, ...
- 009 spring boot中文件的上传与下载
一:任务 1.任务 文件的上传 文件的下载 二:文件的上传 1.新建一个对象 FileInfo.java package com.cao.dto; public class FileInfo { pr ...
- Excel导入工具类兼容xls和xlsx
package com.bj58.finance.platform.operation.provider.util; import org.apache.log4j.Logger; import or ...
随机推荐
- [!!!!!]Inno Setup教程-常见问题解答
[转]Inno Setup教程-常见问题解答 功能 * 翻译 Inno Setup 文字 * 它支持 MBCS (多字节字符集) 吗? * 将来会支持 Windows Installer 吗? ...
- java多线程向数据库中加载数据
读取本地文件,每行为一条记录,文件大小550M,200万条数据.先将文件读取的内存中,再开启6个线程连接postgresql不同coordinator端口导入数据.代码如下: import java. ...
- Link Aggregation and LACP with Open vSwitch
In this post, I’m going to show you how to use link aggregation (via the Link Aggregation Control Pr ...
- 六 JSP 和 Servlet 的系统调优技巧
方法一:在 Servlet 的 init() 函数中申请缓冲数据 方法二:禁止 Servlet 和 JSP 的自动重载: Servlet/JSP 提供了一个实用的技术,即自动重载技术,它为开发人员提供 ...
- python中如何判断某个变量是否存在
方法一:try...except... 方法二: locals().has_key('var') var变量存在返回True, 不存在返回False 方法三:'var' in dir() 同样返回Tr ...
- Apache、tomcat、Nginx常用配置合集
配置文件地址: Apache: /etc/httpd/conf/httpd.conf tomcat: /usr/local/tomcat/conf/server.xml Nginx : /usr/l ...
- MVC&WebForm对照学习:文件上传(以图片为例)
原文 http://www.tuicool.com/articles/myM7fe 主题 HTMLMVC模式Asp.net 博客园::首页:: :: :: ::管理 5 Posts :: 0 ...
- 完全搞懂傅里叶变换和小波(2)——三个中值定理<转载>
书接上文,本文章是该系列的第二篇,按照总纲中给出的框架,本节介绍三个中值定理,包括它们的证明及几何意义.这三个中值定理是高等数学中非常基础的部分,如果读者对于高数的内容已经非常了解,大可跳过此部分.当 ...
- SQL注入测试平台 SQLol -5.DELETE注入测试
访问首页的delete模块,http://127.0.0.1/sql/delete.php,开始对delete模块进行测试. delete语法: DELETE FROM [users] WHERE [ ...
- linux下遍历目录(转-在于思考)
遍历目录的主要思想 由于目录就是一颗树,所以遍历目录就转换为遍历一棵树.谈到树的遍历就再熟悉不过了,有树的前序.层次和后序遍历,我使用的是前序遍历,后序遍历和前序遍历本质上一样,而层次遍历要比前两个麻 ...