Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazy load jsonParser and yamlParser FlagFileParser #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be private with a getter so it only gets initialized on access as opposed to having direct reference to variable.

}

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) {
Expand Down
Loading