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.core;
018
019import java.io.IOException;
020import java.io.InputStream;
021import java.nio.charset.Charset;
022import java.nio.charset.UnsupportedCharsetException;
023
024import org.apache.commons.io.Charsets;
025
026/**
027 * Abstracts access to the request information needed for file uploads.
028 * <p>
029 * This interface should be implemented for each type of request that may be handled by FileUpload, such as servlets and portlets.
030 * </p>
031 */
032public interface RequestContext {
033
034    /**
035     * Gets the character encoding for the request.
036     *
037     * @return The character encoding for the request.
038     */
039    String getCharacterEncoding();
040
041    /**
042     * Gets the character encoding for the request or null if unspecified.
043     *
044     * @return The character encoding for the request or null.
045     * @throws UnsupportedCharsetException If the named Charset is unavailable.
046     */
047    default Charset getCharset() throws UnsupportedCharsetException {
048        return Charsets.toCharset(getCharacterEncoding(), null);
049    }
050
051    /**
052     * Gets the content length of the request.
053     *
054     * @return The content length of the request.
055     */
056    long getContentLength();
057
058    /**
059     * Gets the content type of the request.
060     *
061     * @return The content type of the request.
062     */
063    String getContentType();
064
065    /**
066     * Gets the input stream for the request.
067     *
068     * @return The input stream for the request.
069     * @throws IOException if a problem occurs.
070     */
071    InputStream getInputStream() throws IOException;
072
073}