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 ...
随机推荐
- Think Python - Chapter 03 - Functions
3.1 Function callsIn the context of programming, a function is a named sequence of statements that p ...
- App_Code 引起的 ambiguously 问题
今天遇到了一个这样的问题,一个.net framework 4.0 的web application ,下面有一个App_Code文件夹,里面的一些公共类的build action 是 Compile ...
- ANTLR3完全参考指南读书笔记[01]
引用 Terence Parr. The Definitive ANTLR Reference, Building Domain Specific Languages(antlr3 version). ...
- gulp 制作雪碧图
雪碧图:sprite 是把多张图片拼到一张图中,提升性能的一种做法.把合并的图片一次性加载到内存中,需要时只渲染一部分. 我们选择gulp.spritesmith插件. 使用gulp时首先要在指定的任 ...
- 《C标准库》——之<stddef.h>
<stddef.h>,顾名思义,就是标准定义.C语言里这个标准库里定义了一些类型,和宏定义. <stddef.h>的内容: 类型: ptrdiff_t : 是两个指针相减的结果 ...
- iframe与frameset(转载)
frameset 在一个页面中设置一个或多个框架 不能嵌套在body标签里 frameset 它称为框架标记,是用来告知HTML文件是框架模式,并且设定可视窗口怎么分割 fram ...
- MATLAB格式化输出控制 分类: 数学 2015-07-31 23:01 3人阅读 评论(0) 收藏
MATLAB格式化输出控制 format 默认格式 format short 5字长定点数 format long 15字长定点数 format short e 5字长浮点数 format long ...
- POJ-2486 Apple Tree (树形DP)
题目大意:一棵点带权有根树,根节点为1.从根节点出发,走k步,求能收集的最大权值和. 题目分析:从一个点向其某棵子树出发有三种可能的情况: 1.停留在那棵子树上: 2.再回到这个点: 3.经过这个点走 ...
- UVALive4287 hdu2767 hdu3836 强连通
题意:有多个命题,需要证明他们可以互相推出,现在已经有一些证明关系即 A 可以证明 B,问至少还需要多少证明关系. 首先,如果某几个命题证明关系可以成环,那么这些命题必然可以相互证明,只要沿着环的边走 ...
- hdu1213 并查集
题意:有 n 个朋友,他们可能相互认识,A 认识 B,B 认识 C,则 ABC 相互认识,现在给出他们的认识情况,相互认识的人坐一桌,否则需要分开坐,问至少需要多少桌. 其实就是问并查集的个数,在初始 ...