jiangping
2023-09-21 b471c4d9a01438af23516b622eb4381c15a45073
server/platform/src/main/java/com/doumee/api/BaseController.java
@@ -5,6 +5,12 @@
import org.apache.shiro.SecurityUtils;
import  com.doumee.core.model.ApiResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
 * Controller基类
 * @author Eva.Caesar Liu
@@ -22,4 +28,35 @@
        return (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
    }
    /**
     * 获取ID集合
     *
     * @param ids 使用","隔开的多个ID
     * @return List<Integer>
     */
    protected List<Integer> getIdList (String ids) {
        String [] idArray = ids.split(",");
        List<Integer> idList = new ArrayList<>();
        for (String id : idArray) {
            idList.add(Integer.valueOf(id));
        }
        return idList;
    }
    /**
     * 获取文件字节流
     *
     * @param is 输入流
     * @return ByteArrayOutputStream
     */
    protected ByteArrayOutputStream getOutputStream (InputStream is) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] bs = new byte[is.available()];
        int len;
        while ((len = is.read(bs)) != -1) {
            baos.write(bs, 0, len);
        }
        return baos;
    }
}