Github user HeartSaVioR commented on a diff in the pull request: https://github.com/apache/storm/pull/637#discussion_r34835109 --- Diff: external/flux/flux-core/src/main/java/org/apache/storm/flux/parser/FluxParser.java --- @@ -44,40 +44,47 @@ private FluxParser(){} // TODO refactor input stream processing (see parseResource() method). public static TopologyDef parseFile(String inputFile, boolean dumpYaml, boolean processIncludes, String propertiesFile, boolean envSub) throws IOException { - Yaml yaml = yaml(); + FileInputStream in = new FileInputStream(inputFile); - // TODO process properties, etc. - TopologyDef topology = loadYaml(yaml, in, propertiesFile, envSub); + TopologyDef topology = parseInputStream(in, dumpYaml, processIncludes, propertiesFile, envSub); in.close(); - if(dumpYaml){ - dumpYaml(topology, yaml); - } - if(processIncludes) { - return processIncludes(yaml, topology, propertiesFile, envSub); - } else { - return topology; - } + + return topology; } public static TopologyDef parseResource(String resource, boolean dumpYaml, boolean processIncludes, String propertiesFile, boolean envSub) throws IOException { - Yaml yaml = yaml(); + InputStream in = FluxParser.class.getResourceAsStream(resource); - if(in == null){ - LOG.error("Unable to load classpath resource: " + resource); - System.exit(1); - } - TopologyDef topology = loadYaml(yaml, in, propertiesFile, envSub); + TopologyDef topology = parseInputStream(in, dumpYaml, processIncludes, propertiesFile, envSub); in.close(); - if(dumpYaml){ - dumpYaml(topology, yaml); - } - if(processIncludes) { - return processIncludes(yaml, topology, propertiesFile, envSub); - } else { - return topology; - } + + return topology; } + + public static TopologyDef parseInputStream(InputStream inputStream, boolean dumpYaml, boolean processIncludes, + String propertiesFile, boolean envSub) throws IOException { + + Yaml yaml = yaml(); + + if (inputStream == null) { + LOG.error("Unable to load input stream"); + System.exit(1); + } + + TopologyDef topology = loadYaml(yaml, inputStream, propertiesFile, envSub); + inputStream.close(); --- End diff -- @lyonbrw IMO it isn't a good way to close InputStream which is passed to a parameter. Caller can take care of it, and parseFile / parseResource already do it.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---