// Path: upload-parser-core/src/main/java/com/github/elopteryx/upload/UploadContext.java
// public interface UploadContext {
// 
//     /**
//      * Returns the given request object for this parser,
//      * allowing customization during the stages of the
//      * asynchronous processing.
//      *
//      * @return The request object
//      */
//     HttpServletRequest getRequest();
// 
//     /**
//      * Returns the given user object for this parser,
//      * allowing customization during the stages of the
//      * asynchronous processing.
//      *
//      * @param clazz The class used for casting
//      * @param <T> Type parameter
//      * @return The user object, or null if it was not supplied
//      */
//     <T> T getUserObject(Class<T> clazz);
// 
//     /**
//      * Returns the currently processed part stream,
//      * allowing the caller to get available information.
//      *
//      * @return The currently processed part
//      */
//     PartStream getCurrentPart();
// 
//     /**
//      * Returns the currently active output, which was returned
//      * in the latest UploadParser#onPartBegin method. This will
//      * return a null during the part begin stage and might be
//      * null during the error stage.
//      *
//      * @return The latest output provided by the caller
//      */
//     PartOutput getCurrentOutput();
// 
//     /**
//      * Returns the parts which have already been processed. Before
//      * the onPartBegin method is called the current PartStream is
//      * added into the List returned by this method, meaning that
//      * the UploadContext#getCurrentPart will return with the last
//      * element of the list.
//      * @return The list of the processed parts, in the order they are uploaded
//      */
//     List<PartStream> getPartStreams();
// }
// 
// Path: upload-parser-core/src/main/java/com/github/elopteryx/upload/errors/MultipartException.java
// public class MultipartException extends IOException {
// 
//     /**
//      * Public constructor.
//      * @param message The exception message.
//      */
//     public MultipartException(final String message) {
//         super(message);
//     }
// }


import com.github.elopteryx.upload.UploadContext;
import com.github.elopteryx.upload.errors.MultipartException;
import java.io.IOException;
import java.io.InputStream;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
/*
 * Copyright (C) 2016 Adam Forgacs
 *
 * Licensed 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 com.github.elopteryx.upload.internal;



/**
 * The blocking implementation of the parser. This parser can be used to perform a
 * blocking parse, whether the servlet supports async mode or not.
 */
public final class BlockingUploadParser extends AbstractUploadParser {

    /**
     * The request object.
     */
    private final HttpServletRequest request;

    /**
     * The stream to read.
     */
    private InputStream inputStream;

    public BlockingUploadParser(final HttpServletRequest request) {
        this.request = request;
    }

    /**
     * Sets up the necessary objects to start the parsing. Depending upon
     * the environment the concrete implementations can be very different.
     * @throws IOException If an error occurs with the IO
     */
    private void init() throws IOException {
        init(request);
        inputStream = request.getInputStream();
    }

    /**
     * Performs a full parsing and returns the used context object.
     * @return The upload context
     * @throws IOException If an error occurred with the I/O
     * @throws ServletException If an error occurred with the servlet
     */
// Path: upload-parser-core/src/main/java/com/github/elopteryx/upload/UploadContext.java
// public interface UploadContext {
// 
//     /**
//      * Returns the given request object for this parser,
//      * allowing customization during the stages of the
//      * asynchronous processing.
//      *
//      * @return The request object
//      */
//     HttpServletRequest getRequest();
// 
//     /**
//      * Returns the given user object for this parser,
//      * allowing customization during the stages of the
//      * asynchronous processing.
//      *
//      * @param clazz The class used for casting
//      * @param <T> Type parameter
//      * @return The user object, or null if it was not supplied
//      */
//     <T> T getUserObject(Class<T> clazz);
// 
//     /**
//      * Returns the currently processed part stream,
//      * allowing the caller to get available information.
//      *
//      * @return The currently processed part
//      */
//     PartStream getCurrentPart();
// 
//     /**
//      * Returns the currently active output, which was returned
//      * in the latest UploadParser#onPartBegin method. This will
//      * return a null during the part begin stage and might be
//      * null during the error stage.
//      *
//      * @return The latest output provided by the caller
//      */
//     PartOutput getCurrentOutput();
// 
//     /**
//      * Returns the parts which have already been processed. Before
//      * the onPartBegin method is called the current PartStream is
//      * added into the List returned by this method, meaning that
//      * the UploadContext#getCurrentPart will return with the last
//      * element of the list.
//      * @return The list of the processed parts, in the order they are uploaded
//      */
//     List<PartStream> getPartStreams();
// }
// 
// Path: upload-parser-core/src/main/java/com/github/elopteryx/upload/errors/MultipartException.java
// public class MultipartException extends IOException {
// 
//     /**
//      * Public constructor.
//      * @param message The exception message.
//      */
//     public MultipartException(final String message) {
//         super(message);
//     }
// }


// Path: upload-parser-core/src/main/java/com/github/elopteryx/upload/internal/BlockingUploadParser.java
import com.github.elopteryx.upload.UploadContext;
import com.github.elopteryx.upload.errors.MultipartException;
import java.io.IOException;
import java.io.InputStream;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;

/*
 * Copyright (C) 2016 Adam Forgacs
 *
 * Licensed 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 com.github.elopteryx.upload.internal;



/**
 * The blocking implementation of the parser. This parser can be used to perform a
 * blocking parse, whether the servlet supports async mode or not.
 */
public final class BlockingUploadParser extends AbstractUploadParser {

    /**
     * The request object.
     */
    private final HttpServletRequest request;

    /**
     * The stream to read.
     */
    private InputStream inputStream;

    public BlockingUploadParser(final HttpServletRequest request) {
        this.request = request;
    }

    /**
     * Sets up the necessary objects to start the parsing. Depending upon
     * the environment the concrete implementations can be very different.
     * @throws IOException If an error occurs with the IO
     */
    private void init() throws IOException {
        init(request);
        inputStream = request.getInputStream();
    }

    /**
     * Performs a full parsing and returns the used context object.
     * @return The upload context
     * @throws IOException If an error occurred with the I/O
     * @throws ServletException If an error occurred with the servlet
     */
    public UploadContext doBlockingParse() throws IOException, ServletException {