+
+
+ final class WrappedServletOutputStream extends CountingServletOutputStream {
+
+ private final ServletOutputStream out;
+ private boolean empty;
+
+
+ public WrappedServletOutputStream() throws IOException {
+ this.out = response.getOutputStream();
+ empty = true;
+ }
+
+
+ @Override
+ boolean isZipped() {
+ return false;
+ }
+
+ @Override
+ void setBuffer(int size) {
+ if (!empty)
+ throw new IllegalStateException("attemp to change buffer size after writing data to response!");
+ }
+
+
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+
+ @Override
+ public void flush() throws IOException {
+ out.flush();
+ }
+
+ @Override
+ public void write(int i) throws IOException {
+ empty = false;
+ out.write(i);
+ }
+ }