lxw
2023-11-22 cba96d4cbd3ddd8af20b2d65d1f430c75f667821
2.2.9资源未释放
12个文件已修改
297 ■■■■ 已修改文件
src/main/java/com/whyc/controller/FaceController.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/LicenseController.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/StandardFeatureCurveController.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/encryption/SM2.java 96 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/properties/LinkProperties.java 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/properties/PropertiesUtil.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattRealdataService.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/EchartPictureDowloadService.java 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/Ld9testdataService.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/Station3DService.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/util/ActionUtil.java 35 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/util/HttpUtil.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/FaceController.java
@@ -130,16 +130,22 @@
                //文件全路径
                String fileName = fileDirName + File.separator + uName + ".jpg";
                FileOutputStream fot=null;
                try {
                    FileOutputStream fot = new FileOutputStream(fileName);
                    fot = new FileOutputStream(fileName);
                    fot.write(dataBytes);
                    fot.flush();
                    fot.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    if(fot!=null){
                        try {
                            fot.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
                /*=========数据库表更新===========*/
@@ -208,16 +214,21 @@
                //文件全路径
                String fileName = fileDirName + File.separator + uName + ".jpg";
                FileOutputStream fot =null;
                try {
                    FileOutputStream fot = new FileOutputStream(fileName);
                    fot = new FileOutputStream(fileName);
                    fot.write(dataBytes);
                    fot.flush();
                    fot.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    if(fot!=null){
                        try {
                            fot.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
                return new Response().setII(1,"更新成功");
            }
src/main/java/com/whyc/controller/LicenseController.java
@@ -184,6 +184,7 @@
        fileName = ActionUtil.filterFileName(fileName);
        ClassPathResource classPathResource = new ClassPathResource("/config/"+fileName);
        InputStream inputStream_pub = null;
        FileOutputStream fos=null;
        ApplicationHome applicationHome = new ApplicationHome(LicenseController.class);
        File jarFile = applicationHome.getDir();
        String fileDirName = jarFile.getParentFile().toString()+ File.separator+"ksm";
@@ -191,16 +192,31 @@
        createFile(fileDirName);//创建文件夹ksm
        try {
            inputStream_pub = classPathResource.getInputStream();
            FileOutputStream fos = new FileOutputStream(fileDirName+"/"+fileName);
            fos = new FileOutputStream(fileDirName+"/"+fileName);
            byte[] b = new byte[1024];
            int length;
            while((length = inputStream_pub.read(b))>0){
                fos.write(b,0,length);
            }
            inputStream_pub.close();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(inputStream_pub!=null){
                try {
                    inputStream_pub.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return fileDirName;
    }
src/main/java/com/whyc/controller/StandardFeatureCurveController.java
@@ -12,6 +12,7 @@
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.sql.ResultSet;
import java.util.List;
@@ -41,7 +42,15 @@
        if(!name.substring(name.length()-4).equals(".xls") && !name.substring(name.length()-5).equals(".xlsx")){
            response.set(1,false,"文件类型错误");
        }else{
            service.excelImport(file.getInputStream());
            InputStream is=file.getInputStream();
            service.excelImport(is);
            if(is!=null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            response.set(1,true,"数据导入完成");
        }
        return response;
src/main/java/com/whyc/encryption/SM2.java
@@ -391,15 +391,23 @@
     */
    public void exportPublicKey(ECPoint publicKey, String path) {
        File file = new File(path);
        FileOutputStream fos=null;
        try {
            if (!file.exists())
                file.createNewFile();
            byte buffer[] = publicKey.getEncoded(false);
            FileOutputStream fos = new FileOutputStream(file);
            fos = new FileOutputStream(file);
            fos.write(buffer);
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
@@ -411,10 +419,12 @@
     */
    public ECPoint importPublicKey(String path) {
        File file = new File(path);
        FileInputStream fis =null;
        ECPoint ec=null;
        try {
            if (!file.exists())
                return null;
            FileInputStream fis = new FileInputStream(file);
            fis = new FileInputStream(file);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte buffer[] = new byte[16];
@@ -422,12 +432,19 @@
            while ((size = fis.read(buffer)) != -1) {
                baos.write(buffer, 0, size);
            }
            fis.close();
            return curve.decodePoint(baos.toByteArray());
            ec=curve.decodePoint(baos.toByteArray());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(fis!=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
        return ec;
    }
    /**
@@ -438,14 +455,23 @@
     */
    public void exportPrivateKey(BigInteger privateKey, String path) {
        File file = new File(path);
        ObjectOutputStream oos =null;
        try {
            if (!file.exists())
                file.createNewFile();
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
            oos = new ObjectOutputStream(new FileOutputStream(file));
            oos.writeObject(privateKey);
            oos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(oos!=null){
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
@@ -457,20 +483,35 @@
     */
    public BigInteger importPrivateKey(String path) {
        File file = new File(path);
        FileInputStream fis =null;
        ObjectInputStream ois =null;
        BigInteger res =null;
        try {
            if (!file.exists()) {
                return null;
            }
            FileInputStream fis = new FileInputStream(file);
            ObjectInputStream ois = new ObjectInputStream(fis);
            BigInteger res = (BigInteger) (ois.readObject());
            ois.close();
            fis.close();
            return res;
             fis = new FileInputStream(file);
             ois = new ObjectInputStream(fis);
             res = (BigInteger) (ois.readObject());
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(fis!=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(ois!=null){
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
        return res;
    }
    /**
@@ -796,16 +837,31 @@
    public static BigInteger getPrivateKey(){
        ClassPathResource classPathResource = new ClassPathResource("/config/pri_key.ksm");
        InputStream inputStream = null;
        BigInteger res=null;
        ObjectInputStream ois=null;
        try {
            inputStream = classPathResource.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(inputStream);
            BigInteger res = (BigInteger) (ois.readObject());
            ois.close();
            return res;
            ois = new ObjectInputStream(inputStream);
            res = (BigInteger) (ois.readObject());
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
            return null;
        }finally {
            if(inputStream!=null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(ois!=null){
                try {
                    ois.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return res;
    }
    /**
src/main/java/com/whyc/properties/LinkProperties.java
@@ -28,16 +28,25 @@
     * 从指定路径加载信息到Properties 
     * @param path 
     */  
    public LinkProperties(String path) {
    public LinkProperties(String path) {
        InputStream is=null;
        try {  
            InputStream is = new FileInputStream(path);
            is = new FileInputStream(path);
            this.load(is);  
        } catch (FileNotFoundException e) {  
            e.printStackTrace();  
            throw new RuntimeException("指定文件不存在!");  
        } catch (IOException e) {  
            e.printStackTrace();  
        }
        } finally {
            if(is!=null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }  
      
    /** 
@@ -88,21 +97,29 @@
     * @param path 指定路径 
     * @param charset 文件编码 
     */  
    public void store(String path, String charset) {
    public void store(String path, String charset) {
        OutputStream os =null;
        if (path != null && !"".equals(path)) {  
            try {  
                OutputStream os = new FileOutputStream(path);
                os = new FileOutputStream(path);
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os, charset));  
                this.store(bw, null);  
                bw.close();
            } catch (FileNotFoundException e) {
            } catch (FileNotFoundException e) {
                e.printStackTrace();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }
            } finally {
                if(os!=null){
                    try {
                        os.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        } else {  
            throw new RuntimeException("存储路径不能为空!");  
        }
        }
    }  
  
    /** 
src/main/java/com/whyc/properties/PropertiesUtil.java
@@ -3,6 +3,9 @@
import lombok.extern.log4j.Log4j2;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.io.InputStream;
/**
 * @Description 读取Properties的工具类
 */
@@ -21,11 +24,21 @@
        } else {
            sysName += ".properties";
        }*/
        InputStream is=null;
        try {
            propertiesShiro.load(PropertiesUtil.class.getClassLoader()
                    .getResourceAsStream("config/authentication.properties"));
            is=PropertiesUtil.class.getClassLoader()
                    .getResourceAsStream("config/authentication.properties");
            propertiesShiro.load(is);
        } catch (Exception e) {
            log.warn("资源路径中不存在authentication.properties权限文件,忽略读取!");
        }finally {
            if(is!=null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
src/main/java/com/whyc/service/BattRealdataService.java
@@ -245,7 +245,13 @@
            Object target = ReflectUtil.getTarget(data, addProperties);
            dataList.add(target);
        }
        if(inputStream!=null){
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return new Response().set(1, dataList);
    }
src/main/java/com/whyc/service/EchartPictureDowloadService.java
@@ -401,9 +401,16 @@
                    in = new FileInputStream(picroot + files[i].getName());
                    data = new byte[in.available()];
                    in.read(data);
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }finally {
                    if(in!=null){
                        try {
                            in.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
                listbyte.add(data);
            }
src/main/java/com/whyc/service/Ld9testdataService.java
@@ -160,13 +160,14 @@
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    out.flush();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                if(out!=null){
                    try {
                        out.flush();
                        out.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        return true;
src/main/java/com/whyc/service/Station3DService.java
@@ -69,6 +69,7 @@
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] dataBytes = new byte[0];
        String pictureUrl="";
        FileOutputStream fot =null;
        try {
            dataBytes = decoder.decodeBuffer(fileData);
            /*=========图片保存===========*/
@@ -99,13 +100,19 @@
            //文件全路径
            String fileName = fileDirName + File.separator + pictureName + ".jpg";
            FileOutputStream fot = new FileOutputStream(fileName);
            fot = new FileOutputStream(fileName);
            fot.write(dataBytes);
            fot.flush();
            fot.close();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(fot!=null){
                try {
                    fot.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        /*=========数据库表更新===========*/
src/main/java/com/whyc/util/ActionUtil.java
@@ -422,10 +422,17 @@
            inputStream = new FileInputStream(imgFile);
            data = new byte[inputStream.available()];
            inputStream.read(data);
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        }finally {
            if(inputStream!=null){
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        // 加密
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(data);
@@ -441,8 +448,10 @@
     * @return
    */
    public static boolean generateImage(String imgStr, String path) {
        if (imgStr == null) {
            return false;
        boolean bl=false;
        OutputStream out=null;
        if (imgStr == null) {
            bl=false;
        }
        BASE64Decoder decoder = new BASE64Decoder();
        try {
@@ -454,14 +463,22 @@
                    b[i] += 256;
                }
            }
            OutputStream out = new FileOutputStream(path);
            out = new FileOutputStream(path);
            out.write(b);
            out.flush();
            out.close();
            return true;
            bl=true;
        } catch (Exception e) {
            return false;
        }
            bl=false;
        }finally {
            if(out!=null){
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return bl;
    }
    
    /**
src/main/java/com/whyc/util/HttpUtil.java
@@ -135,6 +135,7 @@
    public static String doPost(String httpUrl,String requestBody) {
        HttpURLConnection connection = null;
        InputStream inputStream = null;
        OutputStream outputStream =null;
        BufferedReader bufferedReader = null;
        String result = null;// 返回结果字符串
        try {
@@ -151,12 +152,11 @@
            //请求体
            connection.setDoOutput(true);
            OutputStream outputStream = connection.getOutputStream();
            outputStream = connection.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(outputStream,"UTF-8");
            osw.write(requestBody);
            osw.flush();
            outputStream.close();
            // 发送请求
            connection.connect();
            // 通过connection连接,获取输入流
@@ -194,6 +194,13 @@
            if (connection != null) {
                connection.disconnect();// 关闭远程连接
            }
            if (null != outputStream) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }