| | |
| | | package com.ruoyi.device.dhsdk.lib; |
| | | |
| | | import com.ruoyi.device.dhsdk.lib.DynamicParseUtil; |
| | | import lombok.extern.slf4j.Slf4j;
|
| | | import org.xml.sax.SAXException; |
| | | |
| | | import javax.xml.parsers.ParserConfigurationException; |
| | |
| | | * @description 动态库加载 |
| | | * @date 2020/11/14 |
| | | */ |
| | | @Slf4j(topic = "dhSdk")
|
| | | public class LibraryLoad { |
| | | private static final String ARCH_WINDOWS = "win"; |
| | | private static final String ARCH_LINUX = "linux"; |
| | |
| | | if (!(EXTRACT_PATH.endsWith("/") || EXTRACT_PATH.endsWith("\\"))) { |
| | | path = EXTRACT_PATH + "/"; |
| | | } |
| | | System.out.println("load library: " + path + fullName); |
| | | log.debug("load library: " + path + fullName);
|
| | | return path + fullName; |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | private static String extractLibrary(String libName) { |
| | | return extractLibrary("", libName); |
| | | return extractLibrary("/lib", libName);
|
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | extractedLibFile = new File(nativeTempDir + libFullName); |
| | | reader = new BufferedInputStream(in); |
| | |
|
| | | // 检查文件夹是否存在,如果不存在则创建
|
| | | File parentDir = extractedLibFile.getParentFile();
|
| | | if (!parentDir.exists()) {
|
| | | parentDir.mkdirs();
|
| | | }
|
| | |
|
| | | writer = new FileOutputStream(extractedLibFile); |
| | | byte[] buffer = new byte[1024]; |
| | | while (true) { |
| | |
| | | writer.close(); |
| | | in.close(); |
| | | } catch (Exception e) { |
| | | //System.out.println("dynamic file[ "+ fileName+ " ] not found in project.please ensure you need this library."); |
| | | log.error("dynamic file[ " + fileName + " ] not found in project.please ensure you need this library.");
|
| | | } |
| | | return extractedLibFile != null ? extractedLibFile.getAbsolutePath() : ""; |
| | | } |