getResourceAsStream is efficient enough, - do not complicate

GitOrigin-RevId: d73264f79aeda3cf29dda1bf79e4d2b04a6c00b1
This commit is contained in:
Vladimir Krivosheev
2024-03-12 21:47:57 +00:00
committed by intellij-monorepo-bot
parent 97e238b328
commit 093087f0c8
@@ -1,13 +1,11 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.util.ArrayUtilRt;
import com.intellij.util.DefaultBundleService;
import com.intellij.util.lang.UrlClassLoader;
import org.jetbrains.annotations.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -150,9 +148,11 @@ public class AbstractBundle {
}
@ApiStatus.Internal
protected static @NotNull ResourceBundle resolveResourceBundleWithFallback(@NotNull ClassLoader loader,
@NotNull String pathToBundle,
@NotNull Supplier<? extends @NotNull ResourceBundle> firstTry) {
protected static @NotNull ResourceBundle resolveResourceBundleWithFallback(
@NotNull ClassLoader loader,
@NotNull String pathToBundle,
@NotNull Supplier<? extends @NotNull ResourceBundle> firstTry
) {
try {
return firstTry.get();
}
@@ -212,28 +212,16 @@ public class AbstractBundle {
return null;
}
if (loader instanceof UrlClassLoader) {
// checkParents - https://youtrack.jetbrains.com/issue/IDEA-282831
byte[] data = ((UrlClassLoader)loader).getResourceAsBytes(resourceName, true);
if (data == null) {
return null;
}
else {
return new PropertyResourceBundle(new InputStreamReader(new ByteArrayInputStream(data), StandardCharsets.UTF_8));
}
InputStream stream = loader.getResourceAsStream(resourceName);
if (stream == null) {
return null;
}
else {
InputStream stream = loader.getResourceAsStream(resourceName);
if (stream == null) {
return null;
}
try {
return new PropertyResourceBundle(new InputStreamReader(stream, StandardCharsets.UTF_8));
}
finally {
stream.close();
}
try {
return new PropertyResourceBundle(new InputStreamReader(stream, StandardCharsets.UTF_8));
}
finally {
stream.close();
}
}
}