1 /*
2 * Copyright 2008-2019 by Emeric Vernat
3 *
4 * This file is part of Java Melody.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package net.bull.javamelody.internal.web;
19
20 import java.io.IOException;
21
22 import javax.servlet.ServletOutputStream;
23 import javax.servlet.http.HttpServletResponse;
24
25 /**
26 * Implémentation de {@link FilterServletResponseWrapper} qui fonctionne avec le {@link CompressionResponseStream}.
27 * @author Emeric Vernat
28 */
29 class CompressionServletResponseWrapper extends FilterServletResponseWrapper {
30 private final int compressionThreshold;
31
32 /**
33 * Constructeur qui crée un adapteur de ServletResponse wrappant la response spécifiée.
34 * @param response HttpServletResponse
35 * @param compressionThreshold int
36 */
37 CompressionServletResponseWrapper(HttpServletResponse response, int compressionThreshold) {
38 super(response);
39 assert compressionThreshold >= 0;
40 this.compressionThreshold = compressionThreshold;
41 }
42
43 /** {@inheritDoc} */
44 @Override
45 public ServletOutputStream createOutputStream() {
46 return new CompressionResponseStream(getHttpServletResponse(), compressionThreshold);
47 }
48
49 /**
50 * Termine et ferme la response.
51 * @throws IOException e
52 */
53 void finishResponse() throws IOException {
54 close();
55 }
56
57 /**
58 * Ne fait rien
59 * @param length int
60 */
61 @Override
62 public void setContentLength(int length) {
63 // ne fait rien
64 }
65 }
66