Running into "Premature end of file" error when retrieving bpmn xmls from repositoryService

Hello,

I am trying to mutate some bpmn XML files retrieved via respositoryService.:

InputStream resourceAsStream = repositoryService.getResourceAsStream(deploymentId, resourceName);

When I attempt to convert resourceAsStream to a string, or parse it via a java DOM library (see below):

InputStream (the variable resourceAsStream) to string:

                Charset utf8Charset = StandardCharsets.UTF_8;
                String utf8CharsetName = utf8Charset.name();
                String bpmnString = IOUtils.toString(resourceAsStream, utf8CharsetName);
                resourceAsStream.close();

InputStream (the variable resourceAsStream) to DOM Object:

                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document doc = builder.parse(resourceAsStream);

…I get the following error:

ENGINE-16004 Exception while closing command context: ENGINE-09003 Could not parse 'versionTest.bpmn'. Premature end of file.
org.camunda.bpm.engine.ProcessEngineException: ENGINE-09003 Could not parse 'versionTest.bpmn'. Premature end of file.

This happens with multiple bpmn files associated with working deployments. I’ve also tried using built in camunda libraries for handling bpmns:

BpmnModelInstance modelInstance = Bpmn.readModelFromStream(resourceAsStream);

I’m not sure how “Premature end of file.” errors could ocurr across multiple working XML files…any thoughts on how to resolve this?

Hi @ct744x
Did you find any solution for this?