类 MockPart
- java.lang.Object
- org.springframework.mock.web.MockPart
- 所有已实现的接口:
Part
public class MockPart extends Object implements Part
Mock implementation ofjavax.servlet.http.Part
.- 从以下版本开始:
- 4.3.12
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
- 另请参阅:
MockHttpServletRequest.addPart(javax.servlet.http.Part)
,MockMultipartFile
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
delete()
Deletes the underlying storage for a file item, including deleting any associated temporary disk file.String
getContentType()
Gets the content type of this part.String
getHeader(String name)
Returns the value of the specified mime header as aString
.Collection<String>
getHeaderNames()
Gets the header names of this Part.HttpHeaders
getHeaders()
Return theHttpHeaders
backing header related accessor methods, allowing for populating selected header entries.Collection<String>
getHeaders(String name)
Gets the values of the Part header with the given name.InputStream
getInputStream()
Gets the content of this part as an InputStreamString
getName()
Gets the name of this partlong
getSize()
Returns the size of this fille.String
getSubmittedFileName()
Gets the file name specified by the clientvoid
write(String fileName)
A convenience method to write this uploaded item to disk.
构造器详细资料
MockPart
public MockPart(String name, @Nullable byte[] content)
Constructor for a part with byte[] content only.- 另请参阅:
getHeaders()
方法详细资料
getName
public String getName()
从接口复制的说明:javax.servlet.http.Part
Gets the name of this part
getSubmittedFileName
@Nullable public String getSubmittedFileName()
从接口复制的说明:javax.servlet.http.Part
Gets the file name specified by the client- 指定者:
getSubmittedFileName
在接口中Part
- 返回:
- the submitted file name
getContentType
@Nullable public String getContentType()
从接口复制的说明:javax.servlet.http.Part
Gets the content type of this part.- 指定者:
getContentType
在接口中Part
- 返回:
- The content type of this part.
getSize
public long getSize()
从接口复制的说明:javax.servlet.http.Part
Returns the size of this fille.
getInputStream
public InputStream getInputStream() throws IOException
从接口复制的说明:javax.servlet.http.Part
Gets the content of this part as an InputStream- 指定者:
getInputStream
在接口中Part
- 返回:
- The content of this part as an InputStream
- 抛出:
IOException
- If an error occurs in retrieving the content as an InputStream
write
public void write(String fileName) throws IOException
从接口复制的说明:javax.servlet.http.Part
A convenience method to write this uploaded item to disk.This method is not guaranteed to succeed if called more than once for the same part. This allows a particular implementation to use, for example, file renaming, where possible, rather than copying all of the underlying data, thus gaining a significant performance benefit.
- 指定者:
write
在接口中Part
- 参数:
fileName
- The location into which the uploaded part should be stored. The value may be a file name or a path. The actual location of the file in the filesystem is relative toMultipartConfigElement.getLocation()
. Absolute paths are used as provided and are relative togetLocation()
. Note: that this is a system dependent string and URI notation may not be acceptable on all systems. For portability, this string should be generated with the File or Path APIs.- 抛出:
IOException
- if an error occurs.
delete
public void delete() throws IOException
从接口复制的说明:javax.servlet.http.Part
Deletes the underlying storage for a file item, including deleting any associated temporary disk file.- 指定者:
delete
在接口中Part
- 抛出:
IOException
- if an error occurs.
getHeader
@Nullable public String getHeader(String name)
从接口复制的说明:javax.servlet.http.Part
Returns the value of the specified mime header as aString
. If the Part did not include a header of the specified name, this method returnsnull
. If there are multiple headers with the same name, this method returns the first header in the part. The header name is case insensitive. You can use this method with any request header.
getHeaders
public Collection<String> getHeaders(String name)
从接口复制的说明:javax.servlet.http.Part
Gets the values of the Part header with the given name.Any changes to the returned
Collection
must not affect thisPart
.Part header names are case insensitive.
- 指定者:
getHeaders
在接口中Part
- 参数:
name
- the header name whose values to return- 返回:
- a (possibly empty)
Collection
of the values of the header with the given name
getHeaderNames
public Collection<String> getHeaderNames()
从接口复制的说明:javax.servlet.http.Part
Gets the header names of this Part.Some servlet containers do not allow servlets to access headers using this method, in which case this method returns
null
Any changes to the returned
Collection
must not affect thisPart
.- 指定者:
getHeaderNames
在接口中Part
- 返回:
- a (possibly empty)
Collection
of the header names of this Part
getHeaders
public final HttpHeaders getHeaders()
Return theHttpHeaders
backing header related accessor methods, allowing for populating selected header entries.