// Path: src/main/java/net/technolords/micro/model/ResponseContext.java
// public class ResponseContext {
//     public static final String JSON_CONTENT_TYPE = "application/json";
//     public static final String XML_CONTENT_TYPE = "application/xml";
//     public static final String PLAIN_TEXT_CONTENT_TYPE = "text/plain";
//     public static final String HTML_CONTENT_TYPE = "text/html";
//     public static final String DEFAULT_CONTENT_TYPE = JSON_CONTENT_TYPE;
//     private String response;
//     private String errorCode;
//     private String contentType = DEFAULT_CONTENT_TYPE;
// 
//     public String getResponse() {
//         return response;
//     }
// 
//     public void setResponse(String response) {
//         this.response = response;
//     }
// 
//     public String getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(String errorCode) {
//         this.errorCode = errorCode;
//     }
// 
//     public String getContentType() {
//         return contentType;
//     }
// 
//     public void setContentType(String contentType) {
//         this.contentType = contentType;
//     }
// }
// 
// Path: src/main/java/net/technolords/micro/model/jaxb/resource/SimpleResource.java
// public class SimpleResource {
//     private String resource;
//     private String cachedData;
//     private int delay;
//     private String errorCode;
//     private int errorRate;
//     private String contentType;
// 
//     @XmlValue
//     public String getResource() {
//         return resource;
//     }
// 
//     public void setResource(String resource) {
//         this.resource = resource;
//     }
// 
//     @XmlTransient
//     public String getCachedData() {
//         return cachedData;
//     }
// 
//     public void setCachedData(String cachedData) {
//         this.cachedData = cachedData;
//     }
// 
//     @XmlAttribute(name = "delay")
//     public int getDelay() {
//         return delay;
//     }
// 
//     public void setDelay(int delay) {
//         this.delay = delay;
//     }
// 
//     @XmlAttribute(name = "error-code")
//     public String getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(String errorCode) {
//         this.errorCode = errorCode;
//     }
// 
//     @XmlAttribute(name = "error-rate")
//     public int getErrorRate() {
//         return errorRate;
//     }
// 
//     public void setErrorRate(int errorRate) {
//         this.errorRate = errorRate;
//     }
// 
//     @XmlAttribute(name = "content-type")
//     public String getContentType() {
//         return contentType;
//     }
// 
//     public void setContentType(String contentType) {
//         this.contentType = contentType;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (obj == null) {
//             return false;
//         }
//         if (!(obj instanceof SimpleResource)) {
//             return false;
//         }
//         SimpleResource ref = (SimpleResource) obj;
//         return (Objects.equals(this.getContentType(), ref.getContentType())
//                 && Objects.equals(this.getErrorCode(), ref.getErrorCode())
//                 && Objects.equals(this.getResource(), ref.getResource())
//         );
//     }
// }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.technolords.micro.model.ResponseContext;
import net.technolords.micro.model.jaxb.resource.SimpleResource;
package net.technolords.micro.output;




public class ResponseContextGenerator {
    private final Logger LOGGER = LoggerFactory.getLogger(getClass());
    private Path pathToDataFolder;

    /**
     * Custom constructor, which caches the path to the data folder. Note that this can be null.
     *
     * @param pathToDataFolder
     *  The path to the data folder.
     */
    public ResponseContextGenerator(Path pathToDataFolder) {
        this.pathToDataFolder = pathToDataFolder;
    }

