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

com.qingxun.javasdkapi.request.PaperCheckDetectRequest Maven / Gradle / Ivy

package com.qingxun.javasdkapi.request;

import cn.hutool.crypto.SecureUtil;
import com.qingxun.javasdkapi.utils.InputStreamUtil;
import com.qingxun.javasdkapi.utils.Md5BytesUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.InputStream;
import java.util.TreeMap;


/**
 *论文查重文档检测字符数 上传数据
 * @author cedric
 */
public class PaperCheckDetectRequest extends BaseRequest  {


    /**
     * md5小写
     */
    private String md5;

    private File file;

    private byte[] fileBytes;

    private String fileName;



    public String getMd5() {
        return md5;
    }

    public File getFile() {
        return file;
    }

    public byte[] getFileBytes() {
        return fileBytes;
    }

    public String getFileName() {
        return fileName;
    }

    private PaperCheckDetectRequest(){

    }

    @Override
    public TreeMap transToMap(){
        TreeMap < String, Object > map = new TreeMap( );
        map.put("md5",this.md5);
        return map;
    }

    public PaperCheckDetectRequest(Builder builder){

        if (builder.file == null) {
            if (StringUtils.isEmpty(builder.fileName)) {
                throw new NullPointerException("file为空");
            }
            if (builder.fileStream == null ){
                throw new NullPointerException("file为空");
            }
        }
        if (StringUtils.isEmpty(builder.md5)) {
            if (null != builder.file) {
                builder.setMd5(SecureUtil.md5(builder.file));
            }
            if (null != builder.fileStream){
                byte[] bytes = InputStreamUtil.transToBytes(builder.fileStream);
                this.fileBytes = bytes;
                builder.setMd5(Md5BytesUtil.md5(bytes));
            }
        }
        if (StringUtils.isEmpty(builder.md5)){
            throw new NullPointerException("md5 字段为空");
        }
        this.md5 = builder.md5;
        this.file = builder.file;
        this.fileName = builder.fileName;
      }


    public static class Builder{


        private String md5;

        private File file;

        private InputStream fileStream;

        private String fileName;

        public Builder setMd5(String md5){
            this.md5 = md5;
            return this;
        }
        public Builder setFile(File file){
            this.file = file;
            return this;
        }

        public Builder setFileStream(InputStream fileStream) {
            this.fileStream = fileStream;
            return this;
        }

        public Builder setFileName(String  filename) {
            this.fileName = filename;
            return this;
        }
        public PaperCheckDetectRequest builder(){
            return new PaperCheckDetectRequest(this);
        }
    }




}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy