Confluence macro: Convert VTL FileInputStream to a Javascript String?


I’m implementing a Confluence Macro, using some of the objects available in the VTL context.

What I want to do is to access the underlying JSON content of an attachment.

So far I’m able to access the attachment with this code (a mix of VTL and Javascript):

#set($vtl_filename = 'my_file.json')
var filename = "$vtl_filename";

#set ($att = $attachmentManager.getAttachment($content, $vtl_filename))
#if (! $att)
    console.log("no attachment found");
    console.log("attachement found");
    #set($data = $attachmentManager.getAttachmentData($att))

    ## How can I get the String value of $data ???


However I’m stuck with the getAttachmentData function, which returns an InputStream (or more precisely, a FileInputStream). I want to get the content as a string (the JSON in the attachment), e.g. read what’s in the stream.

How can I do that using VTL? Is there a way to dump what’s in the stream into a String?

Also, How would I pass the result to the Javascript side of the Macro?



Let me reframe the problem more precisely. I think this specifically refers to the Atlassian API :

They give access to the $attachmentManager as specified here:

This manager has a method which is getAttachmentData() and returns an inputStream:

InputStream getAttachmentData(Attachment attachment)

Retrieve the data for attachment

Which method of the API should I use to extract the content of the InputStream ?

I want get the text contained in the inputStream.