Explorar el Código

解决编译warning

陈精华 hace 3 años
padre
commit
9e5b9d4889

+ 3 - 2
office-plugin/src/main/java/org/artofsolving/jodconverter/cli/Convert.java

@@ -14,6 +14,7 @@ package org.artofsolving.jodconverter.cli;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.Charset;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
@@ -86,7 +87,7 @@ public class Convert {
         DocumentFormatRegistry registry;
         if (commandLine.hasOption(OPTION_REGISTRY.getOpt())) {
             File registryFile = new File(commandLine.getOptionValue(OPTION_REGISTRY.getOpt()));
-            registry = new JsonDocumentFormatRegistry(FileUtils.readFileToString(registryFile));
+            registry = new JsonDocumentFormatRegistry(FileUtils.readFileToString(registryFile, Charset.defaultCharset()));
         } else {
             registry = new DefaultDocumentFormatRegistry();
         }
@@ -122,5 +123,5 @@ public class Convert {
             officeManager.stop();
         }
     }
-    
+
 }

+ 2 - 1
office-plugin/src/main/java/org/artofsolving/jodconverter/document/JsonDocumentFormatRegistry.java

@@ -14,6 +14,7 @@ package org.artofsolving.jodconverter.document;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.Charset;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -25,7 +26,7 @@ import org.json.JSONObject;
 public class JsonDocumentFormatRegistry extends SimpleDocumentFormatRegistry {
 
     public JsonDocumentFormatRegistry(InputStream input) throws JSONException, IOException {
-        readJsonArray(IOUtils.toString(input));
+        readJsonArray(IOUtils.toString(input, Charset.defaultCharset()));
     }
 
     public JsonDocumentFormatRegistry(String source) throws JSONException {

+ 1 - 1
office-plugin/src/main/java/org/artofsolving/jodconverter/model/FileProperties.java

@@ -15,7 +15,7 @@ public class FileProperties {
     }
 
     public Map<String, Object> toMap() {
-        Map<String, Object> map = new HashMap();
+        Map<String, Object> map = new HashMap<>();
         if (filePassword != null) {
             map.put("Password", filePassword);
         }

+ 6 - 5
office-plugin/src/main/java/org/artofsolving/jodconverter/office/OfficeProcess.java

@@ -16,6 +16,7 @@ import static org.artofsolving.jodconverter.process.ProcessManager.PID_NOT_FOUND
 import static org.artofsolving.jodconverter.process.ProcessManager.PID_UNKNOWN;
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -134,11 +135,11 @@ class OfficeProcess {
             logger.fine("no %OFFICE_HOME%/basis-link found; assuming it's OOo 2.x and we don't need to append URE and Basic paths");
             return;
         }
-        String basisLinkText = FileUtils.readFileToString(basisLink).trim();
+        String basisLinkText = FileUtils.readFileToString(basisLink, Charset.defaultCharset()).trim();
         File basisHome = new File(officeHome, basisLinkText);
         File basisProgram = new File(basisHome, "program");
         File ureLink = new File(basisHome, "ure-link");
-        String ureLinkText = FileUtils.readFileToString(ureLink).trim();
+        String ureLinkText = FileUtils.readFileToString(ureLink, Charset.defaultCharset()).trim();
         File ureHome = new File(basisHome, ureLinkText);
         File ureBin = new File(ureHome, "bin");
         Map<String,String> environment = processBuilder.environment();
@@ -163,9 +164,9 @@ class OfficeProcess {
     }
 
     private class ExitCodeRetryable extends Retryable {
-        
+
         private int exitCode;
-        
+
         protected void attempt() throws TemporaryException, Exception {
             try {
                 exitCode = process.exitValue();
@@ -173,7 +174,7 @@ class OfficeProcess {
                 throw new TemporaryException(illegalThreadStateException);
             }
         }
-        
+
         public int getExitCode() {
             return exitCode;
         }

+ 3 - 5
office-plugin/src/main/java/org/artofsolving/jodconverter/process/LinuxProcessManager.java

@@ -13,6 +13,7 @@
 package org.artofsolving.jodconverter.process;
 
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -25,11 +26,10 @@ import org.apache.commons.io.IOUtils;
  * <p>
  * Should Work on Solaris too, except that the command line string
  * returned by <tt>ps</tt> there is limited to 80 characters and this affects
- * {@link #findPid(String)}.
  */
 public class LinuxProcessManager implements ProcessManager {
 
-    private static final Pattern PS_OUTPUT_LINE = Pattern.compile("^\\s*(\\d+)\\s+(.*)$"); 
+    private static final Pattern PS_OUTPUT_LINE = Pattern.compile("^\\s*(\\d+)\\s+(.*)$");
 
     private String[] runAsArgs;
 
@@ -74,9 +74,7 @@ public class LinuxProcessManager implements ProcessManager {
     		command = args;
     	}
         Process process = new ProcessBuilder(command).start();
-        @SuppressWarnings("unchecked")
-        List<String> lines = IOUtils.readLines(process.getInputStream());
-        return lines;
+        return IOUtils.readLines(process.getInputStream(), Charset.defaultCharset());
     }
 
 }

+ 4 - 4
server/pom.xml

@@ -183,7 +183,7 @@
             <artifactId>aspose-cad</artifactId>
             <version>19.9</version>
             <scope>system</scope>
-            <systemPath>${basedir}/lib/aspose-cad-19.9.jar</systemPath>
+            <systemPath>${pom.basedir}/lib/aspose-cad-19.9.jar</systemPath>
         </dependency>
         <!-- 编码识别 -->
         <dependency>
@@ -191,7 +191,7 @@
             <artifactId>cpdetector</artifactId>
             <version>1.04</version>
             <scope>system</scope>
-            <systemPath>${basedir}/lib/cpdetector-1.04.jar</systemPath>
+            <systemPath>${pom.basedir}/lib/cpdetector-1.04.jar</systemPath>
         </dependency>
         <!-- url 规范化 -->
         <dependency>
@@ -260,14 +260,14 @@
             <artifactId>jai_core</artifactId>
             <version>1.1.3</version>
             <scope>system</scope>
-            <systemPath>${basedir}/lib/jai_core-1.1.3.jar</systemPath>
+            <systemPath>${pom.basedir}/lib/jai_core-1.1.3.jar</systemPath>
         </dependency>
         <dependency>
             <groupId>javax.media</groupId>
             <artifactId>jai_codec</artifactId>
             <version>1.1.3</version>
             <scope>system</scope>
-            <systemPath>${basedir}/lib/jai_codec-1.1.3.jar</systemPath>
+            <systemPath>${pom.basedir}/lib/jai_codec-1.1.3.jar</systemPath>
         </dependency>
 
         <!-- test dependency - start -->

+ 10 - 187
server/src/main/java/cn/keking/service/CompressFileReader.java

@@ -13,11 +13,8 @@ import com.github.junrar.rarfile.FileHeader;
 import net.sf.sevenzipjbinding.*;
 import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
 import net.sf.sevenzipjbinding.simple.ISimpleInArchive;
-import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
-import org.apache.commons.compress.archivers.sevenz.SevenZFile;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipFile;
-import org.apache.commons.io.FileUtils;
 import org.springframework.stereotype.Component;
 
 import java.io.*;
@@ -47,59 +44,6 @@ public class CompressFileReader {
         this.fileHandlerService = fileHandlerService;
     }
 
-    public String readZipFile(String filePath, String fileKey) {
-        String archiveSeparator = "/";
-        Map<String, FileNode> appender = new HashMap<>();
-        List<String> imgUrls = new LinkedList<>();
-        String baseUrl = BaseUrlFilter.getBaseUrl();
-        String archiveFileName = fileHandlerService.getFileNameFromPath(filePath);
-        try {
-            ZipFile zipFile = new ZipFile(filePath, KkFileUtils.getFileEncode(filePath));
-            Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
-            // 排序
-            entries = sortZipEntries(entries);
-            List<Map<String, ZipArchiveEntry>> entriesToBeExtracted = new LinkedList<>();
-            while (entries.hasMoreElements()) {
-                ZipArchiveEntry entry = entries.nextElement();
-                String fullName = entry.getName().replaceAll("//", "").replaceAll("\\\\", "");
-                int level = fullName.split(archiveSeparator).length;
-                // 展示名
-                String originName = getLastFileName(fullName, archiveSeparator);
-                String childName = level + "_" + originName;
-                boolean directory = entry.isDirectory();
-                if (!directory) {
-                    childName = archiveFileName + "_" + originName;
-                    entriesToBeExtracted.add(Collections.singletonMap(childName, entry));
-                }
-                String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName);
-                parentName = (level - 1) + "_" + parentName;
-                FileType type = FileType.typeFromUrl(childName);
-                if (type.equals(FileType.PICTURE)) {//添加图片文件到图片列表
-                    imgUrls.add(baseUrl + childName);
-                }
-                FileNode node = new FileNode(originName, childName, parentName, new ArrayList<>(), directory, fileKey);
-                addNodes(appender, parentName, node);
-                appender.put(childName, node);
-            }
-            // 开启新的线程处理文件解压
-            executors.submit(new ZipExtractorWorker(entriesToBeExtracted, zipFile, filePath));
-            fileHandlerService.putImgCache(fileKey, imgUrls);
-            return new ObjectMapper().writeValueAsString(appender.get(""));
-        } catch (IOException e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
-
-    private Enumeration<ZipArchiveEntry> sortZipEntries(Enumeration<ZipArchiveEntry> entries) {
-        List<ZipArchiveEntry> sortedEntries = new LinkedList<>();
-        while (entries.hasMoreElements()) {
-            sortedEntries.add(entries.nextElement());
-        }
-        sortedEntries.sort(Comparator.comparingInt(o -> o.getName().length()));
-        return Collections.enumeration(sortedEntries);
-    }
-
     public String unRar(String filePath, String fileKey) {
         Map<String, FileNode> appender = new HashMap<>();
         List<String> imgUrls = new ArrayList<>();
@@ -110,14 +54,14 @@ public class CompressFileReader {
             List<Map<String, FileHeaderRar>> headersToBeExtract = new ArrayList<>();
             for (FileHeaderRar header : items) {
                 String fullName = header.getFileNameW();
-                String originName = getLastFileName(fullName, File.separator);
+                String originName = getLastFileName(fullName);
                 String childName = originName;
                 boolean directory = header.getDirectory();
                 if (!directory) {
                     childName = archiveFileName + "_" + originName;
                     headersToBeExtract.add(Collections.singletonMap(childName, header));
                 }
-                String parentName = getLast2FileName(fullName, File.separator, archiveFileName);
+                String parentName = getLast2FileName(fullName, archiveFileName);
                 FileType type = FileType.typeFromUrl(childName);
                 if (type.equals(FileType.PICTURE)) {
                     imgUrls.add(baseUrl + childName);
@@ -183,58 +127,6 @@ public class CompressFileReader {
         return itemPath;
     }
 
-    public String read7zFile(String filePath, String fileKey) {
-        String archiveSeparator = "/";
-        Map<String, FileNode> appender = new HashMap<>();
-        List<String> imgUrls = new ArrayList<>();
-        String baseUrl = BaseUrlFilter.getBaseUrl();
-        String archiveFileName = fileHandlerService.getFileNameFromPath(filePath);
-        try {
-            SevenZFile zipFile = new SevenZFile(new File(filePath));
-            Iterable<SevenZArchiveEntry> entries = zipFile.getEntries();
-            // 排序
-            Enumeration<SevenZArchiveEntry> newEntries = sortSevenZEntries(entries);
-            List<Map<String, SevenZArchiveEntry>> entriesToBeExtracted = new ArrayList<>();
-            while (newEntries.hasMoreElements()) {
-                SevenZArchiveEntry entry = newEntries.nextElement();
-                String fullName = entry.getName().replaceAll("//", "").replaceAll("\\\\", "");
-                int level = fullName.split(archiveSeparator).length;
-                // 展示名
-                String originName = getLastFileName(fullName, archiveSeparator);
-                String childName = level + "_" + originName;
-                boolean directory = entry.isDirectory();
-                if (!directory) {
-                    childName = archiveFileName + "_" + originName;
-                    entriesToBeExtracted.add(Collections.singletonMap(childName, entry));
-                }
-                String parentName = getLast2FileName(fullName, archiveSeparator, archiveFileName);
-                parentName = (level - 1) + "_" + parentName;
-                FileType type = FileType.typeFromUrl(childName);
-                if (type.equals(FileType.PICTURE)) {//添加图片文件到图片列表
-                    imgUrls.add(baseUrl + childName);
-                }
-                FileNode node = new FileNode(originName, childName, parentName, new ArrayList<>(), directory, fileKey);
-                addNodes(appender, parentName, node);
-                appender.put(childName, node);
-            }
-            // 开启新的线程处理文件解压
-            executors.submit(new SevenZExtractorWorker(entriesToBeExtracted, filePath));
-            fileHandlerService.putImgCache(fileKey, imgUrls);
-            return new ObjectMapper().writeValueAsString(appender.get(""));
-        } catch (IOException e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
-
-
-    private Enumeration<SevenZArchiveEntry> sortSevenZEntries(Iterable<SevenZArchiveEntry> entries) {
-        List<SevenZArchiveEntry> sortedEntries = new ArrayList<>();
-        for (SevenZArchiveEntry entry : entries) {
-            sortedEntries.add(entry);
-        }
-        return Collections.enumeration(sortedEntries);
-    }
 
     private void addNodes(Map<String, FileNode> appender, String parentName, FileNode node) {
         if (appender.containsKey(parentName)) {
@@ -249,53 +141,28 @@ public class CompressFileReader {
         }
     }
 
-    private List<FileHeader> sortedHeaders(List<FileHeader> headers) {
-        List<FileHeader> sortedHeaders = new ArrayList<>();
-        Map<Integer, FileHeader> mapHeaders = new TreeMap<>();
-        headers.forEach(
-                header ->
-                        mapHeaders.put(
-                                new Integer(0).equals(header.getFileNameW().length())
-                                        ? header.getFileNameString().length()
-                                        : header.getFileNameW().length(),
-                                header));
-        for (Map.Entry<Integer, FileHeader> entry : mapHeaders.entrySet()) {
-            for (FileHeader header : headers) {
-                if (entry
-                        .getKey()
-                        .equals(
-                                new Integer(0).equals(header.getFileNameW().length())
-                                        ? header.getFileNameString().length()
-                                        : header.getFileNameW().length())) {
-                    sortedHeaders.add(header);
-                }
-            }
-        }
-        return sortedHeaders;
-    }
-
-    private static String getLast2FileName(String fullName, String seperator, String rootName) {
-        if (fullName.endsWith(seperator)) {
+    private static String getLast2FileName(String fullName, String rootName) {
+        if (fullName.endsWith(File.separator)) {
             fullName = fullName.substring(0, fullName.length() - 1);
         }
         // 1.获取剩余部分
-        int endIndex = fullName.lastIndexOf(seperator);
+        int endIndex = fullName.lastIndexOf(File.separator);
         String leftPath = fullName.substring(0, endIndex == -1 ? 0 : endIndex);
         if (leftPath.length() > 1) {
             // 2.获取倒数第二个
-            return getLastFileName(leftPath, seperator);
+            return getLastFileName(leftPath);
         } else {
             return rootName;
         }
     }
 
-    private static String getLastFileName(String fullName, String seperator) {
-        if (fullName.endsWith(seperator)) {
+    private static String getLastFileName(String fullName) {
+        if (fullName.endsWith(File.separator)) {
             fullName = fullName.substring(0, fullName.length() - 1);
         }
         String newName = fullName;
-        if (fullName.contains(seperator)) {
-            newName = fullName.substring(fullName.lastIndexOf(seperator) + 1);
+        if (fullName.contains(File.separator)) {
+            newName = fullName.substring(fullName.lastIndexOf(File.separator) + 1);
         }
         return newName;
     }
@@ -456,50 +323,6 @@ public class CompressFileReader {
         }
     }
 
-    class SevenZExtractorWorker implements Runnable {
-
-        private final List<Map<String, SevenZArchiveEntry>> entriesToBeExtracted;
-        private final String filePath;
-
-        public SevenZExtractorWorker(List<Map<String, SevenZArchiveEntry>> entriesToBeExtracted, String filePath) {
-            this.entriesToBeExtracted = entriesToBeExtracted;
-            this.filePath = filePath;
-        }
-
-        @Override
-        public void run() {
-            try {
-                SevenZFile sevenZFile = new SevenZFile(new File(filePath));
-                SevenZArchiveEntry entry = sevenZFile.getNextEntry();
-                while (entry != null) {
-                    if (entry.isDirectory()) {
-                        entry = sevenZFile.getNextEntry();
-                        continue;
-                    }
-                    String childName = "default_file";
-                    SevenZArchiveEntry entry1;
-                    for (Map<String, SevenZArchiveEntry> entryMap : entriesToBeExtracted) {
-                        childName = entryMap.keySet().iterator().next();
-                        entry1 = entryMap.values().iterator().next();
-                        if (entry.getName().equals(entry1.getName())) {
-                            break;
-                        }
-                    }
-                    FileOutputStream out = new FileOutputStream(fileDir + childName);
-                    byte[] content = new byte[(int) entry.getSize()];
-                    sevenZFile.read(content, 0, content.length);
-                    out.write(content);
-                    out.close();
-                    entry = sevenZFile.getNextEntry();
-                }
-                sevenZFile.close();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-            KkFileUtils.deleteFileByPath(filePath);
-        }
-    }
-
     class RarExtractorWorker implements Runnable {
         private final List<Map<String, FileHeader>> headersToBeExtracted;
 

+ 1 - 1
server/src/main/java/cn/keking/service/cache/impl/CacheServiceJDKImpl.java

@@ -3,9 +3,9 @@ package cn.keking.service.cache.impl;
 import cn.keking.service.cache.CacheService;
 import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
 import com.googlecode.concurrentlinkedhashmap.Weighers;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
 import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
 
 import javax.annotation.PostConstruct;
 import java.util.ArrayList;

+ 2 - 0
server/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java

@@ -177,6 +177,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public Map<String, String> getMediaConvertCache() {
         Map<String, String> result = new HashMap<>();
         try{
@@ -199,6 +200,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public String getMediaConvertCache(String key) {
         String result = "";
         try{

+ 4 - 3
server/src/main/java/cn/keking/utils/FtpUtils.java

@@ -1,17 +1,18 @@
 package cn.keking.utils;
 
 import cn.keking.config.ConfigConstants;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.net.ftp.FTPClient;
 import org.apache.commons.net.ftp.FTPReply;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
 
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 /**
  * @auther: chenjh
@@ -46,7 +47,7 @@ public class FtpUtils {
         String remoteFilePath = url.getPath();
         LOGGER.debug("FTP connection url:{}, username:{}, password:{}, controlEncoding:{}, localFilePath:{}", ftpUrl, username, password, controlEncoding, localFilePath);
         FTPClient ftpClient = connect(host, port, username, password, controlEncoding);
-        OutputStream outputStream = new FileOutputStream(localFilePath);
+        OutputStream outputStream = Files.newOutputStream(Paths.get(localFilePath));
         ftpClient.enterLocalPassiveMode();
         boolean downloadResult = ftpClient.retrieveFile(new String(remoteFilePath.getBytes(controlEncoding), StandardCharsets.ISO_8859_1), outputStream);
         LOGGER.debug("FTP download result {}", downloadResult);