{"record":{"id":"0040f9bf2acbfd7e","repo":"flowable/flowable-engine","slug":"couldn-t-read-input-stream-inputstreamname-0040f9","errorCode":null,"errorMessage":"couldn't read input stream ${inputStreamName}","messagePattern":"couldn't read input stream (.+?)","errorType":"exception","errorClass":"org.activiti.engine.ActivitiException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/IoUtil.java","lineNumber":45,"sourceCode":"\n/**\n * @author Tom Baeyens\n * @author Frederik Heremans\n * @author Joram Barrez\n */\npublic class IoUtil {\n\n    public static byte[] readInputStream(InputStream inputStream, String inputStreamName) {\n        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();\n        byte[] buffer = new byte[16 * 1024];\n        try {\n            int bytesRead = inputStream.read(buffer);\n            while (bytesRead != -1) {\n                outputStream.write(buffer, 0, bytesRead);\n                bytesRead = inputStream.read(buffer);\n            }\n        } catch (Exception e) {\n            throw new ActivitiException(\"couldn't read input stream \" + inputStreamName, e);\n        }\n        return outputStream.toByteArray();\n    }\n\n    public static String readFileAsString(String filePath) {\n        byte[] buffer = new byte[(int) getFile(filePath).length()];\n        BufferedInputStream inputStream = null;\n        try {\n            inputStream = new BufferedInputStream(new FileInputStream(getFile(filePath)));\n            inputStream.read(buffer);\n        } catch (Exception e) {\n            throw new ActivitiException(\"Couldn't read file \" + filePath + \": \" + e.getMessage());\n        } finally {\n            IoUtil.closeSilently(inputStream);\n        }\n        return new String(buffer);\n    }\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/util/IoUtil.java#L27-L63","documentation":"IoUtil.readInputStream copies an InputStream into a byte[]; any exception during reading/writing (IOException, closed stream, broken connection) is wrapped in this ActivitiException, with the stream's descriptive name included.","triggerScenarios":"Calling IoUtil.readInputStream(inputStream, name) where the stream throws during read(): stream already closed, socket broken mid-read, or errors from a file/network-backed stream.","commonSituations":"Reading deployment resources from a closed connection; streams consumed twice (second read after the stream is exhausted); timeouts on remote resource streams.","solutions":["Check the wrapped cause (e.getCause()) to identify the underlying I/O failure.","Ensure the InputStream is open and not yet fully consumed when passed in.","Use standard java.io/nio APIs with try-with-resources for custom scenarios instead of re-reading the same stream."],"exampleFix":"// before\nbyte[] data = IoUtil.readInputStream(inputStream, \"resource\");\nbyte[] again = IoUtil.readInputStream(inputStream, \"resource\"); // throws: stream consumed\n// after\nbyte[] data = IoUtil.readInputStream(inputStream, \"resource\");\nbyte[] again = data; // reuse bytes; never re-read a consumed stream","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    byte[] data = IoUtil.readInputStream(in, name);\n} catch (ActivitiException e) {\n    if (e.getCause() instanceof java.io.IOException) { /* reopen stream or abort */ }\n}","preventionTips":["Never read the same InputStream twice; streams are single-use","Use try-with-resources and check stream open state before passing it","For remote streams, apply timeouts and retry with a fresh stream"],"tags":["io","stream","exception-wrapping"],"backgroundTag":"file-read-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}