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

com.qingxun.javasdkapi.request.AudioUploadTransRequest 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 AudioUploadTransRequest extends BaseRequest {

    private String from;

    private String to;


    private File file;
    private byte[] fileBytes;
    private String fileName;



    public String getFrom() {
        return from;
    }

    public String getTo() {
        return to;
    }


    public File getFile() {
        return file;
    }

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

    public String getFileName() {
        return fileName;
    }

    private AudioUploadTransRequest() {

    }


    @Override
    public TreeMap transToMap() {
        TreeMap map = new TreeMap();
        map.put("from", this.from);
        map.put("to", this.to);
        return map;
    }

    public AudioUploadTransRequest(Builder builder) {
        if (StringUtils.isEmpty(builder.from)) {
            throw new NullPointerException("from 字段为空");
        }
        if (StringUtils.isEmpty(builder.to)) {
            throw new NullPointerException("to 字段为空");
        }
        if (builder.file == null) {
            if (StringUtils.isEmpty(builder.fileName)) {
                throw new NullPointerException("file为空");
            }
            if (builder.fileStream == null ){
                throw new NullPointerException("file为空");
            }
        }
        this.from = builder.from;
        this.to = builder.to;
        this.file = builder.file;
        this.fileName = builder.fileName;
        if (null != builder.fileStream) {
            byte[] bytes = InputStreamUtil.transToBytes(builder.fileStream);
            this.fileBytes = bytes;
        }

    }


    public static class Builder {

        private String from;

        private String to;


        private File file;

        private InputStream fileStream;

        private String fileName;



        public Builder setFrom(String from) {
            this.from = from;
            return this;
        }

        public Builder setTo(String to) {
            this.to = to;
            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 AudioUploadTransRequest builder() {
            return new AudioUploadTransRequest(this);
        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy