Package org.springframework.mock.web
Class MockPart
- java.lang.Object
- org.springframework.mock.web.MockPart
- All Implemented Interfaces:
Part
public class MockPart extends Object implements Part
Mock implementation ofjavax.servlet.http.Part.- Since:
- 4.3.12
- Author:
- Rossen Stoyanchev, Juergen Hoeller
- See Also:
MockHttpServletRequest.addPart(javax.servlet.http.Part),MockMultipartFile
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()Deletes the underlying storage for a file item, including deleting any associated temporary disk file.StringgetContentType()Gets the content type of this part.StringgetHeader(String name)Returns the value of the specified mime header as aString.Collection<String>getHeaderNames()Gets the header names of this Part.HttpHeadersgetHeaders()Return theHttpHeadersbacking 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.InputStreamgetInputStream()Gets the content of this part as an InputStreamStringgetName()Gets the name of this partlonggetSize()Returns the size of this fille.StringgetSubmittedFileName()Gets the file name specified by the clientvoidwrite(String fileName)A convenience method to write this uploaded item to disk.
Constructor Detail
MockPart
public MockPart(String name, @Nullable byte[] content)
Constructor for a part with byte[] content only.- See Also:
getHeaders()
Method Detail
getName
public String getName()
Description copied from interface:javax.servlet.http.PartGets the name of this part
getSubmittedFileName
@Nullable public String getSubmittedFileName()
Description copied from interface:javax.servlet.http.PartGets the file name specified by the client- Specified by:
getSubmittedFileNamein interfacePart- Returns:
- the submitted file name
getContentType
@Nullable public String getContentType()
Description copied from interface:javax.servlet.http.PartGets the content type of this part.- Specified by:
getContentTypein interfacePart- Returns:
- The content type of this part.
getSize
public long getSize()
Description copied from interface:javax.servlet.http.PartReturns the size of this fille.
getInputStream
public InputStream getInputStream() throws IOException
Description copied from interface:javax.servlet.http.PartGets the content of this part as an InputStream- Specified by:
getInputStreamin interfacePart- Returns:
- The content of this part as an InputStream
- Throws:
IOException- If an error occurs in retrieving the content as an InputStream
write
public void write(String fileName) throws IOException
Description copied from interface:javax.servlet.http.PartA 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.
- Specified by:
writein interfacePart- Parameters:
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.- Throws:
IOException- if an error occurs.
delete
public void delete() throws IOException
Description copied from interface:javax.servlet.http.PartDeletes the underlying storage for a file item, including deleting any associated temporary disk file.- Specified by:
deletein interfacePart- Throws:
IOException- if an error occurs.
getHeader
@Nullable public String getHeader(String name)
Description copied from interface:javax.servlet.http.PartReturns 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)
Description copied from interface:javax.servlet.http.PartGets the values of the Part header with the given name.Any changes to the returned
Collectionmust not affect thisPart.Part header names are case insensitive.
- Specified by:
getHeadersin interfacePart- Parameters:
name- the header name whose values to return- Returns:
- a (possibly empty)
Collectionof the values of the header with the given name
getHeaderNames
public Collection<String> getHeaderNames()
Description copied from interface:javax.servlet.http.PartGets 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
nullAny changes to the returned
Collectionmust not affect thisPart.- Specified by:
getHeaderNamesin interfacePart- Returns:
- a (possibly empty)
Collectionof the header names of this Part
getHeaders
public final HttpHeaders getHeaders()
Return theHttpHeadersbacking header related accessor methods, allowing for populating selected header entries.