// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String CONTENT_TYPE_HEADER = "Event-Type";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String CONTENT_TYPE_JSON = "application/json";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String CONTENT_TYPE_JSON_EVENTS = "application/vnd.eventstore.events+json";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String ES_HARD_DELETE_HEADER = "ES-HardDelete";
// 
// 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/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.CONTENT_TYPE_HEADER;
import static de.qyotta.eventstore.utils.Constants.CONTENT_TYPE_JSON;
import static de.qyotta.eventstore.utils.Constants.CONTENT_TYPE_JSON_EVENTS;
import static de.qyotta.eventstore.utils.Constants.ES_HARD_DELETE_HEADER;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.http.Consts;
import org.apache.http.Header;
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.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import de.qyotta.eventstore.model.Event;
import de.qyotta.eventstore.utils.HttpCacheLoggingUtil;
   }

   @Override
   public void appendEvents(final String url, final Collection<Event> collection) {
      try {
         try {
            final HttpPost post = new HttpPost(url);
            post.addHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON_EVENTS);
            final JsonArray body = new JsonArray();
            for (final Event e : collection) {
               final JsonObject o = new JsonObject();
               o.addProperty("eventId", e.getEventId());
               o.addProperty("eventType", e.getEventType());
               o.add("metadata", gson.fromJson(e.getMetadata(), JsonObject.class));
               o.add("data", gson.fromJson(e.getData(), JsonObject.class));
               body.add(o);
            }

            final String jsonString = gson.toJson(body);
            post.setEntity(new StringEntity(jsonString, ContentType.create(CONTENT_TYPE_JSON_EVENTS, Consts.UTF_8)));

            LOGGER.debug("Executing request " + read(post.getEntity()
                  .getContent()));

            final HttpCacheContext context = HttpCacheContext.create();
            CloseableHttpResponse response = null;
            try {
               response = httpclient.execute(post, context);

               if (context.getCacheResponseStatus() != null) {
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String CONTENT_TYPE_HEADER = "Event-Type";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String CONTENT_TYPE_JSON = "application/json";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String CONTENT_TYPE_JSON_EVENTS = "application/vnd.eventstore.events+json";
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/Constants.java
// public static final String ES_HARD_DELETE_HEADER = "ES-HardDelete";
// 
// 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/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/EsWriterDefaultImpl.java
import static de.qyotta.eventstore.utils.Constants.CONTENT_TYPE_HEADER;
import static de.qyotta.eventstore.utils.Constants.CONTENT_TYPE_JSON;
import static de.qyotta.eventstore.utils.Constants.CONTENT_TYPE_JSON_EVENTS;
import static de.qyotta.eventstore.utils.Constants.ES_HARD_DELETE_HEADER;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.http.Consts;
import org.apache.http.Header;
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.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import de.qyotta.eventstore.model.Event;
import de.qyotta.eventstore.utils.HttpCacheLoggingUtil;

   }

   @Override
   public void appendEvents(final String url, final Collection<Event> collection) {
      try {
         try {
            final HttpPost post = new HttpPost(url);
            post.addHeader(CONTENT_TYPE_HEADER, CONTENT_TYPE_JSON_EVENTS);
            final JsonArray body = new JsonArray();
            for (final Event e : collection) {
               final JsonObject o = new JsonObject();
               o.addProperty("eventId", e.getEventId());
               o.addProperty("eventType", e.getEventType());
               o.add("metadata", gson.fromJson(e.getMetadata(), JsonObject.class));
               o.add("data", gson.fromJson(e.getData(), JsonObject.class));
               body.add(o);
            }

            final String jsonString = gson.toJson(body);
            post.setEntity(new StringEntity(jsonString, ContentType.create(CONTENT_TYPE_JSON_EVENTS, Consts.UTF_8)));

            LOGGER.debug("Executing request " + read(post.getEntity()
                  .getContent()));

            final HttpCacheContext context = HttpCacheContext.create();
            CloseableHttpResponse response = null;
            try {
               response = httpclient.execute(post, context);

               if (context.getCacheResponseStatus() != null) {
                  HttpCacheLoggingUtil.logCacheResponseStatus(name, context.getCacheResponseStatus());