Revised ByteArrayOutputStream handling in MarshallingView and co

Issue: SPR-11646
(cherry picked from commit 8006696)
This commit is contained in:
Juergen Hoeller
2014-04-02 20:57:09 +02:00
parent d1030b798d
commit f014bbb5cf
3 changed files with 10 additions and 12 deletions

View File

@@ -24,7 +24,6 @@ import javax.xml.transform.stream.StreamResult;
import org.springframework.oxm.Marshaller;
import org.springframework.util.Assert;
import org.springframework.util.StreamUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.AbstractView;
@@ -104,13 +103,12 @@ public class MarshallingView extends AbstractView {
if (toBeMarshalled == null) {
throw new IllegalStateException("Unable to locate object to be marshalled in model: " + model);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
this.marshaller.marshal(toBeMarshalled, new StreamResult(bos));
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
this.marshaller.marshal(toBeMarshalled, new StreamResult(baos));
setResponseContentType(request, response);
response.setContentLength(bos.size());
StreamUtils.copy(bos.toByteArray(), response.getOutputStream());
response.setContentLength(baos.size());
baos.writeTo(response.getOutputStream());
}
/**