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.servlet5;
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     * Constructs a context for this request.
033     *
034     * @param request The request to which this context applies.
035     */
036    public JakartaServletRequestContext(final HttpServletRequest request) {
037        super(request::getHeader, request::getContentLength, request);
038    }
039
040    /**
041     * Gets the character encoding for the request.
042     *
043     * @return The character encoding for the request.
044     */
045    @Override
046    public String getCharacterEncoding() {
047        return getRequest().getCharacterEncoding();
048    }
049
050    /**
051     * Gets the content type of the request.
052     *
053     * @return The content type of the request.
054     */
055    @Override
056    public String getContentType() {
057        return getRequest().getContentType();
058    }
059
060    /**
061     * Gets the input stream for the request.
062     *
063     * @return The input stream for the request.
064     * @throws IOException if a problem occurs.
065     */
066    @Override
067    public InputStream getInputStream() throws IOException {
068        return getRequest().getInputStream();
069    }
070
071}