Class ExpectedBodyFile
java.lang.Object
com.pixelservices.flash.components.http.expected.ExpectedBodyFile
The ExpectedBodyFile lets you assume the existence of a file in the request body and work with it.
Changes made: - Removed caching of the parsed file. - Fixed file creation by resolving the destination path using Path.resolve(). - Added sanitization of the file name to remove illegal characters.
-
Constructor Summary
ConstructorsConstructorDescriptionExpectedBodyFile
(String fieldName, RequestHandler requestHandler) Constructor for ExpectedBodyFile.ExpectedBodyFile
(String fieldName, String description, RequestHandler requestHandler) Constructor for ExpectedBodyFile. -
Method Summary
Modifier and TypeMethodDescriptioncreateFile
(String directory) Overloaded method to create a file using a directory path as a String.createFile
(Path directory, boolean overrideExisting) Create a file from the InputStream in the specified directory.Get the description of the field.Get the field name.Get the name of the file.Get the InputStream of the file.void
processFile
(BiConsumer<InputStream, String> fileProcessor) Process the file with a BiConsumer.
-
Constructor Details
-
ExpectedBodyFile
Constructor for ExpectedBodyFile.- Parameters:
fieldName
- The name of the file to be retrieved from the request body.requestHandler
- The RequestHandler object.
-
ExpectedBodyFile
Constructor for ExpectedBodyFile.- Parameters:
fieldName
- The name of the file to be retrieved from the request body.description
- An optional description.requestHandler
- The RequestHandler object.
-
-
Method Details
-
getInputStream
Get the InputStream of the file.- Returns:
- the InputStream of the file.
-
getFileName
Get the name of the file.- Returns:
- the file name.
-
processFile
Process the file with a BiConsumer.- Parameters:
fileProcessor
- The BiConsumer that receives the file’s InputStream and file name.
-
getFieldName
Get the field name.- Returns:
- the field name.
-
getDescription
Get the description of the field.- Returns:
- the description.
-
createFile
Create a file from the InputStream in the specified directory.- Parameters:
directory
- the target directory.overrideExisting
- if true, overwrite any existing file; if false, do not override an existing file.- Returns:
- the created File or null if an error occurred.
-
createFile
Overloaded method to create a file using a directory path as a String.- Parameters:
directory
- the target directory as a String.- Returns:
- the created File.
-