GzipSource.java 4.02 KB
package okio;

import java.io.EOFException;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.Inflater;
import tx;

public final class GzipSource
  implements Source
{
  private int a = 0;
  private final BufferedSource b;
  private final Inflater c;
  private final InflaterSource d;
  private final CRC32 e = new CRC32();
  
  public GzipSource(Source paramSource)
  {
    if (paramSource == null) {
      throw new IllegalArgumentException("source == null");
    }
    this.c = new Inflater(true);
    this.b = Okio.buffer(paramSource);
    this.d = new InflaterSource(this.b, this.c);
  }
  
  private static void a(String paramString, int paramInt1, int paramInt2)
    throws IOException
  {
    if (paramInt2 != paramInt1) {
      throw new IOException(String.format("%s: actual 0x%08x != expected 0x%08x", new Object[] { paramString, Integer.valueOf(paramInt2), Integer.valueOf(paramInt1) }));
    }
  }
  
  private void a(Buffer paramBuffer, long paramLong1, long paramLong2)
  {
    Object localObject;
    long l1;
    long l2;
    for (paramBuffer = paramBuffer.a;; paramBuffer = paramBuffer.f)
    {
      localObject = paramBuffer;
      l1 = paramLong1;
      l2 = paramLong2;
      if (paramLong1 < paramBuffer.c - paramBuffer.b) {
        break;
      }
      paramLong1 -= paramBuffer.c - paramBuffer.b;
    }
    while (l2 > 0L)
    {
      int i = (int)(((tx)localObject).b + l1);
      int j = (int)Math.min(((tx)localObject).c - i, l2);
      this.e.update(((tx)localObject).a, i, j);
      l2 -= j;
      localObject = ((tx)localObject).f;
      l1 = 0L;
    }
  }
  
  public final void close()
    throws IOException
  {
    this.d.close();
  }
  
  public final long read(Buffer paramBuffer, long paramLong)
    throws IOException
  {
    if (paramLong < 0L) {
      throw new IllegalArgumentException("byteCount < 0: " + paramLong);
    }
    if (paramLong == 0L) {
      return 0L;
    }
    long l;
    if (this.a == 0)
    {
      this.b.require(10L);
      int j = this.b.buffer().getByte(3L);
      if ((j >> 1 & 0x1) == 1) {}
      for (int i = 1;; i = 0)
      {
        if (i != 0) {
          a(this.b.buffer(), 0L, 10L);
        }
        a("ID1ID2", 8075, this.b.readShort());
        this.b.skip(8L);
        if ((j >> 2 & 0x1) == 1)
        {
          this.b.require(2L);
          if (i != 0) {
            a(this.b.buffer(), 0L, 2L);
          }
          int k = this.b.buffer().readShortLe();
          this.b.require(k);
          if (i != 0) {
            a(this.b.buffer(), 0L, k);
          }
          this.b.skip(k);
        }
        if ((j >> 3 & 0x1) != 1) {
          break label323;
        }
        l = this.b.indexOf((byte)0);
        if (l != -1L) {
          break;
        }
        throw new EOFException();
      }
      if (i != 0) {
        a(this.b.buffer(), 0L, 1L + l);
      }
      this.b.skip(1L + l);
      label323:
      if ((j >> 4 & 0x1) == 1)
      {
        l = this.b.indexOf((byte)0);
        if (l == -1L) {
          throw new EOFException();
        }
        if (i != 0) {
          a(this.b.buffer(), 0L, 1L + l);
        }
        this.b.skip(1L + l);
      }
      if (i != 0)
      {
        a("FHCRC", this.b.readShortLe(), (short)(int)this.e.getValue());
        this.e.reset();
      }
      this.a = 1;
    }
    if (this.a == 1)
    {
      l = paramBuffer.b;
      paramLong = this.d.read(paramBuffer, paramLong);
      if (paramLong != -1L)
      {
        a(paramBuffer, l, paramLong);
        return paramLong;
      }
      this.a = 2;
    }
    if (this.a == 2)
    {
      a("CRC", this.b.readIntLe(), (int)this.e.getValue());
      a("ISIZE", this.b.readIntLe(), this.c.getTotalOut());
      this.a = 3;
      if (!this.b.exhausted()) {
        throw new IOException("gzip finished without exhausting source");
      }
    }
    return -1L;
  }
  
  public final Timeout timeout()
  {
    return this.b.timeout();
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/okio/GzipSource.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */