fluent-hc-4.3.5

16:35:53.098 INFO  jd.cli.Main - Decompiling fluent-hc-4.3.5.jar
package org.apache.http.client.fluent;

import org.apache.http.client.ResponseHandler;
import org.apache.http.concurrent.BasicFuture;

class Async$ExecRunnable<T>
  implements Runnable
{
  private final BasicFuture<T> future;
  private final Request request;
  private final Executor executor;
  private final ResponseHandler<T> handler;
  
  Async$ExecRunnable(BasicFuture<T> future, Request request, Executor executor, ResponseHandler<T> handler)
  {
    this.future = future;
    this.request = request;
    this.executor = executor;
    this.handler = handler;
  }
  
  public void run()
  {
    try
    {
      Response response = executor.execute(request);
      T result = response.handleResponse(handler);
      future.completed(result);
    }
    catch (Exception ex)
    {
      future.failed(ex);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.Async.ExecRunnable
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.util.EntityUtils;

public class Response
{
  private final HttpResponse response;
  private boolean consumed;
  
  Response(HttpResponse response)
  {
    this.response = response;
  }
  
  private void assertNotConsumed()
  {
    if (consumed) {
      throw new IllegalStateException("Response content has been already consumed");
    }
  }
  
  private void dispose()
  {
    if (consumed) {
      return;
    }
    try
    {
      HttpEntity entity = response.getEntity();
      InputStream content = entity.getContent();
      if (content != null) {
        content.close();
      }
    }
    catch (Exception ignore) {}finally
    {
      consumed = true;
    }
  }
  
  public void discardContent()
  {
    dispose();
  }
  
  public <T> T handleResponse(ResponseHandler<T> handler)
    throws ClientProtocolException, IOException
  {
    assertNotConsumed();
    try
    {
      return (T)handler.handleResponse(response);
    }
    finally
    {
      dispose();
    }
  }
  
  public Content returnContent()
    throws ClientProtocolException, IOException
  {
    return (Content)handleResponse(new ContentResponseHandler());
  }
  
  public HttpResponse returnResponse()
    throws IOException
  {
    assertNotConsumed();
    try
    {
      HttpEntity entity = response.getEntity();
      ByteArrayEntity byteArrayEntity;
      if (entity != null)
      {
        byteArrayEntity = new ByteArrayEntity(EntityUtils.toByteArray(entity));
        
        ContentType contentType = ContentType.getOrDefault(entity);
        byteArrayEntity.setContentType(contentType.toString());
        response.setEntity(byteArrayEntity);
      }
      return response;
    }
    finally
    {
      consumed = true;
    }
  }
  
  public void saveContent(File file)
    throws IOException
  {
    assertNotConsumed();
    StatusLine statusLine = response.getStatusLine();
    if (statusLine.getStatusCode() >= 300) {
      throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
    }
    FileOutputStream out = new FileOutputStream(file);
    try
    {
      HttpEntity entity = response.getEntity();
      if (entity != null) {
        entity.writeTo(out);
      }
    }
    finally
    {
      consumed = true;
      out.close();
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.Response
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.net.URI;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.annotation.NotThreadSafe;

@NotThreadSafe
class InternalEntityEnclosingHttpRequest
  extends InternalHttpRequest
  implements HttpEntityEnclosingRequest
{
  private HttpEntity entity;
  
  public InternalEntityEnclosingHttpRequest(String method, URI requestURI)
  {
    super(method, requestURI);
  }
  
  public HttpEntity getEntity()
  {
    return entity;
  }
  
  public void setEntity(HttpEntity entity)
  {
    this.entity = entity;
  }
  
  public boolean expectContinue()
  {
    Header expect = getFirstHeader("Expect");
    return (expect != null) && ("100-continue".equalsIgnoreCase(expect.getValue()));
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.InternalEntityEnclosingHttpRequest
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpResponseException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.entity.ContentType;
import org.apache.http.util.EntityUtils;

class ContentResponseHandler
  implements ResponseHandler<Content>
{
  public Content handleResponse(HttpResponse response)
    throws ClientProtocolException, IOException
  {
    StatusLine statusLine = response.getStatusLine();
    HttpEntity entity = response.getEntity();
    if (statusLine.getStatusCode() >= 300) {
      throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase());
    }
    if (entity != null) {
      return new Content(EntityUtils.toByteArray(entity), ContentType.getOrDefault(entity));
    }
    return Content.NO_CONTENT;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.ContentResponseHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpHost;
import org.apache.http.HttpVersion;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.config.RequestConfig.Builder;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.ContentType;

public class Request
{
  public static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
  public static final Locale DATE_LOCALE = Locale.US;
  public static final TimeZone TIME_ZONE = TimeZone.getTimeZone("GMT");
  private final InternalHttpRequest request;
  private final RequestConfig.Builder configBuilder;
  private SimpleDateFormat dateFormatter;
  
  public static Request Get(URI uri)
  {
    return new Request(new InternalHttpRequest("GET", uri));
  }
  
  public static Request Get(String uri)
  {
    return new Request(new InternalHttpRequest("GET", URI.create(uri)));
  }
  
  public static Request Head(URI uri)
  {
    return new Request(new InternalHttpRequest("HEAD", uri));
  }
  
  public static Request Head(String uri)
  {
    return new Request(new InternalHttpRequest("HEAD", URI.create(uri)));
  }
  
  public static Request Post(URI uri)
  {
    return new Request(new InternalEntityEnclosingHttpRequest("POST", uri));
  }
  
  public static Request Post(String uri)
  {
    return new Request(new InternalEntityEnclosingHttpRequest("POST", URI.create(uri)));
  }
  
  public static Request Put(URI uri)
  {
    return new Request(new InternalEntityEnclosingHttpRequest("PUT", uri));
  }
  
  public static Request Put(String uri)
  {
    return new Request(new InternalEntityEnclosingHttpRequest("PUT", URI.create(uri)));
  }
  
  public static Request Trace(URI uri)
  {
    return new Request(new InternalHttpRequest("TRACE", uri));
  }
  
  public static Request Trace(String uri)
  {
    return new Request(new InternalHttpRequest("TRACE", URI.create(uri)));
  }
  
  public static Request Delete(URI uri)
  {
    return new Request(new InternalHttpRequest("DELETE", uri));
  }
  
  public static Request Delete(String uri)
  {
    return new Request(new InternalHttpRequest("DELETE", URI.create(uri)));
  }
  
  public static Request Options(URI uri)
  {
    return new Request(new InternalHttpRequest("OPTIONS", uri));
  }
  
  public static Request Options(String uri)
  {
    return new Request(new InternalHttpRequest("OPTIONS", URI.create(uri)));
  }
  
  Request(InternalHttpRequest request)
  {
    this.request = request;
    configBuilder = RequestConfig.custom();
  }
  
  InternalHttpRequest prepareRequest()
  {
    request.setConfig(configBuilder.build());
    return request;
  }
  
  public Response execute()
    throws ClientProtocolException, IOException
  {
    request.setConfig(configBuilder.build());
    return new Response(Executor.CLIENT.execute(request));
  }
  
  public void abort()
    throws UnsupportedOperationException
  {
    request.abort();
  }
  
  public Request addHeader(Header header)
  {
    request.addHeader(header);
    return this;
  }
  
  public Request setHeader(Header header)
  {
    request.setHeader(header);
    return this;
  }
  
  public Request addHeader(String name, String value)
  {
    request.addHeader(name, value);
    return this;
  }
  
  public Request setHeader(String name, String value)
  {
    request.setHeader(name, value);
    return this;
  }
  
  public Request removeHeader(Header header)
  {
    request.removeHeader(header);
    return this;
  }
  
  public Request removeHeaders(String name)
  {
    request.removeHeaders(name);
    return this;
  }
  
  public Request setHeaders(Header... headers)
  {
    request.setHeaders(headers);
    return this;
  }
  
  public Request setCacheControl(String cacheControl)
  {
    request.setHeader("Cache-Control", cacheControl);
    return this;
  }
  
  private SimpleDateFormat getDateFormat()
  {
    if (dateFormatter == null)
    {
      dateFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", DATE_LOCALE);
      dateFormatter.setTimeZone(TIME_ZONE);
    }
    return dateFormatter;
  }
  
  public Request setDate(Date date)
  {
    request.setHeader("Date", getDateFormat().format(date));
    return this;
  }
  
  public Request setIfModifiedSince(Date date)
  {
    request.setHeader("If-Modified-Since", getDateFormat().format(date));
    return this;
  }
  
  public Request setIfUnmodifiedSince(Date date)
  {
    request.setHeader("If-Unmodified-Since", getDateFormat().format(date));
    return this;
  }
  
  @Deprecated
  public Request config(String param, Object object)
  {
    return this;
  }
  
  @Deprecated
  public Request removeConfig(String param)
  {
    return this;
  }
  
  public Request version(HttpVersion version)
  {
    request.setProtocolVersion(version);
    return this;
  }
  
  @Deprecated
  public Request elementCharset(String charset)
  {
    return this;
  }
  
  public Request useExpectContinue()
  {
    configBuilder.setExpectContinueEnabled(true);
    return this;
  }
  
  public Request userAgent(String agent)
  {
    request.setHeader("User-Agent", agent);
    return this;
  }
  
  public Request socketTimeout(int timeout)
  {
    configBuilder.setSocketTimeout(timeout);
    return this;
  }
  
  public Request connectTimeout(int timeout)
  {
    configBuilder.setConnectTimeout(timeout);
    return this;
  }
  
  public Request staleConnectionCheck(boolean b)
  {
    configBuilder.setStaleConnectionCheckEnabled(b);
    return this;
  }
  
  public Request viaProxy(HttpHost proxy)
  {
    configBuilder.setProxy(proxy);
    return this;
  }
  
  public Request body(HttpEntity entity)
  {
    if ((request instanceof HttpEntityEnclosingRequest)) {
      ((HttpEntityEnclosingRequest)request).setEntity(entity);
    } else {
      throw new IllegalStateException(request.getMethod() + " request cannot enclose an entity");
    }
    return this;
  }
  
  public Request bodyForm(Iterable<? extends NameValuePair> formParams, Charset charset)
  {
    List<NameValuePair> paramList = new ArrayList();
    for (NameValuePair param : formParams) {
      paramList.add(param);
    }
    ContentType contentType = ContentType.create("application/x-www-form-urlencoded", charset);
    String s = URLEncodedUtils.format(paramList, charset != null ? charset.name() : null);
    return bodyString(s, contentType);
  }
  
  public Request bodyForm(Iterable<? extends NameValuePair> formParams)
  {
    return bodyForm(formParams, Consts.ISO_8859_1);
  }
  
  public Request bodyForm(NameValuePair... formParams)
  {
    return bodyForm(Arrays.asList(formParams), Consts.ISO_8859_1);
  }
  
  public Request bodyString(String s, ContentType contentType)
  {
    Charset charset = contentType != null ? contentType.getCharset() : null;
    byte[] raw;
    try
    {
      raw = charset != null ? s.getBytes(charset.name()) : s.getBytes();
    }
    catch (UnsupportedEncodingException ex)
    {
      raw = s.getBytes();
    }
    return body(new InternalByteArrayEntity(raw, contentType));
  }
  
  public Request bodyFile(File file, ContentType contentType)
  {
    return body(new InternalFileEntity(file, contentType));
  }
  
  public Request bodyByteArray(byte[] b)
  {
    return body(new InternalByteArrayEntity(b));
  }
  
  public Request bodyByteArray(byte[] b, int off, int len)
  {
    return body(new InternalByteArrayEntity(b, off, len));
  }
  
  public Request bodyStream(InputStream instream)
  {
    return body(new InternalInputStreamEntity(instream, -1L, null));
  }
  
  public Request bodyStream(InputStream instream, ContentType contentType)
  {
    return body(new InternalInputStreamEntity(instream, -1L, contentType));
  }
  
  public String toString()
  {
    return request.getRequestLine().toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.Request
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Form
{
  private final List<NameValuePair> params;
  
  public static Form form()
  {
    return new Form();
  }
  
  Form()
  {
    params = new ArrayList();
  }
  
  public Form add(String name, String value)
  {
    params.add(new BasicNameValuePair(name, value));
    return this;
  }
  
  public List<NameValuePair> build()
  {
    return new ArrayList(params);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.Form
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;

class InternalByteArrayEntity
  extends AbstractHttpEntity
  implements Cloneable
{
  private final byte[] b;
  private final int off;
  private final int len;
  
  public InternalByteArrayEntity(byte[] b, ContentType contentType)
  {
    Args.notNull(b, "Source byte array");
    this.b = b;
    off = 0;
    len = this.b.length;
    if (contentType != null) {
      setContentType(contentType.toString());
    }
  }
  
  public InternalByteArrayEntity(byte[] b, int off, int len, ContentType contentType)
  {
    Args.notNull(b, "Source byte array");
    if ((off < 0) || (off > b.length) || (len < 0) || (off + len < 0) || (off + len > b.length)) {
      throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length);
    }
    this.b = b;
    this.off = off;
    this.len = len;
    if (contentType != null) {
      setContentType(contentType.toString());
    }
  }
  
  public InternalByteArrayEntity(byte[] b)
  {
    this(b, null);
  }
  
  public InternalByteArrayEntity(byte[] b, int off, int len)
  {
    this(b, off, len, null);
  }
  
  public boolean isRepeatable()
  {
    return true;
  }
  
  public long getContentLength()
  {
    return len;
  }
  
  public InputStream getContent()
  {
    return new ByteArrayInputStream(b, off, len);
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    Args.notNull(outstream, "Output stream");
    outstream.write(b, off, len);
    outstream.flush();
  }
  
  public boolean isStreaming()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.InternalByteArrayEntity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.MalformedChallengeException;
import org.apache.http.auth.NTCredentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLInitializationException;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeader;

public class Executor
{
  static final PoolingHttpClientConnectionManager CONNMGR;
  
  static
  {
    LayeredConnectionSocketFactory ssl = null;
    try
    {
      ssl = SSLConnectionSocketFactory.getSystemSocketFactory();
    }
    catch (SSLInitializationException ex)
    {
      try
      {
        SSLContext sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(null, null, null);
        ssl = new SSLConnectionSocketFactory(sslcontext);
      }
      catch (SecurityException ignore) {}catch (KeyManagementException ignore) {}catch (NoSuchAlgorithmException ignore) {}
    }
    Registry<ConnectionSocketFactory> sfr = RegistryBuilder.create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", ssl != null ? ssl : SSLConnectionSocketFactory.getSocketFactory()).build();
    
    CONNMGR = new PoolingHttpClientConnectionManager(sfr);
    CONNMGR.setDefaultMaxPerRoute(100);
    CONNMGR.setMaxTotal(200);
  }
  
  static final HttpClient CLIENT = HttpClientBuilder.create().setConnectionManager(CONNMGR).build();
  private final HttpClient httpclient;
  private final AuthCache authCache;
  private final CredentialsProvider credentialsProvider;
  private volatile CookieStore cookieStore;
  
  public static Executor newInstance()
  {
    return new Executor(CLIENT);
  }
  
  public static Executor newInstance(HttpClient httpclient)
  {
    return new Executor(httpclient != null ? httpclient : CLIENT);
  }
  
  Executor(HttpClient httpclient)
  {
    this.httpclient = httpclient;
    credentialsProvider = new BasicCredentialsProvider();
    authCache = new BasicAuthCache();
  }
  
  public Executor auth(AuthScope authScope, Credentials creds)
  {
    credentialsProvider.setCredentials(authScope, creds);
    return this;
  }
  
  public Executor auth(HttpHost host, Credentials creds)
  {
    AuthScope authScope = host != null ? new AuthScope(host.getHostName(), host.getPort()) : AuthScope.ANY;
    
    return auth(authScope, creds);
  }
  
  public Executor authPreemptive(HttpHost host)
  {
    BasicScheme basicScheme = new BasicScheme();
    try
    {
      basicScheme.processChallenge(new BasicHeader("WWW-Authenticate", "BASIC "));
    }
    catch (MalformedChallengeException ignore) {}
    authCache.put(host, basicScheme);
    return this;
  }
  
  public Executor authPreemptiveProxy(HttpHost host)
  {
    BasicScheme basicScheme = new BasicScheme();
    try
    {
      basicScheme.processChallenge(new BasicHeader("Proxy-Authenticate", "BASIC "));
    }
    catch (MalformedChallengeException ignore) {}
    authCache.put(host, basicScheme);
    return this;
  }
  
  public Executor auth(Credentials cred)
  {
    return auth(AuthScope.ANY, cred);
  }
  
  public Executor auth(String username, String password)
  {
    return auth(new UsernamePasswordCredentials(username, password));
  }
  
  public Executor auth(String username, String password, String workstation, String domain)
  {
    return auth(new NTCredentials(username, password, workstation, domain));
  }
  
  public Executor auth(HttpHost host, String username, String password)
  {
    return auth(host, new UsernamePasswordCredentials(username, password));
  }
  
  public Executor auth(HttpHost host, String username, String password, String workstation, String domain)
  {
    return auth(host, new NTCredentials(username, password, workstation, domain));
  }
  
  public Executor clearAuth()
  {
    credentialsProvider.clear();
    return this;
  }
  
  public Executor cookieStore(CookieStore cookieStore)
  {
    this.cookieStore = cookieStore;
    return this;
  }
  
  public Executor clearCookies()
  {
    cookieStore.clear();
    return this;
  }
  
  public Response execute(Request request)
    throws ClientProtocolException, IOException
  {
    HttpClientContext localContext = HttpClientContext.create();
    localContext.setAttribute("http.auth.credentials-provider", credentialsProvider);
    localContext.setAttribute("http.auth.auth-cache", authCache);
    localContext.setAttribute("http.cookie-store", cookieStore);
    InternalHttpRequest httprequest = request.prepareRequest();
    return new Response(httpclient.execute(httprequest, localContext));
  }
  
  @Deprecated
  public static void registerScheme(Scheme scheme) {}
  
  @Deprecated
  public static void unregisterScheme(String name) {}
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.Executor
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;

class InternalFileEntity
  extends AbstractHttpEntity
  implements Cloneable
{
  private final File file;
  
  public InternalFileEntity(File file, ContentType contentType)
  {
    this.file = ((File)Args.notNull(file, "File"));
    if (contentType != null) {
      setContentType(contentType.toString());
    }
  }
  
  public boolean isRepeatable()
  {
    return true;
  }
  
  public long getContentLength()
  {
    return file.length();
  }
  
  public InputStream getContent()
    throws IOException
  {
    return new FileInputStream(file);
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    Args.notNull(outstream, "Output stream");
    InputStream instream = new FileInputStream(file);
    try
    {
      byte[] tmp = new byte['?'];
      int l;
      while ((l = instream.read(tmp)) != -1) {
        outstream.write(tmp, 0, l);
      }
      outstream.flush();
    }
    finally
    {
      instream.close();
    }
  }
  
  public boolean isStreaming()
  {
    return false;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.InternalFileEntity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.entity.AbstractHttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.util.Args;

class InternalInputStreamEntity
  extends AbstractHttpEntity
{
  private final InputStream content;
  private final long length;
  
  public InternalInputStreamEntity(InputStream instream, long length, ContentType contentType)
  {
    content = ((InputStream)Args.notNull(instream, "Source input stream"));
    this.length = length;
    if (contentType != null) {
      setContentType(contentType.toString());
    }
  }
  
  public boolean isRepeatable()
  {
    return false;
  }
  
  public long getContentLength()
  {
    return length;
  }
  
  public InputStream getContent()
    throws IOException
  {
    return content;
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    Args.notNull(outstream, "Output stream");
    InputStream instream = content;
    try
    {
      byte[] buffer = new byte['?'];
      if (length < 0L)
      {
        int l;
        while ((l = instream.read(buffer)) != -1) {
          outstream.write(buffer, 0, l);
        }
      }
      long remaining = length;
      while (remaining > 0L)
      {
        int l = instream.read(buffer, 0, (int)Math.min(4096L, remaining));
        if (l == -1) {
          break;
        }
        outstream.write(buffer, 0, l);
        remaining -= l;
      }
    }
    finally
    {
      instream.close();
    }
  }
  
  public boolean isStreaming()
  {
    return true;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.InternalInputStreamEntity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.net.URI;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.http.HttpVersion;
import org.apache.http.ProtocolVersion;
import org.apache.http.RequestLine;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.Configurable;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.concurrent.Cancellable;
import org.apache.http.message.AbstractHttpMessage;
import org.apache.http.message.BasicRequestLine;
import org.apache.http.util.Args;

@NotThreadSafe
class InternalHttpRequest
  extends AbstractHttpMessage
  implements HttpUriRequest, HttpExecutionAware, Configurable
{
  private final String method;
  private ProtocolVersion version;
  private URI uri;
  private RequestConfig config;
  private final AtomicBoolean aborted;
  private final AtomicReference<Cancellable> cancellableRef;
  
  InternalHttpRequest(String method, URI requestURI)
  {
    Args.notBlank(method, "Method");
    Args.notNull(requestURI, "Request URI");
    this.method = method;
    uri = requestURI;
    aborted = new AtomicBoolean(false);
    cancellableRef = new AtomicReference(null);
  }
  
  public void setProtocolVersion(ProtocolVersion version)
  {
    this.version = version;
  }
  
  public ProtocolVersion getProtocolVersion()
  {
    return version != null ? version : HttpVersion.HTTP_1_1;
  }
  
  public String getMethod()
  {
    return method;
  }
  
  public URI getURI()
  {
    return uri;
  }
  
  public void abort()
    throws UnsupportedOperationException
  {
    if (aborted.compareAndSet(false, true))
    {
      Cancellable cancellable = (Cancellable)cancellableRef.getAndSet(null);
      if (cancellable != null) {
        cancellable.cancel();
      }
    }
  }
  
  public boolean isAborted()
  {
    return aborted.get();
  }
  
  public void setCancellable(Cancellable cancellable)
  {
    if (!aborted.get()) {
      cancellableRef.set(cancellable);
    }
  }
  
  public RequestLine getRequestLine()
  {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    URI uri = getURI();
    String uritext = null;
    if (uri != null) {
      uritext = uri.toASCIIString();
    }
    if ((uritext == null) || (uritext.length() == 0)) {
      uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
  }
  
  public RequestConfig getConfig()
  {
    return config;
  }
  
  public void setConfig(RequestConfig config)
  {
    this.config = config;
  }
  
  public void setURI(URI uri)
  {
    this.uri = uri;
  }
  
  public String toString()
  {
    return getMethod() + " " + getURI() + " " + getProtocolVersion();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.InternalHttpRequest
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import org.apache.http.Consts;
import org.apache.http.entity.ContentType;

public class Content
{
  public static final Content NO_CONTENT = new Content(new byte[0], ContentType.DEFAULT_BINARY);
  private final byte[] raw;
  private final ContentType type;
  
  Content(byte[] raw, ContentType type)
  {
    this.raw = raw;
    this.type = type;
  }
  
  public ContentType getType()
  {
    return type;
  }
  
  public byte[] asBytes()
  {
    return (byte[])raw.clone();
  }
  
  public String asString()
  {
    Charset charset = type.getCharset();
    if (charset == null) {
      charset = Consts.ISO_8859_1;
    }
    try
    {
      return new String(raw, charset.name());
    }
    catch (UnsupportedEncodingException ex) {}
    return new String(raw);
  }
  
  public InputStream asStream()
  {
    return new ByteArrayInputStream(raw);
  }
  
  public String toString()
  {
    return asString();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.Content
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

class HttpHeader
{
  public static final String CONTENT_LENGTH = "Content-Length";
  public static final String DATE = "Date";
  public static final String CACHE_CONTROL = "Cache-Control";
  public static final String CONTENT_TYPE = "Content-Type";
  public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
  public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.HttpHeader
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.client.fluent;

import java.util.concurrent.Future;
import org.apache.http.client.ResponseHandler;
import org.apache.http.concurrent.BasicFuture;
import org.apache.http.concurrent.FutureCallback;

public class Async
{
  private Executor executor;
  private java.util.concurrent.Executor concurrentExec;
  
  public static Async newInstance()
  {
    return new Async();
  }
  
  public Async use(Executor executor)
  {
    this.executor = executor;
    return this;
  }
  
  public Async use(java.util.concurrent.Executor concurrentExec)
  {
    this.concurrentExec = concurrentExec;
    return this;
  }
  
  static class ExecRunnable<T>
    implements Runnable
  {
    private final BasicFuture<T> future;
    private final Request request;
    private final Executor executor;
    private final ResponseHandler<T> handler;
    
    ExecRunnable(BasicFuture<T> future, Request request, Executor executor, ResponseHandler<T> handler)
    {
      this.future = future;
      this.request = request;
      this.executor = executor;
      this.handler = handler;
    }
    
    public void run()
    {
      try
      {
        Response response = executor.execute(request);
        T result = response.handleResponse(handler);
        future.completed(result);
      }
      catch (Exception ex)
      {
        future.failed(ex);
      }
    }
  }
  
  public <T> Future<T> execute(Request request, ResponseHandler<T> handler, FutureCallback<T> callback)
  {
    BasicFuture<T> future = new BasicFuture(callback);
    ExecRunnable<T> runnable = new ExecRunnable(future, request, executor != null ? executor : Executor.newInstance(), handler);
    if (concurrentExec != null)
    {
      concurrentExec.execute(runnable);
    }
    else
    {
      Thread t = new Thread(runnable);
      t.setDaemon(true);
      t.start();
    }
    return future;
  }
  
  public <T> Future<T> execute(Request request, ResponseHandler<T> handler)
  {
    return execute(request, handler, null);
  }
  
  public Future<Content> execute(Request request, FutureCallback<Content> callback)
  {
    return execute(request, new ContentResponseHandler(), callback);
  }
  
  public Future<Content> execute(Request request)
  {
    return execute(request, new ContentResponseHandler(), null);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.client.fluent.Async
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd