From fa4a12b95f6dae3cfe74bc2892ba160e715ad85b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= Date: Wed, 29 May 2024 10:13:27 +0100 Subject: [PATCH] lazy load jsonParser and yamlParser FlagFileParser --- .../sdk/server/integrations/FileDataSourceParsing.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileDataSourceParsing.java b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileDataSourceParsing.java index 9571c44..2750acc 100644 --- a/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileDataSourceParsing.java +++ b/lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/FileDataSourceParsing.java @@ -72,14 +72,18 @@ static final class FlagFileRep { } static abstract class FlagFileParser { - private static final FlagFileParser jsonParser = new JsonFlagFileParser(); - private static final FlagFileParser yamlParser = new YamlFlagFileParser(); + static class JsonParserHolder { + static final FlagFileParser INSTANCE = new JsonFlagFileParser(); + } + static class YamlParserHolder { + static final FlagFileParser INSTANCE = new YamlFlagFileParser(); + } public abstract FlagFileRep parse(InputStream input) throws FileDataException, IOException; public static FlagFileParser selectForContent(byte[] data) { Reader r = new InputStreamReader(new ByteArrayInputStream(data)); - return detectJson(r) ? jsonParser : yamlParser; + return detectJson(r) ? JsonParserHolder.INSTANCE : YamlParserHolder.INSTANCE; } private static boolean detectJson(Reader r) {