website.automate.waml.io.WamlReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of waml-io Show documentation
Show all versions of waml-io Show documentation
(De)Serializer of the web automation markup language (WAML) for Java
package website.automate.waml.io;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import website.automate.waml.io.model.Scenario;
import com.fasterxml.jackson.databind.ObjectMapper;
public class WamlReader {
private ObjectMapper objectMapper = WamlConfig.getInstance().getMapper();
public List read(InputStream inputStream) {
List scenarios = new LinkedList<>();
Scanner scanner = new Scanner(inputStream, StandardCharsets.UTF_8.name());
try {
scanner.useDelimiter("\r?\n---\r?\n");
while(scanner.hasNext()){
String content = scanner.next();
scenarios.add(objectMapper.readValue(content, Scenario.class));
}
} catch (Exception e) {
if(e instanceof WamlDeserializationException){
throw (WamlDeserializationException)e;
} else {
throw new WamlDeserializationException(
"Unable to read the suite from the desired format.", e);
}
} finally {
scanner.close();
}
return scenarios;
}
}