OWL ITS + 탐지시스템(인터넷 진흥원)
이민희
2021-12-01 5fb1952ae91f1a739803247266e87dbd15ea1f27
src/main/java/kr/wisestone/owl/util/CommonUtil.java
@@ -344,6 +344,24 @@
        return fileMap;
    }
    //  string file 정보를 file Map 형태로 변경한다.
    public static Map<String, Object> makeFileMap(String fileName, String file, String contentType) {
        Map<String, Object> fileMap = new HashMap<>();
        try {
            byte[] bytes = Base64.decodeBase64(file);
            fileMap.put("fileName", fileName);
            fileMap.put("fileSize", bytes.length);
            fileMap.put("contentType", contentType);
            fileMap.put("file", CommonUtil.bytesToFile(fileName, bytes));
        } catch (Exception e) {
            LOGGER.debug(e.getMessage());
        }
        return fileMap;
    }
    public static String getPostDataString(Map<String, String> params) throws UnsupportedEncodingException {
        StringBuilder result = new StringBuilder();
        boolean first = true;
@@ -378,6 +396,42 @@
        return convertFile;
    }
    // string을 파일로 변환
    public static File stringToFile(String fileName, String file) {
        byte[] bytes = null;
        try {
            bytes = Base64.decodeBase64(file);
        } catch (Exception ex) {
            LOGGER.debug("string to bytes 변환 오류");
        }
        if (bytes != null) {
            return bytesToFile(fileName, bytes);
        }
        return  null;
    }
    // bytes를 파일로 변환
    public static File bytesToFile(String fileName, byte[] bytes) {
        File convertFile = new File(WebAppUtil.getContextRealPath() + TMP_UPLOAD_FOLDER + getFileNameByUUID(fileName));
        if (!convertFile.exists()) {
            convertFile.mkdirs();
        }
        try{
            FileOutputStream lFileOutputStream = new FileOutputStream(convertFile);
            lFileOutputStream.write(bytes);
            lFileOutputStream.close();
        }catch (IllegalStateException | IOException e) {
            LOGGER.debug("bytes 파일 file 변환 오류");
        }
        return convertFile;
    }
    public static InputStream getFileInputStream(String strPath, String strNewFileName){
        InputStream objInputStream = null;