0
String output = "qwerty123";

Then how to export that string to StreamedContent in PrimeFaces ?

you can see the example here : https://www.primefaces.org/showcase/ui/file/download.xhtml?jfwid=e2fc5

In that link, the StreamedContent exported from .jpg collected from resources in Web Pages Directory. But in my case, I just want to convert the string above output to .txt then stream it in StreamedContent without Files.write();.

Thanks in advance.

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102

1 Answers1

2

You can use a ByteArrayInputStream to stream the contents of your string:

DefaultStreamedContent.builder()
        .name("your.txt")
        .contentType("text/plain")
        .stream(() -> new ByteArrayInputStream("qwerty123".getBytes(StandardCharsets.UTF_8)))
        .build();

See also:

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102