1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
21
21
import java .io .OutputStreamWriter ;
22
22
import java .io .PrintWriter ;
23
23
import java .io .UnsupportedEncodingException ;
24
-
25
24
import javax .servlet .FilterChain ;
26
25
import javax .servlet .ServletException ;
27
26
import javax .servlet .ServletOutputStream ;
31
30
32
31
import org .springframework .util .Assert ;
33
32
import org .springframework .util .DigestUtils ;
34
- import org .springframework .util .FileCopyUtils ;
33
+ import org .springframework .util .StreamUtils ;
35
34
import org .springframework .web .util .WebUtils ;
36
35
37
36
/**
48
47
*/
49
48
public class ShallowEtagHeaderFilter extends OncePerRequestFilter {
50
49
51
- private static String HEADER_ETAG = "ETag" ;
50
+ private static final String HEADER_ETAG = "ETag" ;
52
51
53
- private static String HEADER_IF_NONE_MATCH = "If-None-Match" ;
52
+ private static final String HEADER_IF_NONE_MATCH = "If-None-Match" ;
54
53
55
54
56
55
/**
@@ -117,7 +116,7 @@ private void updateResponse(HttpServletRequest request, HttpServletResponse resp
117
116
private void copyBodyToResponse (byte [] body , HttpServletResponse response ) throws IOException {
118
117
if (body .length > 0 ) {
119
118
response .setContentLength (body .length );
120
- FileCopyUtils .copy (body , response .getOutputStream ());
119
+ StreamUtils .copy (body , response .getOutputStream ());
121
120
}
122
121
}
123
122
@@ -166,7 +165,7 @@ private static class ShallowEtagResponseWrapper extends HttpServletResponseWrapp
166
165
167
166
private int statusCode = HttpServletResponse .SC_OK ;
168
167
169
- private ShallowEtagResponseWrapper (HttpServletResponse response ) {
168
+ public ShallowEtagResponseWrapper (HttpServletResponse response ) {
170
169
super (response );
171
170
}
172
171
@@ -233,6 +232,7 @@ private byte[] toByteArray() {
233
232
return this .content .toByteArray ();
234
233
}
235
234
235
+
236
236
private class ResponseServletOutputStream extends ServletOutputStream {
237
237
238
238
@ Override
@@ -246,9 +246,10 @@ public void write(byte[] b, int off, int len) throws IOException {
246
246
}
247
247
}
248
248
249
+
249
250
private class ResponsePrintWriter extends PrintWriter {
250
251
251
- private ResponsePrintWriter (String characterEncoding ) throws UnsupportedEncodingException {
252
+ public ResponsePrintWriter (String characterEncoding ) throws UnsupportedEncodingException {
252
253
super (new OutputStreamWriter (content , characterEncoding ));
253
254
}
254
255
0 commit comments