org.apache.felix.http.javaxwrappers.ServletResponseWrapper Maven / Gradle / Ivy
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.felix.http.javaxwrappers;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import org.jetbrains.annotations.NotNull;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletResponse;
/**
* Servlet response wrapper
*/
public class ServletResponseWrapper implements javax.servlet.ServletResponse {
private final ServletResponse response;
/**
* Get a wrapper
* @param r Response
* @return Wrapped response
*/
public static javax.servlet.ServletResponse getWrapper(final ServletResponse r) {
if ( r instanceof org.apache.felix.http.jakartawrappers.ServletResponseWrapper) {
return ((org.apache.felix.http.jakartawrappers.ServletResponseWrapper)r).getResponse();
}
if ( r instanceof HttpServletResponse ) {
return new HttpServletResponseWrapper((HttpServletResponse)r);
}
return new ServletResponseWrapper(r);
}
/**
* Create new response
* @param r Wrapped response
*/
public ServletResponseWrapper(@NotNull final ServletResponse r) {
this.response = r;
}
/**
* Get the wrapped response
* @return The response
*/
public ServletResponse getResponse() {
return this.response;
}
@Override
public String getCharacterEncoding() {
return this.response.getCharacterEncoding();
}
@Override
public String getContentType() {
return this.response.getContentType();
}
@Override
public javax.servlet.ServletOutputStream getOutputStream() throws IOException {
return new ServletOutputStreamWrapper(this.response.getOutputStream());
}
@Override
public PrintWriter getWriter() throws IOException {
return this.response.getWriter();
}
@Override
public void setCharacterEncoding(final String charset) {
this.response.setCharacterEncoding(charset);
}
@Override
public void setContentLength(final int len) {
this.response.setContentLength(len);
}
@Override
public void setContentLengthLong(final long len) {
this.response.setContentLengthLong(len);
}
@Override
public void setContentType(final String type) {
this.response.setContentType(type);
}
@Override
public void setBufferSize(final int size) {
this.response.setBufferSize(size);
}
@Override
public int getBufferSize() {
return this.response.getBufferSize();
}
@Override
public void flushBuffer() throws IOException {
this.response.flushBuffer();
}
@Override
public void resetBuffer() {
this.response.resetBuffer();
}
@Override
public boolean isCommitted() {
return this.response.isCommitted();
}
@Override
public void reset() {
this.response.reset();
}
@Override
public void setLocale(final Locale loc) {
this.response.setLocale(loc);
}
@Override
public Locale getLocale() {
return this.response.getLocale();
}
}