All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.jfunc.http.component.CompositeContentCallBackCreator Maven / Gradle / Ivy

package top.jfunc.http.component;

import top.jfunc.http.base.ContentCallback;
import top.jfunc.http.request.HttpRequest;
import top.jfunc.http.request.UploadRequest;

import java.io.IOException;

/**
 * @see top.jfunc.http.smart.AbstractSmartHttpClient
 * @author xiongshiyan at 2020/10/15 , contact me with email [email protected] or phone 15208384257
 */
public class CompositeContentCallBackCreator implements ContentCallbackCreator {
    private ContentCallbackCreator bodyContentCallbackCreator;
    private ContentCallbackCreator uploadContentCallbackCreator;


    public CompositeContentCallBackCreator(ContentCallbackCreator bodyContentCallbackCreator,
                                           ContentCallbackCreator uploadContentCallbackCreator) {
        this.bodyContentCallbackCreator = bodyContentCallbackCreator;
        this.uploadContentCallbackCreator = uploadContentCallbackCreator;
    }

    @Override
    public ContentCallback create(HttpRequest httpRequest) throws IOException {
        if(httpRequest instanceof UploadRequest){
            return getUploadContentCallbackCreator().create(httpRequest);
        }
        return getBodyContentCallbackCreator().create(httpRequest);
    }

    public ContentCallbackCreator getBodyContentCallbackCreator() {
        return bodyContentCallbackCreator;
    }

    public ContentCallbackCreator getUploadContentCallbackCreator() {
        return uploadContentCallbackCreator;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy