From 755262ba9a1a3c0573a0e910bbd0a353e9e2a2c5 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期三, 16 六月 2021 16:39:57 +0800
Subject: [PATCH] Merge branch 'master' of http://git.homecommunity.cn/supervip/MicroCommunity

---
 java110-db/src/main/java/com/java110/db/DataSourceConfig.java |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/java110-db/src/main/java/com/java110/db/DataSourceConfig.java b/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
old mode 100644
new mode 100755
index f8df53a..159df84
--- a/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
+++ b/java110-db/src/main/java/com/java110/db/DataSourceConfig.java
@@ -1,8 +1,6 @@
 package com.java110.db;
 
-import org.apache.shardingsphere.shardingjdbc.api.yaml.YamlMasterSlaveDataSourceFactory;
 import org.apache.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.io.ClassPathResource;
@@ -10,9 +8,11 @@
 
 import javax.servlet.Filter;
 import javax.sql.DataSource;
-import java.io.File;
+import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.sql.SQLException;
 
@@ -59,8 +59,29 @@
      * @throws FileNotFoundException        鏂囦欢鏈彂鐜板紓甯�
      * @throws UnsupportedEncodingException 涓嶆敮鎸佺紪鐮佸紓甯�
      */
-    private File getYmlFile() throws IOException {
-        Resource certResource = new ClassPathResource(SHARDING_YML_PATH);
-        return certResource.getFile();
+    private byte[] getYmlFile() throws IOException {
+        Reader reader = null;
+        InputStream inputStream = null;
+        ByteArrayOutputStream swapStream = null;
+        try {
+            Resource resource = new ClassPathResource(SHARDING_YML_PATH);
+
+            inputStream = resource.getInputStream();
+            swapStream = new ByteArrayOutputStream();
+            byte[] buff = new byte[100];
+            int rc = 0;
+            while ((rc = inputStream.read(buff, 0, 100)) > 0) {
+                swapStream.write(buff, 0, rc);
+            }
+            byte[] in2b = swapStream.toByteArray();
+            return in2b;
+        } finally {
+            if (inputStream != null) {
+                inputStream.close();
+            }
+            if (swapStream != null) {
+                swapStream.close();
+            }
+        }
     }
 }

--
Gitblit v1.8.0