final ManagementRequestHeader header = ManagementRequestHeader.class.cast(context.getRequestHeader());
final ManagementResponseHeader response = new ManagementResponseHeader(header.getVersion(), header.getRequestId(), null);
final InputStream is = exec.getAttachments().getInputStreams().get(index);
try {
final ByteArrayOutputStream bout = copyStream(is);
final FlushableDataOutput output = context.writeMessage(response);
try {
output.writeByte(ModelControllerProtocol.PARAM_INPUTSTREAM_LENGTH);
output.writeInt(bout.size());
output.writeByte(ModelControllerProtocol.PARAM_INPUTSTREAM_CONTENTS);
output.write(bout.toByteArray());
output.writeByte(ManagementProtocol.RESPONSE_END);
output.close();
} finally {
StreamUtils.safeClose(output);
}
} finally {
// the caller is responsible for closing the input streams