All Downloads are FREE. Search and download functionalities are using the official Maven repository.

website.automate.waml.io.WamlReader Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
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;
    }
   
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy