package org.apache.http.impl.client;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.ProtocolException;
import org.apache.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);
      }
   }
}
