package org.chenyang.http.impl.client;

import org.chenyang.http.Header;
import org.chenyang.http.HttpEntity;
import org.chenyang.http.HttpEntityEnclosingRequest;
import org.chenyang.http.ProtocolException;
import org.chenyang.http.entity.HttpEntityWrapper;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/** @deprecated */
@Deprecated
public class EntityEnclosingRequestWrapper extends RequestWrapper implements HttpEntityEnclosingRequest {
   private HttpEntity entity;
   private boolean consumed;

   public EntityEnclosingRequestWrapper(HttpEntityEnclosingRequest request) throws ProtocolException {
      super(request);
      this.setEntity(request.getEntity());
   }

   public HttpEntity getEntity() {
      return this.entity;
   }

   public void setEntity(HttpEntity entity) {
      this.entity = entity != null ? new EntityWrapper(entity) : null;
      this.consumed = false;
   }

   public boolean expectContinue() {
      Header expect = this.getFirstHeader("Expect");
      return expect != null && "100-continue".equalsIgnoreCase(expect.getValue());
   }

   public boolean isRepeatable() {
      return this.entity == null || this.entity.isRepeatable() || !this.consumed;
   }

   class EntityWrapper extends HttpEntityWrapper {
      EntityWrapper(HttpEntity entity) {
         super(entity);
      }

      public void consumeContent() throws IOException {
         EntityEnclosingRequestWrapper.this.consumed = true;
         super.consumeContent();
      }

      public InputStream getContent() throws IOException {
         EntityEnclosingRequestWrapper.this.consumed = true;
         return super.getContent();
      }

      public void writeTo(OutputStream outStream) throws IOException {
         EntityEnclosingRequestWrapper.this.consumed = true;
         super.writeTo(outStream);
      }
   }
}
