Skip to content

Commit

Permalink
Refactor ShardingSphereURLProvider.getContent() (#30116)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Feb 13, 2024
1 parent 79643ab commit 4538c3f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static byte[] getContent(final String url, final String urlPrefix) {
ShardingSpherePreconditions.checkNotNull(url, () -> new URLProviderNotFoundException(url));
for (ShardingSphereURLProvider each : ShardingSphereServiceLoader.getServiceInstances(ShardingSphereURLProvider.class)) {
if (url.contains(each.getConfigurationType())) {
return each.getContent(url, urlPrefix);
return each.getContent(url, ArgsUtils.getConfigurationSubject(url, urlPrefix, each.getConfigurationType()));
}
}
throw new URLProviderNotFoundException(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public interface ShardingSphereURLProvider {
* Get configuration content from URL.
*
* @param url driver URL
* @param urlPrefix URL prefix
* @param configurationSubject configuration subject
* @return configuration content
*/
byte[] getContent(String url, String urlPrefix);
byte[] getContent(String url, String configurationSubject);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath;

import lombok.SneakyThrows;
import org.apache.shardingsphere.driver.jdbc.core.driver.ArgsUtils;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -40,10 +39,9 @@ public String getConfigurationType() {

@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getConfigurationType());
public byte[] getContent(final String url, final String configurationSubject) {
try (
InputStream stream = Files.newInputStream(new File(file).toPath());
InputStream stream = Files.newInputStream(new File(configurationSubject).toPath());
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ public String getConfigurationType() {

@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getConfigurationType());
public byte[] getContent(final String url, final String configurationSubject) {
try (
InputStream stream = Files.newInputStream(new File(file).toPath());
InputStream stream = Files.newInputStream(new File(configurationSubject).toPath());
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ public String getConfigurationType() {

@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getConfigurationType());
public byte[] getContent(final String url, final String configurationSubject) {
try (
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(file);
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ public String getConfigurationType() {

@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getConfigurationType());
public byte[] getContent(final String url, final String configurationSubject) {
try (
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(file);
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ public String getConfigurationType() {

@Override
@SneakyThrows(IOException.class)
public byte[] getContent(final String url, final String urlPrefix) {
String file = ArgsUtils.getConfigurationSubject(url, urlPrefix, getConfigurationType());
public byte[] getContent(final String url, final String configurationSubject) {
try (
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(file);
InputStream stream = ArgsUtils.getResourceAsStreamFromClasspath(configurationSubject);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder builder = new StringBuilder();
String line;
Expand Down

0 comments on commit 4538c3f

Please sign in to comment.