From 2482343c4ef88dec11ee05c25a6f96bc53474bd1 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Thu, 12 Apr 2018 21:45:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E6=9E=90=E9=98=BB=E6=96=AD=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=9B=E4=BF=AE=E6=AD=A3=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=80=89=E6=8B=A9=E5=A4=9A=E4=B8=AA=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E7=9A=84=E6=97=B6=E5=80=99=E6=8A=A5=E9=94=99?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeesite/common/image/CaptchaUtils.java | 4 +- .../java/com/jeesite/common/io/FileUtils.java | 7 +-- .../com/jeesite/common/media/VideoUtils.java | 8 +-- .../jeesite/common/reflect/ClassUtils.java | 13 +++-- .../jeesite/common/text/DiffMatchPatch.java | 2 +- .../common/utils/excel/ExcelImport.java | 54 ++++++++++--------- .../common/utils/excel/ExcelWriter.java | 51 ++++++++++++------ .../jeesite/common/utils/word/WordExport.java | 13 +++-- .../java/com/jeesite/test/CodeStatistic.java | 12 ++++- .../main/resources/config/jeesite-core.yml | 2 +- 10 files changed, 98 insertions(+), 68 deletions(-) diff --git a/common/src/main/java/com/jeesite/common/image/CaptchaUtils.java b/common/src/main/java/com/jeesite/common/image/CaptchaUtils.java index acf01438..e3f26d19 100644 --- a/common/src/main/java/com/jeesite/common/image/CaptchaUtils.java +++ b/common/src/main/java/com/jeesite/common/image/CaptchaUtils.java @@ -39,9 +39,9 @@ public class CaptchaUtils { private static MarbleRippleFilterFactory mrff; // 大理石 private static void initialize(){ - if (ccs == null || true){ + if (ccs == null){ synchronized (CaptchaUtils.class) { - if (ccs == null || true){ + if (ccs == null){ // 配置初始化 ccs = new ConfigurableCaptchaService(); diff --git a/common/src/main/java/com/jeesite/common/io/FileUtils.java b/common/src/main/java/com/jeesite/common/io/FileUtils.java index d0c1ef80..bdf04805 100644 --- a/common/src/main/java/com/jeesite/common/io/FileUtils.java +++ b/common/src/main/java/com/jeesite/common/io/FileUtils.java @@ -736,7 +736,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils { if (pastLength != 0) { response.setHeader("Accept-Ranges", "bytes");// 如果是第一次下,还没有断点续传,状态是默认的 200,无需显式设置;响应的格式是:HTTP/1.1 200 OK // 不是从最开始下载, 响应的格式是: Content-Range: bytes [文件块的开始字节]-[文件的总大小 - 1]/[文件的总大小] - logger.debug("---------------不是从开始进行下载!服务器即将开始断点续传..."); + logger.debug("服务器即将开始断点续传..."); switch (rangeSwitch) { case 1: { // 针对 bytes=27000- 的请求 String contentRange = new StringBuffer("bytes ").append(new Long(pastLength).toString()).append("-") @@ -753,9 +753,6 @@ public class FileUtils extends org.apache.commons.io.FileUtils { break; } } - } else { - // 是从开始下载 - logger.debug("---------------是从开始进行下载!"); } try { @@ -798,7 +795,7 @@ public class FileUtils extends org.apache.commons.io.FileUtils { } } out.flush(); - logger.debug("---------------下载完成!"); + logger.debug("下载完成!" + file.getAbsolutePath()); } catch (IOException ie) { /** * 在写数据的时候, 对于 ClientAbortException 之类的异常, diff --git a/common/src/main/java/com/jeesite/common/media/VideoUtils.java b/common/src/main/java/com/jeesite/common/media/VideoUtils.java index db131d9e..02e190d0 100644 --- a/common/src/main/java/com/jeesite/common/media/VideoUtils.java +++ b/common/src/main/java/com/jeesite/common/media/VideoUtils.java @@ -438,9 +438,7 @@ public class VideoUtils { BufferedReader br = new BufferedReader(new InputStreamReader(__is)); String line = null; while ((line = br.readLine()) != null) { - if (line != null){ - log.debug(line); - } + log.debug(line); } } catch (Exception e) { e.printStackTrace(); @@ -461,9 +459,7 @@ public class VideoUtils { BufferedReader br = new BufferedReader(new InputStreamReader(__is)); String line = null; while ((line = br.readLine()) != null) { - if (line != null){ - log.error(line); - } + log.error(line); } } catch (Exception e) { e.printStackTrace(); diff --git a/common/src/main/java/com/jeesite/common/reflect/ClassUtils.java b/common/src/main/java/com/jeesite/common/reflect/ClassUtils.java index 375b02fe..be6abf30 100644 --- a/common/src/main/java/com/jeesite/common/reflect/ClassUtils.java +++ b/common/src/main/java/com/jeesite/common/reflect/ClassUtils.java @@ -244,8 +244,9 @@ public class ClassUtils { if (test.matches(type)) { matches.add((Class) type); } - } catch (Throwable t) { - log.warn("Could not examine class '" + fqn + "'" + " due to a " + t.getClass().getName() + " with message: " + t.getMessage()); + } catch (Exception t) { + log.warn("Could not examine class '" + fqn + "'" + " due to a " + + t.getClass().getName() + " with message: " + t.getMessage()); } } } @@ -682,8 +683,12 @@ class DefaultVFS extends VFS { // Failure to read the stream means this is not a JAR } finally { try { - is.close(); - } catch (Exception e) {} + if (is != null){ + is.close(); + } + } catch (Exception e) { + + } } return false; diff --git a/common/src/main/java/com/jeesite/common/text/DiffMatchPatch.java b/common/src/main/java/com/jeesite/common/text/DiffMatchPatch.java index f0f70a53..28e34ca2 100644 --- a/common/src/main/java/com/jeesite/common/text/DiffMatchPatch.java +++ b/common/src/main/java/com/jeesite/common/text/DiffMatchPatch.java @@ -849,7 +849,7 @@ public class DiffMatchPatch { thisDiff = pointer.next(); } } - while (thisDiff != null) { + while (prevDiff != null && thisDiff != null) { // while (thisDiff != null) { ThinkGem if (prevDiff.operation == Operation.DELETE && thisDiff.operation == Operation.INSERT) { String deletion = prevDiff.text; diff --git a/common/src/main/java/com/jeesite/common/utils/excel/ExcelImport.java b/common/src/main/java/com/jeesite/common/utils/excel/ExcelImport.java index 8809b130..e7a72dd3 100644 --- a/common/src/main/java/com/jeesite/common/utils/excel/ExcelImport.java +++ b/common/src/main/java/com/jeesite/common/utils/excel/ExcelImport.java @@ -409,33 +409,35 @@ public class ExcelImport { } //log.debug("Import value type: ["+i+","+column+"] " + valType); try { - if (valType == String.class){ - String s = String.valueOf(val.toString()); - if(StringUtils.endsWith(s, ".0")){ - val = StringUtils.substringBefore(s, ".0"); + if (val != null){ + if (valType == String.class){ + String s = String.valueOf(val.toString()); + if(StringUtils.endsWith(s, ".0")){ + val = StringUtils.substringBefore(s, ".0"); + }else{ + val = String.valueOf(val.toString()); + } + }else if (valType == Integer.class){ + val = Double.valueOf(val.toString()).intValue(); + }else if (valType == Long.class){ + val = Double.valueOf(val.toString()).longValue(); + }else if (valType == Double.class){ + val = Double.valueOf(val.toString()); + }else if (valType == Float.class){ + val = Float.valueOf(val.toString()); + }else if (valType == Date.class){ + if (val instanceof String){ + val = DateUtils.parseDate(val); + }else if (val instanceof Double){ + val = DateUtil.getJavaDate((Double)val); // POI Excel 日期格式转换 + } }else{ - val = String.valueOf(val.toString()); - } - }else if (valType == Integer.class){ - val = Double.valueOf(val.toString()).intValue(); - }else if (valType == Long.class){ - val = Double.valueOf(val.toString()).longValue(); - }else if (valType == Double.class){ - val = Double.valueOf(val.toString()); - }else if (valType == Float.class){ - val = Float.valueOf(val.toString()); - }else if (valType == Date.class){ - if (val instanceof String){ - val = DateUtils.parseDate(val); - }else if (val instanceof Double){ - val = DateUtil.getJavaDate((Double)val); // POI Excel 日期格式转换 - } - }else{ - if (ef.fieldType() != Class.class){ - val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); - }else{ - val = Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(), - "fieldtype."+valType.getSimpleName()+"Type")).getMethod("getValue", String.class).invoke(null, val.toString()); + if (ef.fieldType() != Class.class){ + val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString()); + }else{ + val = Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(), + "fieldtype."+valType.getSimpleName()+"Type")).getMethod("getValue", String.class).invoke(null, val.toString()); + } } } } catch (Exception ex) { diff --git a/common/src/main/java/com/jeesite/common/utils/excel/ExcelWriter.java b/common/src/main/java/com/jeesite/common/utils/excel/ExcelWriter.java index a22e29f2..ac1d6386 100644 --- a/common/src/main/java/com/jeesite/common/utils/excel/ExcelWriter.java +++ b/common/src/main/java/com/jeesite/common/utils/excel/ExcelWriter.java @@ -110,28 +110,45 @@ public abstract class ExcelWriter { * @param entry the name of the sheet entry to substitute, e.g. xl/worksheets/sheet1.xml * @param out the stream to write the result to */ - @SuppressWarnings("resource") private static void substitute(File zipfile, File tmpfile, String entry, OutputStream out) throws IOException { - ZipFile zip = new ZipFile(zipfile); - ZipOutputStream zos = new ZipOutputStream(out); - - @SuppressWarnings("unchecked") - Enumeration en = (Enumeration) zip.entries(); - while (en.hasMoreElements()) { - ZipEntry ze = en.nextElement(); - if (!ze.getName().equals(entry)) { - zos.putNextEntry(new ZipEntry(ze.getName())); - InputStream is = zip.getInputStream(ze); - copyStream(is, zos); + ZipFile zip = null; + ZipOutputStream zos = null; + InputStream is = null; + try{ + zip = new ZipFile(zipfile); + zos = new ZipOutputStream(out); + @SuppressWarnings("unchecked") + Enumeration en = (Enumeration) zip.entries(); + while (en.hasMoreElements()) { + ZipEntry ze = en.nextElement(); + if (!ze.getName().equals(entry)) { + zos.putNextEntry(new ZipEntry(ze.getName())); + InputStream is2 = null; + try{ + is2 = zip.getInputStream(ze); + copyStream(is2, zos); + }finally { + if (is2 != null){ + is2.close(); + } + } + } + } + zos.putNextEntry(new ZipEntry(entry)); + is = new FileInputStream(tmpfile); + copyStream(is, zos); + }finally { + if (is != null){ is.close(); } + if (zos != null){ + zos.close(); + } + if (zip != null){ + zip.close(); + } } - zos.putNextEntry(new ZipEntry(entry)); - InputStream is = new FileInputStream(tmpfile); - copyStream(is, zos); - is.close(); - zos.close(); } private static void copyStream(InputStream in, OutputStream out) diff --git a/common/src/main/java/com/jeesite/common/utils/word/WordExport.java b/common/src/main/java/com/jeesite/common/utils/word/WordExport.java index 709114f1..3eb88a9d 100644 --- a/common/src/main/java/com/jeesite/common/utils/word/WordExport.java +++ b/common/src/main/java/com/jeesite/common/utils/word/WordExport.java @@ -214,15 +214,18 @@ public class WordExport { FileOutputStream fos = null; try { fos = new FileOutputStream(newFile); + this.document.write(fos); } catch (FileNotFoundException e) { e.printStackTrace(); - } - try { - this.document.write(fos); - fos.flush(); - fos.close(); } catch (IOException e) { e.printStackTrace(); + } finally { + try { + fos.flush(); + fos.close(); + } catch (IOException e) { + e.printStackTrace(); + } } } diff --git a/common/src/test/java/com/jeesite/test/CodeStatistic.java b/common/src/test/java/com/jeesite/test/CodeStatistic.java index 0aaa4797..61ff9925 100644 --- a/common/src/test/java/com/jeesite/test/CodeStatistic.java +++ b/common/src/test/java/com/jeesite/test/CodeStatistic.java @@ -74,10 +74,12 @@ public class CodeStatistic { * @param f */ private static void count(File f) { + FileReader fr = null; BufferedReader br = null; boolean flag = false; try { - br = new BufferedReader(new FileReader(f)); + fr = new FileReader(f); + br = new BufferedReader(fr); String line = ""; while ((line = br.readLine()) != null) { line = line.trim(); // 除去注释前的空格 @@ -113,6 +115,14 @@ public class CodeStatistic { e.printStackTrace(); } } + if (fr != null){ + try { + fr.close(); + fr = null; + } catch (IOException e) { + e.printStackTrace(); + } + } } } } \ No newline at end of file diff --git a/modules/core/src/main/resources/config/jeesite-core.yml b/modules/core/src/main/resources/config/jeesite-core.yml index d1d2d194..dd3dfdf7 100644 --- a/modules/core/src/main/resources/config/jeesite-core.yml +++ b/modules/core/src/main/resources/config/jeesite-core.yml @@ -409,7 +409,7 @@ file: # 上传文件的相对路径(支持:yyyy, MM, dd, HH, mm, ss, E) uploadPath: '{yyyy}{MM}/' - # 上传单个文件最大字节(500M),在这之上还有 > Tomcat限制 > Nginx限制,等。 + # 上传单个文件最大字节(500M),在这之上还有 > Tomcat限制 > Nginx限制,等,此设置会覆盖 spring.http.multipart.maxFileSize 设置 maxFileSize: 500*1024*1024 #设置允许上传的文件后缀