com.crashlytics.tools.android_2.1.0

+)
    {
      char ch = s.charAt(i);
      if ((ch == '"') || (ch == ',') || (ch == ';')) {
        return false;
      }
    }
    return true;
  }
  
  public static ContentType create(String mimeType, Charset charset)
  {
    String type = ((String)Args.notBlank(mimeType, "MIME type")).toLowerCase(Locale.US);
    Args.check(valid(type), "MIME type may not contain reserved characters");
    return new ContentType(type, charset);
  }
  
  public static ContentType create(String mimeType)
  {
    return new ContentType(mimeType, (Charset)null);
  }
  
  public static ContentType create(String mimeType, String charset)
    throws UnsupportedCharsetException
  {
    return create(mimeType, !TextUtils.isBlank(charset) ? Charset.forName(charset) : null);
  }
  
  private static ContentType create(HeaderElement helem)
  {
    String mimeType = helem.getName();
    NameValuePair[] params = helem.getParameters();
    return new ContentType(mimeType, (params != null) && (params.length > 0) ? params : null);
  }
  
  public static ContentType parse(String s)
    throws ParseException, UnsupportedCharsetException
  {
    Args.notNull(s, "Content type");
    CharArrayBuffer buf = new CharArrayBuffer(s.length());
    buf.append(s);
    ParserCursor cursor = new ParserCursor(0, s.length());
    HeaderElement[] elements = BasicHeaderValueParser.INSTANCE.parseElements(buf, cursor);
    if (elements.length > 0) {
      return create(elements[0]);
    }
    throw new ParseException("Invalid content type: " + s);
  }
  
  public static ContentType get(HttpEntity entity)
    throws ParseException, UnsupportedCharsetException
  {
    if (entity == null) {
      return null;
    }
    Header header = entity.getContentType();
    if (header != null)
    {
      HeaderElement[] elements = header.getElements();
      if (elements.length > 0) {
        return create(elements[0]);
      }
    }
    return null;
  }
  
  public static ContentType getOrDefault(HttpEntity entity)
    throws ParseException, UnsupportedCharsetException
  {
    ContentType contentType = get(entity);
    return contentType != null ? contentType : DEFAULT_TEXT;
  }
  
  public ContentType withCharset(Charset charset)
  {
    return create(getMimeType(), charset);
  }
  
  public ContentType withCharset(String charset)
  {
    return create(getMimeType(), charset);
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.util.Args;

public class EntityTemplate
  extends AbstractHttpEntity
{
  private final ContentProducer contentproducer;
  
  public EntityTemplate(ContentProducer contentproducer)
  {
    this.contentproducer = ((ContentProducer)Args.notNull(contentproducer, "Content producer"));
  }
  
  public long getContentLength()
  {
    return -1L;
  }
  
  public InputStream getContent()
    throws IOException
  {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    writeTo(buf);
    return new ByteArrayInputStream(buf.toByteArray());
  }
  
  public boolean isRepeatable()
  {
    return true;
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    Args.notNull(outstream, "Output stream");
    contentproducer.writeTo(outstream);
  }
  
  public boolean isStreaming()
  {
    return false;
  }
}

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

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;

@NotThreadSafe
public class FileEntity
  extends AbstractHttpEntity
  implements Cloneable
{
  protected final File file;
  
  @Deprecated
  public FileEntity(File file, String contentType)
  {
    this.file = ((File)Args.notNull(file, "File"));
    setContentType(contentType);
  }
  
  public FileEntity(File file, ContentType contentType)
  {
    this.file = ((File)Args.notNull(file, "File"));
    if (contentType != null) {
      setContentType(contentType.toString());
    }
  }
  
  public FileEntity(File file)
  {
    this.file = ((File)Args.notNull(file, "File"));
  }
  
  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;
  }
  
  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;

@NotThreadSafe
public class HttpEntityWrapper
  implements HttpEntity
{
  protected HttpEntity wrappedEntity;
  
  public HttpEntityWrapper(HttpEntity wrappedEntity)
  {
    this.wrappedEntity = ((HttpEntity)Args.notNull(wrappedEntity, "Wrapped entity"));
  }
  
  public boolean isRepeatable()
  {
    return wrappedEntity.isRepeatable();
  }
  
  public boolean isChunked()
  {
    return wrappedEntity.isChunked();
  }
  
  public long getContentLength()
  {
    return wrappedEntity.getContentLength();
  }
  
  public Header getContentType()
  {
    return wrappedEntity.getContentType();
  }
  
  public Header getContentEncoding()
  {
    return wrappedEntity.getContentEncoding();
  }
  
  public InputStream getContent()
    throws IOException
  {
    return wrappedEntity.getContent();
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    wrappedEntity.writeTo(outstream);
  }
  
  public boolean isStreaming()
  {
    return wrappedEntity.isStreaming();
  }
  
  @Deprecated
  public void consumeContent()
    throws IOException
  {
    wrappedEntity.consumeContent();
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;

@NotThreadSafe
public class InputStreamEntity
  extends AbstractHttpEntity
{
  private final InputStream content;
  private final long length;
  
  public InputStreamEntity(InputStream instream)
  {
    this(instream, -1L);
  }
  
  public InputStreamEntity(InputStream instream, long length)
  {
    this(instream, length, null);
  }
  
  public InputStreamEntity(InputStream instream, ContentType contentType)
  {
    this(instream, -1L, contentType);
  }
  
  public InputStreamEntity(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.entity.InputStreamEntity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.entity;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.Args;

@NotThreadSafe
public class SerializableEntity
  extends AbstractHttpEntity
{
  private byte[] objSer;
  private Serializable objRef;
  
  public SerializableEntity(Serializable ser, boolean bufferize)
    throws IOException
  {
    Args.notNull(ser, "Source object");
    if (bufferize) {
      createBytes(ser);
    } else {
      objRef = ser;
    }
  }
  
  public SerializableEntity(Serializable ser)
  {
    Args.notNull(ser, "Source object");
    objRef = ser;
  }
  
  private void createBytes(Serializable ser)
    throws IOException
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(ser);
    out.flush();
    objSer = baos.toByteArray();
  }
  
  public InputStream getContent()
    throws IOException, IllegalStateException
  {
    if (objSer == null) {
      createBytes(objRef);
    }
    return new ByteArrayInputStream(objSer);
  }
  
  public long getContentLength()
  {
    if (objSer == null) {
      return -1L;
    }
    return objSer.length;
  }
  
  public boolean isRepeatable()
  {
    return true;
  }
  
  public boolean isStreaming()
  {
    return objSer == null;
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    Args.notNull(outstream, "Output stream");
    if (objSer == null)
    {
      ObjectOutputStream out = new ObjectOutputStream(outstream);
      out.writeObject(objRef);
      out.flush();
    }
    else
    {
      outstream.write(objSer);
      outstream.flush();
    }
  }
}

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

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.Args;

@NotThreadSafe
public class StringEntity
  extends AbstractHttpEntity
  implements Cloneable
{
  protected final byte[] content;
  
  public StringEntity(String string, ContentType contentType)
  {
    Args.notNull(string, "Source string");
    Charset charset = contentType != null ? contentType.getCharset() : null;
    if (charset == null) {
      charset = HTTP.DEF_CONTENT_CHARSET;
    }
    try
    {
      content = string.getBytes(charset.name());
    }
    catch (UnsupportedEncodingException ex)
    {
      throw new UnsupportedCharsetException(charset.name());
    }
    if (contentType != null) {
      setContentType(contentType.toString());
    }
  }
  
  @Deprecated
  public StringEntity(String string, String mimeType, String charset)
    throws UnsupportedEncodingException
  {
    Args.notNull(string, "Source string");
    String mt = mimeType != null ? mimeType : "text/plain";
    String cs = charset != null ? charset : "ISO-8859-1";
    content = string.getBytes(cs);
    setContentType(mt + "; charset=" + cs);
  }
  
  public StringEntity(String string, String charset)
    throws UnsupportedEncodingException
  {
    this(string, ContentType.create(ContentType.TEXT_PLAIN.getMimeType(), charset));
  }
  
  public StringEntity(String string, Charset charset)
  {
    this(string, ContentType.create(ContentType.TEXT_PLAIN.getMimeType(), charset));
  }
  
  public StringEntity(String string)
    throws UnsupportedEncodingException
  {
    this(string, ContentType.DEFAULT_TEXT);
  }
  
  public boolean isRepeatable()
  {
    return true;
  }
  
  public long getContentLength()
  {
    return content.length;
  }
  
  public InputStream getContent()
    throws IOException
  {
    return new ByteArrayInputStream(content);
  }
  
  public void writeTo(OutputStream outstream)
    throws IOException
  {
    Args.notNull(outstream, "Output stream");
    outstream.write(content);
    outstream.flush();
  }
  
  public boolean isStreaming()
  {
    return false;
  }
  
  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }
}

/* Location:
 * Qualified Name:     org.apache.http.entity.StringEntity
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl;

import java.io.IOException;
import java.net.SocketTimeoutException;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpConnectionMetrics;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
import org.apache.http.StatusLine;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.impl.entity.EntityDeserializer;
import org.apache.http.impl.entity.EntitySerializer;
import org.apache.http.impl.entity.LaxContentLengthStrategy;
import org.apache.http.impl.entity.StrictContentLengthStrategy;
import org.apache.http.impl.io.DefaultHttpResponseParser;
import org.apache.http.impl.io.HttpRequestWriter;
import org.apache.http.io.EofSensor;
import org.apache.http.io.HttpMessageParser;
import org.apache.http.io.HttpMessageWriter;
import org.apache.http.io.HttpTransportMetrics;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.io.SessionOutputBuffer;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;

@Deprecated
@NotThreadSafe
public abstract class AbstractHttpClientConnection
  implements HttpClientConnection
{
  private final EntitySerializer entityserializer;
  private final EntityDeserializer entitydeserializer;
  private SessionInputBuffer inbuffer = null;
  private SessionOutputBuffer outbuffer = null;
  private EofSensor eofSensor = null;
  private HttpMessageParser<HttpResponse> responseParser = null;
  private HttpMessageWriter<HttpRequest> requestWriter = null;
  private HttpConnectionMetricsImpl metrics = null;
  
  public AbstractHttpClientConnection()
  {
    entityserializer = createEntitySerializer();
    entitydeserializer = createEntityDeserializer();
  }
  
  protected abstract void assertOpen()
    throws IllegalStateException;
  
  protected EntityDeserializer createEntityDeserializer()
  {
    return new EntityDeserializer(new LaxContentLengthStrategy());
  }
  
  protected EntitySerializer createEntitySerializer()
  {
    return new EntitySerializer(new StrictContentLengthStrategy());
  }
  
  protected HttpResponseFactory createHttpResponseFactory()
  {
    return DefaultHttpResponseFactory.INSTANCE;
  }
  
  protected HttpMessageParser<HttpResponse> createResponseParser(SessionInputBuffer buffer, HttpResponseFactory responseFactory, HttpParams params)
  {
    return new DefaultHttpResponseParser(buffer, null, responseFactory, params);
  }
  
  protected HttpMessageWriter<HttpRequest> createRequestWriter(SessionOutputBuffer buffer, HttpParams params)
  {
    return new HttpRequestWriter(buffer, null, params);
  }
  
  protected HttpConnectionMetricsImpl createConnectionMetrics(HttpTransportMetrics inTransportMetric, HttpTransportMetrics outTransportMetric)
  {
    return new HttpConnectionMetricsImpl(inTransportMetric, outTransportMetric);
  }
  
  protected void init(SessionInputBuffer inbuffer, SessionOutputBuffer outbuffer, HttpParams params)
  {
    this.inbuffer = ((SessionInputBuffer)Args.notNull(inbuffer, "Input session buffer"));
    this.outbuffer = ((SessionOutputBuffer)Args.notNull(outbuffer, "Output session buffer"));
    if ((inbuffer instanceof EofSensor)) {
      eofSensor = ((EofSensor)inbuffer);
    }
    responseParser = createResponseParser(inbuffer, createHttpResponseFactory(), params);
    
    requestWriter = createRequestWriter(outbuffer, params);
    
    metrics = createConnectionMetrics(inbuffer.getMetrics(), outbuffer.getMetrics());
  }
  
  public boolean isResponseAvailable(int timeout)
    throws IOException
  {
    assertOpen();
    try
    {
      return inbuffer.isDataAvailable(timeout);
    }
    catch (SocketTimeoutException ex) {}
    return false;
  }
  
  public void sendRequestHeader(HttpRequest request)
    throws HttpException, IOException
  {
    Args.notNull(request, "HTTP request");
    assertOpen();
    requestWriter.write(request);
    metrics.incrementRequestCount();
  }
  
  public void sendRequestEntity(HttpEntityEnclosingRequest request)
    throws HttpException, IOException
  {
    Args.notNull(request, "HTTP request");
    assertOpen();
    if (request.getEntity() == null) {
      return;
    }
    entityserializer.serialize(outbuffer, request, request.getEntity());
  }
  
  protected void doFlush()
    throws IOException
  {
    outbuffer.flush();
  }
  
  public void flush()
    throws IOException
  {
    assertOpen();
    doFlush();
  }
  
  public HttpResponse receiveResponseHeader()
    throws HttpException, IOException
  {
    assertOpen();
    HttpResponse response = (HttpResponse)responseParser.parse();
    if (response.getStatusLine().getStatusCode() >= 200) {
      metrics.incrementResponseCount();
    }
    return response;
  }
  
  public void receiveResponseEntity(HttpResponse response)
    throws HttpException, IOException
  {
    Args.notNull(response, "HTTP response");
    assertOpen();
    HttpEntity entity = entitydeserializer.deserialize(inbuffer, response);
    response.setEntity(entity);
  }
  
  protected boolean isEof()
  {
    return (eofSensor != null) && (eofSensor.isEof());
  }
  
  public boolean isStale()
  {
    if (!isOpen()) {
      return true;
    }
    if (isEof()) {
      return true;
    }
    try
    {
      inbuffer.isDataAvailable(1);
      return isEof();
    }
    catch (SocketTimeoutException ex)
    {
      return false;
    }
    catch (IOException ex) {}
    return true;
  }
  
  public HttpConnectionMetrics getMetrics()
  {
    return metrics;
  }
}

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

import java.io.IOException;
import org.apache.http.HttpConnectionMetrics;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestFactory;
import org.apache.http.HttpResponse;
import org.apache.http.HttpServerConnection;
import org.apache.http.StatusLine;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.impl.entity.DisallowIdentityContentLengthStrategy;
import org.apache.http.impl.entity.EntityDeserializer;
import org.apache.http.impl.entity.EntitySerializer;
import org.apache.http.impl.entity.LaxContentLengthStrategy;
import org.apache.http.impl.entity.StrictContentLengthStrategy;
import org.apache.http.impl.io.DefaultHttpRequestParser;
import org.apache.http.impl.io.HttpResponseWriter;
import org.apache.http.io.EofSensor;
import org.apache.http.io.HttpMessageParser;
import org.apache.http.io.HttpMessageWriter;
import org.apache.http.io.HttpTransportMetrics;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.io.SessionOutputBuffer;
import org.apache.http.params.HttpParams;
import org.apache.http.util.Args;

@Deprecated
@NotThreadSafe
public abstract class AbstractHttpServerConnection
  implements HttpServerConnection
{
  private final EntitySerializer entityserializer;
  private final EntityDeserializer entitydeserializer;
  private SessionInputBuffer inbuffer = null;
  private SessionOutputBuffer outbuffer = null;
  private EofSensor eofSensor = null;
  private HttpMessageParser<HttpRequest> requestParser = null;
  private HttpMessageWriter<HttpResponse> responseWriter = null;
  private HttpConnectionMetricsImpl metrics = null;
  
  public AbstractHttpServerConnection()
  {
    entityserializer = createEntitySerializer();
    entitydeserializer = createEntityDeserializer();
  }
  
  protected abstract void assertOpen()
    throws IllegalStateException;
  
  protected EntityDeserializer createEntityDeserializer()
  {
    return new EntityDeserializer(new DisallowIdentityContentLengthStrategy(new LaxContentLengthStrategy(0)));
  }
  
  protected EntitySerializer createEntitySerializer()
  {
    return new EntitySerializer(new StrictContentLengthStrategy());
  }
  
  protected HttpRequestFactory createHttpRequestFactory()
  {
    return DefaultHttpRequestFactory.INSTANCE;
  }
  
  protected HttpMessageParser<HttpRequest> createRequestParser(SessionInputBuffer buffer, HttpRequestFactory requestFactory, HttpParams params)
  {
    return new DefaultHttpRequestParser(buffer, null, requestFactory, params);
  }
  
  protected HttpMessageWriter<HttpResponse> createResponseWriter(SessionOutputBuffer buffer, HttpParams params)
  {
    return new HttpResponseWriter(buffer, null, params);
  }
  
  protected HttpConnectionMetricsImpl createConnectionMetrics(HttpTransportMetrics inTransportMetric, HttpTransportMetrics outTransportMetric)
  {
    return new HttpConnectionMetricsImpl(inTransportMetric, outTransportMetric);
  }
  
  protected void init(SessionInputBuffer inbuffer, SessionOutputBuffer outbuffer, HttpParams params)
  {
    this.inbuffer = ((SessionInputBuffer)Args.notNull(inbuffer, "Input session buffer"));
    this.outbuffer = ((SessionOutputBuffer)Args.notNull(outbuffer, "Output session buffer"));
    if ((inbuffer instanceof EofSensor)) {
      eofSensor = ((EofSensor)inbuffer);
    }
    requestParser = createRequestParser(inbuffer, createHttpRequestFactory(), params);
    
    responseWriter = createResponseWriter(outbuffer, params);
    
    metrics = createConnectionMetrics(inbuffer.getMetrics(), outbuffer.getMetrics());
  }
  
  public HttpRequest receiveRequestHeader()
    throws HttpException, IOException
  {
    assertOpen();
    HttpRequest request = (HttpRequest)requestParser.parse();
    metrics.incrementRequestCount();
    return request;
  }
  
  public void receiveRequestEntity(HttpEntityEnclosingRequest request)
    throws HttpException, IOException
  {
    Args.notNull(request, "HTTP request");
    assertOpen();
    HttpEntity entity = entitydeserializer.deserialize(inbuffer, request);
    request.setEntity(entity);
  }
  
  protected void doFlush()
    throws IOException
  {
    outbuffer.flush();
  }
  
  public void flush()
    throws IOException
  {
    assertOpen();
    doFlush();
  }
  
  public void sendResponseHeader(HttpResponse response)
    throws HttpException, IOException
  {
    Args.notNull(response, "HTTP response");
    assertOpen();
    responseWriter.write(response);
    if (response.getStatusLine().getStatusCode() >= 200) {
      metrics.incrementResponseCount();
    }
  }
  
  public void sendResponseEntity(HttpResponse response)
    throws HttpException, IOException
  {
    if (response.getEntity() == null) {
      return;
    }
    entityserializer.serialize(outbuffer, response, response.getEntity());
  }
  
  protected boolean isEof()
  {
    return (eofSensor != null) && (eofSensor.isEof());
  }
  
  public boolean isStale()
  {
    if (!isOpen()) {
      return true;
    }
    if (isEof()) {
      return true;
    }
    try
    {
      inbuffer.isDataAvailable(1);
      return isEof();
    }
    catch (IOException ex) {}
    return true;
  }
  
  public HttpConnectionMetrics getMetrics()
  {
    return metrics;
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import org.apache.http.Header;
import org.apache.http.HttpConnection;
import org.apache.http.HttpConnectionMetrics;
import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpInetConnection;
import org.apache.http.HttpMessage;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.entity.LaxContentLengthStrategy;
import org.apache.http.impl.entity.StrictContentLengthStrategy;
import org.apache.http.impl.io.ChunkedInputStream;
import org.apache.http.impl.io.ChunkedOutputStream;
import org.apache.http.impl.io.ContentLengthInputStream;
import org.apache.http.impl.io.ContentLengthOutputStream;
import org.apache.http.impl.io.HttpTransportMetricsImpl;
import org.apache.http.impl.io.IdentityInputStream;
import org.apache.http.impl.io.IdentityOutputStream;
import org.apache.http.impl.io.SessionInputBufferImpl;
import org.apache.http.impl.io.SessionOutputBufferImpl;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.io.SessionOutputBuffer;
import org.apache.http.util.Args;
import org.apache.http.util.Asserts;
import org.apache.http.util.NetUtils;

@NotThreadSafe
public class BHttpConnectionBase
  implements HttpConnection, HttpInetConnection
{
  private final SessionInputBufferImpl inbuffer;
  private final SessionOutputBufferImpl outbuffer;
  private final HttpConnectionMetricsImpl connMetrics;
  private final ContentLengthStrategy incomingContentStrategy;
  private final ContentLengthStrategy outgoingContentStrategy;
  private volatile boolean open;
  private volatile Socket socket;
  
  protected BHttpConnectionBase(int buffersize, int fragmentSizeHint, CharsetDecoder chardecoder, CharsetEncoder charencoder, MessageConstraints constraints, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy)
  {
    Args.positive(buffersize, "Buffer size");
    HttpTransportMetricsImpl inTransportMetrics = new HttpTransportMetricsImpl();
    HttpTransportMetricsImpl outTransportMetrics = new HttpTransportMetricsImpl();
    inbuffer = new SessionInputBufferImpl(inTransportMetrics, buffersize, -1, constraints != null ? constraints : MessageConstraints.DEFAULT, chardecoder);
    
    outbuffer = new SessionOutputBufferImpl(outTransportMetrics, buffersize, fragmentSizeHint, charencoder);
    
    connMetrics = new HttpConnectionMetricsImpl(inTransportMetrics, outTransportMetrics);
    this.incomingContentStrategy = (incomingContentStrategy != null ? incomingContentStrategy : LaxContentLengthStrategy.INSTANCE);
    
    this.outgoingContentStrategy = (outgoingContentStrategy != null ? outgoingContentStrategy : StrictContentLengthStrategy.INSTANCE);
  }
  
  protected void ensureOpen()
    throws IOException
  {
    Asserts.check(open, "Connection is not open");
    if (!inbuffer.isBound()) {
      inbuffer.bind(getSocketInputStream(socket));
    }
    if (!outbuffer.isBound()) {
      outbuffer.bind(getSocketOutputStream(socket));
    }
  }
  
  protected InputStream getSocketInputStream(Socket socket)
    throws IOException
  {
    return socket.getInputStream();
  }
  
  protected OutputStream getSocketOutputStream(Socket socket)
    throws IOException
  {
    return socket.getOutputStream();
  }
  
  protected void bind(Socket socket)
    throws IOException
  {
    Args.notNull(socket, "Socket");
    this.socket = socket;
    open = true;
    inbuffer.bind(null);
    outbuffer.bind(null);
  }
  
  protected SessionInputBuffer getSessionInputBuffer()
  {
    return inbuffer;
  }
  
  protected SessionOutputBuffer getSessionOutputBuffer()
  {
    return outbuffer;
  }
  
  protected void doFlush()
    throws IOException
  {
    outbuffer.flush();
  }
  
  public boolean isOpen()
  {
    return open;
  }
  
  protected Socket getSocket()
  {
    return socket;
  }
  
  protected OutputStream createOutputStream(long len, SessionOutputBuffer outbuffer)
  {
    if (len == -2L) {
      return new ChunkedOutputStream(2048, outbuffer);
    }
    if (len == -1L) {
      return new IdentityOutputStream(outbuffer);
    }
    return new ContentLengthOutputStream(outbuffer, len);
  }
  
  protected OutputStream prepareOutput(HttpMessage message)
    throws HttpException
  {
    long len = outgoingContentStrategy.determineLength(message);
    return createOutputStream(len, outbuffer);
  }
  
  protected InputStream createInputStream(long len, SessionInputBuffer inbuffer)
  {
    if (len == -2L) {
      return new ChunkedInputStream(inbuffer);
    }
    if (len == -1L) {
      return new IdentityInputStream(inbuffer);
    }
    return new ContentLengthInputStream(inbuffer, len);
  }
  
  protected HttpEntity prepareInput(HttpMessage message)
    throws HttpException
  {
    BasicHttpEntity entity = new BasicHttpEntity();
    
    long len = incomingContentStrategy.determineLength(message);
    InputStream instream = createInputStream(len, inbuffer);
    if (len == -2L)
    {
      entity.setChunked(true);
      entity.setContentLength(-1L);
      entity.setContent(instream);
    }
    else if (len == -1L)
    {
      entity.setChunked(false);
      entity.setContentLength(-1L);
      entity.setContent(instream);
    }
    else
    {
      entity.setChunked(false);
      entity.setContentLength(len);
      entity.setContent(instream);
    }
    Header contentTypeHeader = message.getFirstHeader("Content-Type");
    if (contentTypeHeader != null) {
      entity.setContentType(contentTypeHeader);
    }
    Header contentEncodingHeader = message.getFirstHeader("Content-Encoding");
    if (contentEncodingHeader != null) {
      entity.setContentEncoding(contentEncodingHeader);
    }
    return entity;
  }
  
  public InetAddress getLocalAddress()
  {
    if (socket != null) {
      return socket.getLocalAddress();
    }
    return null;
  }
  
  public int getLocalPort()
  {
    if (socket != null) {
      return socket.getLocalPort();
    }
    return -1;
  }
  
  public InetAddress getRemoteAddress()
  {
    if (socket != null) {
      return socket.getInetAddress();
    }
    return null;
  }
  
  public int getRemotePort()
  {
    if (socket != null) {
      return socket.getPort();
    }
    return -1;
  }
  
  public void setSocketTimeout(int timeout)
  {
    if (socket != null) {
      try
      {
        socket.setSoTimeout(timeout);
      }
      catch (SocketException ignore) {}
    }
  }
  
  public int getSocketTimeout()
  {
    if (socket != null) {
      try
      {
        return socket.getSoTimeout();
      }
      catch (SocketException ignore)
      {
        return -1;
      }
    }
    return -1;
  }
  
  public void shutdown()
    throws IOException
  {
    open = false;
    Socket tmpsocket = socket;
    if (tmpsocket != null) {
      tmpsocket.close();
    }
  }
  
  public void close()
    throws IOException
  {
    if (!open) {
      return;
    }
    open = false;
    Socket sock = socket;
    try
    {
      inbuffer.clear();
      outbuffer.flush();
      try
      {
        try {}catch (IOException ignore) {}
        try {}catch (IOException ignore) {}
      }
      catch (UnsupportedOperationException ignore) {}
    }
    finally
    {
      sock.close();
    }
  }
  
  private int fillInputBuffer(int timeout)
    throws IOException
  {
    int oldtimeout = socket.getSoTimeout();
    try
    {
      socket.setSoTimeout(timeout);
      return inbuffer.fillBuffer();
    }
    finally
    {
      socket.setSoTimeout(oldtimeout);
    }
  }
  
  protected boolean awaitInput(int timeout)
    throws IOException
  {
    if (inbuffer.hasBufferedData()) {
      return true;
    }
    fillInputBuffer(timeout);
    return inbuffer.hasBufferedData();
  }
  
  public boolean isStale()
  {
    if (!isOpen()) {
      return true;
    }
    try
    {
      int bytesRead = fillInputBuffer(1);
      return bytesRead < 0;
    }
    catch (SocketTimeoutException ex)
    {
      return false;
    }
    catch (IOException ex) {}
    return true;
  }
  
  protected void incrementRequestCount()
  {
    connMetrics.incrementRequestCount();
  }
  
  protected void incrementResponseCount()
  {
    connMetrics.incrementResponseCount();
  }
  
  public HttpConnectionMetrics getMetrics()
  {
    return connMetrics;
  }
  
  public String toString()
  {
    if (socket != null)
    {
      StringBuilder buffer = new StringBuilder();
      SocketAddress remoteAddress = socket.getRemoteSocketAddress();
      SocketAddress localAddress = socket.getLocalSocketAddress();
      if ((remoteAddress != null) && (localAddress != null))
      {
        NetUtils.formatAddress(buffer, localAddress);
        buffer.append("<->");
        NetUtils.formatAddress(buffer, remoteAddress);
      }
      return buffer.toString();
    }
    return "[Not bound]";
  }
}

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

import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import org.apache.http.config.ConnectionConfig;

public final class ConnSupport
{
  public static CharsetDecoder createDecoder(ConnectionConfig cconfig)
  {
    if (cconfig == null) {
      return null;
    }
    Charset charset = cconfig.getCharset();
    CodingErrorAction malformed = cconfig.getMalformedInputAction();
    CodingErrorAction unmappable = cconfig.getUnmappableInputAction();
    if (charset != null) {
      return charset.newDecoder().onMalformedInput(malformed != null ? malformed : CodingErrorAction.REPORT).onUnmappableCharacter(unmappable != null ? unmappable : CodingErrorAction.REPORT);
    }
    return null;
  }
  
  public static CharsetEncoder createEncoder(ConnectionConfig cconfig)
  {
    if (cconfig == null) {
      return null;
    }
    Charset charset = cconfig.getCharset();
    if (charset != null)
    {
      CodingErrorAction malformed = cconfig.getMalformedInputAction();
      CodingErrorAction unmappable = cconfig.getUnmappableInputAction();
      return charset.newEncoder().onMalformedInput(malformed != null ? malformed : CodingErrorAction.REPORT).onUnmappableCharacter(unmappable != null ? unmappable : CodingErrorAction.REPORT);
    }
    return null;
  }
}

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

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import org.apache.http.HttpClientConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory;
import org.apache.http.impl.io.DefaultHttpResponseParserFactory;
import org.apache.http.io.HttpMessageParser;
import org.apache.http.io.HttpMessageParserFactory;
import org.apache.http.io.HttpMessageWriter;
import org.apache.http.io.HttpMessageWriterFactory;
import org.apache.http.util.Args;

@NotThreadSafe
public class DefaultBHttpClientConnection
  extends BHttpConnectionBase
  implements HttpClientConnection
{
  private final HttpMessageParser<HttpResponse> responseParser;
  private final HttpMessageWriter<HttpRequest> requestWriter;
  
  public DefaultBHttpClientConnection(int buffersize, int fragmentSizeHint, CharsetDecoder chardecoder, CharsetEncoder charencoder, MessageConstraints constraints, ContentLengthStrategy incomingContentStrategy, ContentLengthStrategy outgoingContentStrategy, HttpMessageWriterFactory<HttpRequest> requestWriterFactory, HttpMessageParserFactory<HttpResponse> responseParserFactory)
  {
    super(buffersize, fragmentSizeHint, chardecoder, charencoder, constraints, incomingContentStrategy, outgoingContentStrategy);
    
    requestWriter = (requestWriterFactory != null ? requestWriterFactory : DefaultHttpRequestWriterFactory.INSTANCE).create(getSessionOutputBuffer());
    
    responseParser = (responseParserFactory != null ? responseParserFactory : DefaultHttpResponseParserFactory.INSTANCE).create(getSessionInputBuffer(), constraints);
  }
  
  public DefaultBHttpClientConnection(int buffersize, CharsetDecoder chardecoder, CharsetEncoder charencoder, MessageConstraints constraints)
  {
    this(buffersize, buffersize, chardecoder, charencoder, constraints, null, null, null, null);
  }
  
  public DefaultBHttpClientConnection(int buffersize)
  {
    this(buffersize, buffersize, null, null, null, null, null, null, null);
  }
  
  protected void onResponseReceived(HttpResponse response) {}
  
  protected void onRequestSubmitted(HttpRequest request) {}
  
  public void bind(Socket socket)
    throws IOException
  {
    super.bind(socket);
  }
  
  public boolean isResponseAvailable(int timeout)
    throws IOException
  {
    ensureOpen();
    try
    {
      return awaitInput(timeout);
    }
    catch (SocketTimeoutException ex) {}
    return false;
  }
  
  public void sendRequestHeader(HttpRequest request)
    throws HttpException, IOException
  {
    Args.notNull(request, "HTTP request");
    ensureOpen();
    requestWriter.write(request);
    onRequestSubmitted(request);
    incrementRequestCount();
  }
  
  public void sendRequestEntity(HttpEntityEnclosingRequest request)
    throws HttpException, IOException
  {
    Args.notNull(request, "HTTP request");
    ensureOpen();
    HttpEntity entity = request.getEntity();
    if (entity == null) {
      return;
    }
    OutputStream outstream = prepareOutput(request);
    entity.writeTo(outstream);
    outstream.close();
  }
  
  public HttpResponse receiveResponseHeader()
    throws HttpException, IOException
  {
    ensureOpen();
    HttpResponse response = (HttpResponse)responseParser.parse();
    onResponseReceived(response);
    if (response.getStatusLine().getStatusCode() >= 200) {
      incrementResponseCount();
    }
    return response;
  }
  
  public void receiveResponseEntity(HttpResponse response)
    thr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

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-2019. Infinite Loop Ltd