    /**
     * Auxiliary method that reads the response data as well as updating the internal cache so
     * subsequent reads will will served from memory. It also implements the delay and updates
     * the ResponseContext with an erroneous status code if the error rate is triggered.
     *
     * @param resource
     *  The resource to read and cache.
     *
     * @return
     *  The data associated with the resource (i.e. response).
     *
     * @throws IOException
     *  When reading the resource fails.
     */
// Path: src/main/java/net/technolords/micro/model/ResponseContext.java
// public class ResponseContext {
//     public static final String JSON_CONTENT_TYPE = "application/json";
//     public static final String XML_CONTENT_TYPE = "application/xml";
//     public static final String PLAIN_TEXT_CONTENT_TYPE = "text/plain";
//     public static final String HTML_CONTENT_TYPE = "text/html";
//     public static final String DEFAULT_CONTENT_TYPE = JSON_CONTENT_TYPE;
//     private String response;
//     private String errorCode;
//     private String contentType = DEFAULT_CONTENT_TYPE;
// 
//     public String getResponse() {
//         return response;
//     }
// 
//     public void setResponse(String response) {
//         this.response = response;
//     }
// 
//     public String getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(String errorCode) {
//         this.errorCode = errorCode;
//     }
// 
//     public String getContentType() {
//         return contentType;
//     }
// 
//     public void setContentType(String contentType) {
//         this.contentType = contentType;
//     }
// }
// 
// Path: src/main/java/net/technolords/micro/model/jaxb/resource/SimpleResource.java
// public class SimpleResource {
//     private String resource;
//     private String cachedData;
//     private int delay;
//     private String errorCode;
//     private int errorRate;
//     private String contentType;
// 
//     @XmlValue
//     public String getResource() {
//         return resource;
//     }
// 
//     public void setResource(String resource) {
//         this.resource = resource;
//     }
// 
//     @XmlTransient
//     public String getCachedData() {
//         return cachedData;
//     }
// 
//     public void setCachedData(String cachedData) {
//         this.cachedData = cachedData;
//     }
// 
//     @XmlAttribute(name = "delay")
//     public int getDelay() {
//         return delay;
//     }
// 
//     public void setDelay(int delay) {
//         this.delay = delay;
//     }
// 
//     @XmlAttribute(name = "error-code")
//     public String getErrorCode() {
//         return errorCode;
//     }
// 
//     public void setErrorCode(String errorCode) {
//         this.errorCode = errorCode;
//     }
// 
//     @XmlAttribute(name = "error-rate")
//     public int getErrorRate() {
//         return errorRate;
//     }
// 
//     public void setErrorRate(int errorRate) {
//         this.errorRate = errorRate;
//     }
// 
//     @XmlAttribute(name = "content-type")
//     public String getContentType() {
//         return contentType;
//     }
// 
//     public void setContentType(String contentType) {
//         this.contentType = contentType;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (obj == null) {
//             return false;
//         }
//         if (!(obj instanceof SimpleResource)) {
//             return false;
//         }
//         SimpleResource ref = (SimpleResource) obj;
//         return (Objects.equals(this.getContentType(), ref.getContentType())
//                 && Objects.equals(this.getErrorCode(), ref.getErrorCode())
//                 && Objects.equals(this.getResource(), ref.getResource())
//         );
//     }
// }


// Path: src/main/java/net/technolords/micro/output/ResponseContextGenerator.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.technolords.micro.model.ResponseContext;
import net.technolords.micro.model.jaxb.resource.SimpleResource;

package net.technolords.micro.output;




public class ResponseContextGenerator {
    private final Logger LOGGER = LoggerFactory.getLogger(getClass());
    private Path pathToDataFolder;

    /**
     * Custom constructor, which caches the path to the data folder. Note that this can be null.
     *
     * @param pathToDataFolder
     *  The path to the data folder.
     */
    public ResponseContextGenerator(Path pathToDataFolder) {
        this.pathToDataFolder = pathToDataFolder;
    }

    /**
     * Auxiliary method that reads the response data as well as updating the internal cache so
     * subsequent reads will will served from memory. It also implements the delay and updates
     * the ResponseContext with an erroneous status code if the error rate is triggered.
     *
     * @param resource
     *  The resource to read and cache.
     *
     * @return
     *  The data associated with the resource (i.e. response).
     *
     * @throws IOException
     *  When reading the resource fails.
     */
    public ResponseContext readResourceCacheOrFile(SimpleResource resource) throws IOException, InterruptedException {