// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String ACCEPT_EVENTSTORE_ATOM_JSON = "application/vnd.eventstore.atom+json";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String ACCEPT_HEADER = "Accept";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/Event.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class Event {
//    private String eventId;
//    private String eventType;
//    private Long eventNumber;
//    private String streamId;
//    private Boolean isLinkMetaData;
//    private Long positionEventNumber;
//    private String positionStreamId;
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    private String summary;
// 
//    private String eventStreamId;
//    private String data;
//    private String metadata;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventDeletedException.java
// public class EventDeletedException extends RuntimeException {
//    private static final long serialVersionUID = 1L;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventResponse.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class EventResponse {
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    private String summary;
// 
//    private Event content;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventStreamFeed.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class EventStreamFeed {
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    boolean headOfStream;
//    private List<Link> links;
//    private List<Entry> entries;
// 
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventStreamNotFoundException.java
// public class EventStreamNotFoundException extends RuntimeException {
//    private static final long serialVersionUID = 1L;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/HttpCacheLoggingUtil.java
// public class HttpCacheLoggingUtil {
//    private static final Logger LOGGER = LoggerFactory.getLogger(HttpCacheLoggingUtil.class.getName());
// 
//    @SuppressWarnings("nls")
//    public static void logCacheResponseStatus(String prefix, CacheResponseStatus cacheResponseStatus) {
//       switch (cacheResponseStatus) {
//          case CACHE_HIT:
//             LOGGER.debug(prefix + ":A response was generated from the cache with no requests sent upstream");
//             break;
//          case CACHE_MODULE_RESPONSE:
//             LOGGER.debug(prefix + ":The response was generated directly by the caching module");
//             break;
//          case CACHE_MISS:
//             LOGGER.debug(prefix + ":The response came from an upstream server");
//             break;
//          case VALIDATED:
//             LOGGER.debug(prefix + ":The response was generated from the cache after validating the entry with the origin server");
//             break;
//          default:
//             break;
//       }
//    }
// 
// }


import static de.qyotta.eventstore.utils.Constants.ACCEPT_EVENTSTORE_ATOM_JSON;
import static de.qyotta.eventstore.utils.Constants.ACCEPT_HEADER;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.http.HttpStatus;
import org.apache.http.client.cache.HttpCacheContext;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import de.qyotta.eventstore.model.Event;
import de.qyotta.eventstore.model.EventDeletedException;
import de.qyotta.eventstore.model.EventResponse;
import de.qyotta.eventstore.model.EventStreamFeed;
import de.qyotta.eventstore.model.EventStreamNotFoundException;
import de.qyotta.eventstore.utils.HttpCacheLoggingUtil;
package de.qyotta.eventstore.communication;






@SuppressWarnings("nls")
public class EsReaderDefaultImpl implements ESReader {
   private static final Logger LOGGER = LoggerFactory.getLogger(EsReaderDefaultImpl.class.getName());
   private final Gson gson;
   private final CloseableHttpClient httpclient;
   private String name;

   public EsReaderDefaultImpl(final CloseableHttpClient httpclient) {
      this(EsReaderDefaultImpl.class.getSimpleName() + "_" + UUID.randomUUID(), httpclient);
   }

   public EsReaderDefaultImpl(String name, final CloseableHttpClient httpclient) {
      this.name = name;
      this.httpclient = httpclient;
      final GsonBuilder gsonBuilder = new GsonBuilder();
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String ACCEPT_EVENTSTORE_ATOM_JSON = "application/vnd.eventstore.atom+json";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String ACCEPT_HEADER = "Accept";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/Event.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class Event {
//    private String eventId;
//    private String eventType;
//    private Long eventNumber;
//    private String streamId;
//    private Boolean isLinkMetaData;
//    private Long positionEventNumber;
//    private String positionStreamId;
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    private String summary;
// 
//    private String eventStreamId;
//    private String data;
//    private String metadata;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventDeletedException.java
// public class EventDeletedException extends RuntimeException {
//    private static final long serialVersionUID = 1L;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventResponse.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class EventResponse {
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    private String summary;
// 
//    private Event content;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventStreamFeed.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PUBLIC)
// @AllArgsConstructor(access = AccessLevel.PUBLIC)
// public class EventStreamFeed {
//    private String title;
//    private String id;
//    private String updated;
//    private Author author;
//    boolean headOfStream;
//    private List<Link> links;
//    private List<Entry> entries;
// 
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/model/EventStreamNotFoundException.java
// public class EventStreamNotFoundException extends RuntimeException {
//    private static final long serialVersionUID = 1L;
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/HttpCacheLoggingUtil.java
// public class HttpCacheLoggingUtil {
//    private static final Logger LOGGER = LoggerFactory.getLogger(HttpCacheLoggingUtil.class.getName());
// 
//    @SuppressWarnings("nls")
//    public static void logCacheResponseStatus(String prefix, CacheResponseStatus cacheResponseStatus) {
//       switch (cacheResponseStatus) {
//          case CACHE_HIT:
//             LOGGER.debug(prefix + ":A response was generated from the cache with no requests sent upstream");
//             break;
//          case CACHE_MODULE_RESPONSE:
//             LOGGER.debug(prefix + ":The response was generated directly by the caching module");
//             break;
//          case CACHE_MISS:
//             LOGGER.debug(prefix + ":The response came from an upstream server");
//             break;
//          case VALIDATED:
//             LOGGER.debug(prefix + ":The response was generated from the cache after validating the entry with the origin server");
//             break;
//          default:
//             break;
//       }
//    }
// 
// }


// Path: eventstore-client/src/main/java/de/qyotta/eventstore/communication/EsReaderDefaultImpl.java
import static de.qyotta.eventstore.utils.Constants.ACCEPT_EVENTSTORE_ATOM_JSON;
import static de.qyotta.eventstore.utils.Constants.ACCEPT_HEADER;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.http.HttpStatus;
import org.apache.http.client.cache.HttpCacheContext;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import de.qyotta.eventstore.model.Event;
import de.qyotta.eventstore.model.EventDeletedException;
import de.qyotta.eventstore.model.EventResponse;
import de.qyotta.eventstore.model.EventStreamFeed;
import de.qyotta.eventstore.model.EventStreamNotFoundException;
import de.qyotta.eventstore.utils.HttpCacheLoggingUtil;

package de.qyotta.eventstore.communication;






@SuppressWarnings("nls")
public class EsReaderDefaultImpl implements ESReader {
   private static final Logger LOGGER = LoggerFactory.getLogger(EsReaderDefaultImpl.class.getName());
   private final Gson gson;
   private final CloseableHttpClient httpclient;
   private String name;

   public EsReaderDefaultImpl(final CloseableHttpClient httpclient) {
      this(EsReaderDefaultImpl.class.getSimpleName() + "_" + UUID.randomUUID(), httpclient);
   }

   public EsReaderDefaultImpl(String name, final CloseableHttpClient httpclient) {
      this.name = name;
      this.httpclient = httpclient;
      final GsonBuilder gsonBuilder = new GsonBuilder();
      gsonBuilder.registerTypeAdapter(Event.class, new JsonDeserializer<Event>() {