/** * Write the stream to a temporary storage and calculate the content length * @param entity HTTPEntity * @param messageFormatter message formatter * @param msgContext current message context * @param format message format * @throws IOException if an exception occurred while writing data */ private void setStreamAsTempData(BasicHttpEntity entity, MessageFormatter messageFormatter, MessageContext msgContext, OMOutputFormat format) throws IOException { TemporaryData serialized = new TemporaryData(256, 4096, "http-nio_", ".dat"); OutputStream out = serialized.getOutputStream(); try { messageFormatter.writeTo(msgContext, format, out, true); } finally { out.close(); } msgContext.setProperty(NhttpConstants.SERIALIZED_BYTES, serialized); entity.setContentLength(serialized.getLength()); }