public class MockPart extends Object implements Part
javax.servlet.http.Part.MockHttpServletRequest.addPart(javax.servlet.http.Part),
MockMultipartFile| Constructor and Description |
|---|
MockPart(String name,
byte[] content)
Constructor for a part with byte[] content only.
|
MockPart(String name,
String filename,
byte[] content)
Constructor for a part with a filename and byte[] content.
|
| Modifier and Type | Method and Description |
|---|---|
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 a
String. |
Collection<String> |
getHeaderNames()
Gets the header names of this Part.
|
HttpHeaders |
getHeaders()
Return the
HttpHeaders 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 InputStream
|
String |
getName()
Gets the name of this part
|
long |
getSize()
Returns the size of this fille.
|
String |
getSubmittedFileName()
Gets the file name specified by the client
|
void |
write(String fileName)
A convenience method to write this uploaded item to disk.
|
public MockPart(String name, @Nullable byte[] content)
getHeaders()public MockPart(String name, @Nullable String filename, @Nullable byte[] content)
getHeaders()public String getName()
javax.servlet.http.Part@Nullable public String getSubmittedFileName()
javax.servlet.http.PartgetSubmittedFileName in interface Part@Nullable public String getContentType()
javax.servlet.http.PartgetContentType in interface Partpublic long getSize()
javax.servlet.http.Partpublic InputStream getInputStream() throws IOException
javax.servlet.http.PartgetInputStream in interface PartIOException - If an error occurs in retrieving the content
as an InputStreampublic void write(String fileName) throws IOException
javax.servlet.http.PartThis 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 in interface PartfileName - 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 to MultipartConfigElement.getLocation(). Absolute
paths are used as provided and are relative to
getLocation(). 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.public void delete()
throws IOException
javax.servlet.http.Partdelete in interface PartIOException - if an error occurs.@Nullable public String getHeader(String name)
javax.servlet.http.PartString. If the Part did not include a header
of the specified name, this method returns null.
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.public Collection<String> getHeaders(String name)
javax.servlet.http.PartAny changes to the returned Collection must not
affect this Part.
Part header names are case insensitive.
getHeaders in interface Partname - the header name whose values to returnCollection of the values of
the header with the given namepublic Collection<String> getHeaderNames()
javax.servlet.http.PartSome 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 this Part.
getHeaderNames in interface PartCollection of the header
names of this Partpublic final HttpHeaders getHeaders()
HttpHeaders backing header related accessor methods,
allowing for populating selected header entries.