Class ExpectedBodyFile

java.lang.Object
com.pixelservices.flash.components.http.expected.ExpectedBodyFile

public class ExpectedBodyFile extends Object
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 Details

    • ExpectedBodyFile

      public ExpectedBodyFile(String fieldName, RequestHandler requestHandler)
      Constructor for ExpectedBodyFile.
      Parameters:
      fieldName - The name of the file to be retrieved from the request body.
      requestHandler - The RequestHandler object.
    • ExpectedBodyFile

      public ExpectedBodyFile(String fieldName, String description, RequestHandler requestHandler)
      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

      public InputStream getInputStream()
      Get the InputStream of the file.
      Returns:
      the InputStream of the file.
    • getFileName

      public String getFileName()
      Get the name of the file.
      Returns:
      the file name.
    • processFile

      public void processFile(BiConsumer<InputStream,String> fileProcessor)
      Process the file with a BiConsumer.
      Parameters:
      fileProcessor - The BiConsumer that receives the file’s InputStream and file name.
    • getFieldName

      public String getFieldName()
      Get the field name.
      Returns:
      the field name.
    • getDescription

      public String getDescription()
      Get the description of the field.
      Returns:
      the description.
    • createFile

      public File createFile(Path directory, boolean overrideExisting)
      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

      public File createFile(String directory)
      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.