You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/12/01 08:59:09 UTC
[shardingsphere] branch master updated: Ignore license header for ShardingSphereDriverURL.toConfigurationBytes() (#22557)
This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new a3492f5488a Ignore license header for ShardingSphereDriverURL.toConfigurationBytes() (#22557)
a3492f5488a is described below
commit a3492f5488a6be703d86dc5168b0020d840783d3
Author: gxxiong <xi...@foxmail.com>
AuthorDate: Thu Dec 1 16:58:58 2022 +0800
Ignore license header for ShardingSphereDriverURL.toConfigurationBytes() (#22557)
* Ignore license header for ShardingSphereDriverURL.toConfigurationBytes()
* delete guava method
* com.google.common.base.Charsets be replaced to StandardCharsets
* format code
---
.../driver/jdbc/core/driver/ShardingSphereDriverURL.java | 16 +++++++++++++---
.../jdbc/core/driver/ShardingSphereDriverURLTest.java | 6 +++---
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURL.java b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURL.java
index 4c84c19cdf7..9b496a56737 100644
--- a/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURL.java
+++ b/jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURL.java
@@ -20,9 +20,12 @@ package org.apache.shardingsphere.driver.jdbc.core.driver;
import com.google.common.base.Preconditions;
import lombok.SneakyThrows;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Objects;
@@ -57,9 +60,16 @@ public final class ShardingSphereDriverURL {
@SneakyThrows(IOException.class)
public byte[] toConfigurationBytes() {
try (InputStream stream = inClasspath ? ShardingSphereDriverURL.class.getResourceAsStream("/" + file) : Files.newInputStream(new File(file).toPath())) {
- byte[] result = new byte[null == stream ? 0 : stream.available()];
- Objects.requireNonNull(stream, String.format("Can not find configuration file `%s`.", file)).read(result);
- return result;
+ Objects.requireNonNull(stream, String.format("Can not find configuration file `%s`.", file));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
+ StringBuilder builder = new StringBuilder();
+ String line;
+ while ((line = reader.readLine()) != null) {
+ if (!line.startsWith("#")) {
+ builder.append(line);
+ }
+ }
+ return builder.toString().getBytes(StandardCharsets.UTF_8);
}
}
}
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURLTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURLTest.java
index 49622d2aa1b..43e684965d5 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURLTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/driver/ShardingSphereDriverURLTest.java
@@ -34,20 +34,20 @@ public final class ShardingSphereDriverURLTest {
@Test
public void assertToClasspathConfigurationFile() {
ShardingSphereDriverURL actual = new ShardingSphereDriverURL("jdbc:shardingsphere:classpath:config/driver/foo-driver-fixture.yaml");
- assertThat(actual.toConfigurationBytes().length, is(822));
+ assertThat(actual.toConfigurationBytes().length, is(35));
}
@Test
public void assertToConfigurationFile() {
String absolutePath = Objects.requireNonNull(ShardingSphereDriverURLTest.class.getClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
ShardingSphereDriverURL actual = new ShardingSphereDriverURL("jdbc:shardingsphere:" + absolutePath);
- assertThat(actual.toConfigurationBytes().length, is(822));
+ assertThat(actual.toConfigurationBytes().length, is(35));
}
@Test
public void assertToConfigurationFileWithOtherParameters() {
String absolutePath = Objects.requireNonNull(ShardingSphereDriverURLTest.class.getClassLoader().getResource("config/driver/foo-driver-fixture.yaml")).getPath();
ShardingSphereDriverURL actual = new ShardingSphereDriverURL("jdbc:shardingsphere:" + absolutePath + "?xxx=xxx&yyy=yyy");
- assertThat(actual.toConfigurationBytes().length, is(822));
+ assertThat(actual.toConfigurationBytes().length, is(35));
}
}