1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.server.shared;
2021import java.io.IOException;
22import java.io.OutputStreamWriter;
23import java.io.PrintWriter;
24import java.io.UnsupportedEncodingException;
2526import javax.servlet.ServletOutputStream;
27import javax.servlet.http.HttpServletResponse;
28import javax.servlet.http.HttpServletResponseWrapper;
2930publicclassNoBodyHttpServletResponseWrapperextends HttpServletResponseWrapper {
3132privatefinalNoBodyOutputStream noBodyStream;
33private PrintWriter writer;
3435publicNoBodyHttpServletResponseWrapper(HttpServletResponse response) throws IOException {
36super(response);
37 noBodyStream = newNoBodyOutputStream();
38 }
3940 @Override
41public ServletOutputStream getOutputStream() throws IOException {
42return noBodyStream;
43 }
4445 @Override
46public PrintWriter getWriter() throws UnsupportedEncodingException {
47if (writer == null) {
48 writer = new PrintWriter(new OutputStreamWriter(noBodyStream, getCharacterEncoding()));
49 }
5051return writer;
52 }
5354privatestaticclassNoBodyOutputStreamextends ServletOutputStream {
55 @Override
56publicvoid write(int b) throws IOException {
57// ignore58 }
5960 @Override
61publicvoid write(byte[] b) throws IOException {
62// ignore63 }
6465 @Override
66publicvoid write(byte[] b, int off, int len) throws IOException {
67// ignore68 }
69 }
70 }