1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jumpmind.symmetric.web;
22
23 import java.io.ByteArrayOutputStream;
24 import java.io.PrintWriter;
25
26 import javax.servlet.ServletOutputStream;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.servlet.http.HttpServletResponseWrapper;
29
30 public class ThrottledResponseWrapper extends HttpServletResponseWrapper {
31 private ByteArrayOutputStream output;
32
33 private long maxBps = 10240L;
34
35 private long threshold = 8192L;
36
37 private long checkPoint = 1024L;
38
39 public ThrottledResponseWrapper(HttpServletResponse response) {
40 super(response);
41 output = new ByteArrayOutputStream();
42 }
43
44 public ServletOutputStream getOutputStream() {
45 return new ThrottledServletOutputStream(output, maxBps, threshold, checkPoint);
46 }
47
48 public PrintWriter getWriter() {
49 return new PrintWriter(getOutputStream(), true);
50 }
51
52 public ByteArrayOutputStream getOutput() {
53 return output;
54 }
55
56 public void setOutput(ByteArrayOutputStream output) {
57 this.output = output;
58 }
59
60 public long getMaxBps() {
61 return maxBps;
62 }
63
64 public void setMaxBps(long maxBps) {
65 this.maxBps = maxBps;
66 }
67
68 public long getThreshold() {
69 return threshold;
70 }
71
72 public void setThreshold(long threshold) {
73 this.threshold = threshold;
74 }
75
76 public long getCheckPoint() {
77 return checkPoint;
78 }
79
80 public void setCheckPoint(long checkPoint) {
81 this.checkPoint = checkPoint;
82 }
83 }