use of org.yaml.snakeyaml.reader.StreamReader in project alien4cloud by alien4cloud.
the class YamlParser method parseFile.
/**
* Parse a yaml file into the given T instance.
*
* @param yamlStream Input stream that contains the yaml.
* @param instance The instance to parse.
* @return A parsing result that contains the parsing errors as well as the created instance.
* @throws ParsingException In case there is a blocking issue while parsing the definition.
*/
public ParsingResult<T> parseFile(String filePath, String fileName, InputStream yamlStream, T instance) throws ParsingException {
StreamReader sreader = new StreamReader(new UnicodeReader(yamlStream));
Composer composer = new Composer(new ParserImpl(sreader), new Resolver());
Node rootNode = null;
try {
rootNode = composer.getSingleNode();
if (rootNode == null) {
throw new ParsingException(fileName, new ParsingError(ErrorCode.SYNTAX_ERROR, "Empty file.", new Mark("root", 0, 0, 0, null, 0), "No yaml content found in file.", new Mark("root", 0, 0, 0, null, 0), filePath));
}
} catch (MarkedYAMLException exception) {
throw new ParsingException(fileName, new ParsingError(ErrorCode.INVALID_YAML, exception));
}
try {
return doParsing(fileName, rootNode, instance);
} catch (ParsingException e) {
e.setFileName(fileName);
throw e;
}
}
Aggregations