001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.fileupload2.jakarta;
018
019import java.io.IOException;
020import java.io.InputStream;
021
022import org.apache.commons.fileupload2.core.AbstractRequestContext;
023
024import jakarta.servlet.http.HttpServletRequest;
025
026/**
027 * Provides access to the request information needed for a request made to an HTTP servlet.
028 */
029public class JakartaServletRequestContext extends AbstractRequestContext<HttpServletRequest> {
030
031    /**
032     * The request for which the context is being provided.
033     */
034    private final HttpServletRequest request;
035
036    /**
037     * Constructs a context for this request.
038     *
039     * @param request The request to which this context applies.
040     */
041    public JakartaServletRequestContext(final HttpServletRequest request) {
042        super(request::getHeader, request::getContentLength, request);
043        this.request = request;
044    }
045
046    /**
047     * Gets the character encoding for the request.
048     *
049     * @return The character encoding for the request.
050     */
051    @Override
052    public String getCharacterEncoding() {
053        return request.getCharacterEncoding();
054    }
055
056    /**
057     * Gets the content type of the request.
058     *
059     * @return The content type of the request.
060     */
061    @Override
062    public String getContentType() {
063        return request.getContentType();
064    }
065
066    /**
067     * Gets the input stream for the request.
068     *
069     * @return The input stream for the request.
070     * @throws IOException if a problem occurs.
071     */
072    @Override
073    public InputStream getInputStream() throws IOException {
074        return request.getInputStream();
075    }
076
077}