Class FileDownloadUtil

java.lang.Object
ru.vyarus.dropwizard.guice.test.client.util.FileDownloadUtil

public final class FileDownloadUtil extends Object
File download from response utility.
Since:
09.10.2025
  • Method Details

    • download

      public static Path download(jakarta.ws.rs.core.Response response, Path dir)
      Download a file from the response.

      Limitation: does not support multipart responses. Use parseFileName(String) and saveFile(String, InputStream, Path) manually directly for multipart chunks.

      Parameters:
      response - response object
      dir - target directory to save the file in
      Returns:
      downloaded ile
    • saveFile

      public static Path saveFile(String name, InputStream input, Path dir)
      Save file from input stream to target directory. If a file with the same name already exists, an index will be added to the name.
      Parameters:
      name - file name (could be without extension)
      input - file input stream
      dir - target directory
      Returns:
      downloaded file
    • readFilename

      public static @Nullable String readFilename(jakarta.ws.rs.core.Response response)
      Use jersey header parser when the multipart jar is available. Otherwise, fallback to less accurate manual parsing.
      Parameters:
      response - response object to read header from
      Returns:
      file name from content-disposition header or null if header not found
    • parseFileName

      public static @Nullable String parseFileName(jakarta.ws.rs.core.Response response)
      Less accurate version of readFilename(Response) with simplified header parsing. Used when the multipart jar is not available (and so jersey native parsing can't be used).
      Parameters:
      response - response object to read header from
      Returns:
      file name from content-disposition header or null if header not found
    • parseFileName

      public static String parseFileName(String header)
      Less accurate version of readFilename(Response) with simplified header parsing. Used when the multipart jar is not available (and so jersey native parsing can't be used).
      Parameters:
      header - content-disposition header
      Returns:
      parsed file name