StreamResource with dynamic filename

Dear community,
I am stuck with a Button that downloads dynamic context (PDF files) and would appreciate your help:

public class DownloadStreamButton extends Anchor {

    public DownloadStreamButton(String buttonText, String filename, Supplier<byte[]> bytes) {
        super(new StreamResource(filename, () -> new ByteArrayInputStream(bytes.get())), "");

        Button button = new Button(buttonText, VaadinIcon.CLOUD_DOWNLOAD.create());
        getElement().setAttribute("download", true);

The StreamResource accepts a Supplier for the data but not for the filename.

Any advice? Thank you!

You can take a look at where this any many other helpers are implemented.

Thank you very much @quirky-zebra .

        DynamicFileDownloader downloader = new DynamicFileDownloader(name, "",
                outputStream -> {
                    try {
                    } catch (IOException ex) {
                }) {

            protected String getFileName(VaadinSession session, VaadinRequest request) {
                return "%s_%s_%d-%02d.pdf".formatted(name, employeeId.getValue(), yearSelect.getValue().getValue(), monthSelect.getValue().getValue());

I use for that, works with Vaadin14 and Vaadin24