strongduanmu commented on code in PR #30361:
URL: https://github.com/apache/shardingsphere/pull/30361#discussion_r1508767493
##########
infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java:
##########
@@ -161,32 +154,30 @@ private static JarFile getJarFile(final URL url) {
* `com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem` will
be automatically created during the life cycle of the context,
* so additional determination is required.
*
+ * @param directory directory
* @param directoryUrl directory url
* @return stream of resource name
*/
@SneakyThrows({IOException.class, URISyntaxException.class})
- private static Stream<String> readDirectoryInFileSystem(final URL
directoryUrl) {
- if ("resource".equals(directoryUrl.getProtocol())) {
- try {
- return loadFromDirectory(directoryUrl);
- } catch (FileSystemNotFoundException exception) {
- FileSystem nativeImageResourceFileSystem =
FileSystems.newFileSystem(directoryUrl.toURI(), Collections.emptyMap());
- return loadFromDirectory(directoryUrl).onClose(() -> {
- try {
- nativeImageResourceFileSystem.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- });
- }
+ private static Stream<String> readDirectoryInFileSystem(final String
directory, final URL directoryUrl) {
+ try {
+ return loadFromDirectory(directory, directoryUrl);
+ } catch (FileSystemNotFoundException exception) {
Review Comment:
Please add final for FileSystemNotFoundException, and rename exception to ex.
##########
infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java:
##########
@@ -161,32 +154,30 @@ private static JarFile getJarFile(final URL url) {
* `com.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem` will
be automatically created during the life cycle of the context,
* so additional determination is required.
*
+ * @param directory directory
* @param directoryUrl directory url
* @return stream of resource name
*/
@SneakyThrows({IOException.class, URISyntaxException.class})
- private static Stream<String> readDirectoryInFileSystem(final URL
directoryUrl) {
- if ("resource".equals(directoryUrl.getProtocol())) {
- try {
- return loadFromDirectory(directoryUrl);
- } catch (FileSystemNotFoundException exception) {
- FileSystem nativeImageResourceFileSystem =
FileSystems.newFileSystem(directoryUrl.toURI(), Collections.emptyMap());
- return loadFromDirectory(directoryUrl).onClose(() -> {
- try {
- nativeImageResourceFileSystem.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- });
- }
+ private static Stream<String> readDirectoryInFileSystem(final String
directory, final URL directoryUrl) {
+ try {
+ return loadFromDirectory(directory, directoryUrl);
+ } catch (FileSystemNotFoundException exception) {
+ FileSystem fileSystem =
FileSystems.newFileSystem(directoryUrl.toURI(), Collections.emptyMap());
+ return loadFromDirectory(directory, directoryUrl).onClose(() -> {
+ try {
+ fileSystem.close();
+ } catch (IOException e) {
Review Comment:
Please rename exception to ex.
##########
infra/util/src/main/java/org/apache/shardingsphere/infra/util/directory/ClasspathResourceDirectoryReader.java:
##########
@@ -130,13 +129,7 @@ private static Stream<String> readDirectoryInJar(final
String directory, final U
if (null == jar) {
return Stream.empty();
}
- return jar.stream().filter(jarEntry ->
jarEntry.getName().startsWith(directory) &&
!jarEntry.isDirectory()).map(JarEntry::getName).onClose(() -> {
- try {
- jar.close();
- } catch (final IOException ex) {
- throw new RuntimeException(ex);
- }
- });
+ return jar.stream().filter(jarEntry ->
jarEntry.getName().startsWith(directory) &&
!jarEntry.isDirectory()).map(JarEntry::getName);
Review Comment:
Do you think rename jarEntry to each is better?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]