package com.ikea.shared.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;

public class CustomStream extends InputStream
{
  private static final int DEFAULT_BUFFER_SIZE = 512;
  private int[] mDataBuffer;
  private InputStream mIs;
  private int mReadIndex;
  private int mSkipAtEnd;
  private int mSkipAtStart;
  private boolean mStreamEnded;
  private int mWriteIndex;

  public CustomStream(InputStream paramInputStream)
  {
    this(paramInputStream, 0);
  }

  public CustomStream(InputStream paramInputStream, int paramInt)
  {
    this(paramInputStream, paramInt, 0);
  }

  public CustomStream(InputStream paramInputStream, int paramInt1, int paramInt2)
  {
    this(paramInputStream, paramInt1, paramInt2, 512);
  }

  public CustomStream(InputStream paramInputStream, int paramInt1, int paramInt2, int paramInt3)
  {
    this.mIs = paramInputStream;
    this.mSkipAtEnd = paramInt2;
    this.mSkipAtStart = paramInt1;
    this.mDataBuffer = new int[paramInt3];
  }

  private void fillBuffer()
  {
    if (this.mStreamEnded);
    int i;
    do
    {
      return;
      try
      {
        while (this.mSkipAtStart > 0)
        {
          int j = this.mIs.read();
          if (j == -1)
            break;
          this.mSkipAtStart = (-1 + this.mSkipAtStart);
          System.out.println("skipping " + (char)j);
        }
      }
      catch (IOException localIOException)
      {
        localIOException.printStackTrace();
        return;
      }
      if (this.mReadIndex == this.mWriteIndex)
      {
        this.mWriteIndex = 0;
        this.mReadIndex = 0;
      }
      while (true)
      {
        i = this.mIs.read();
        if ((i == -1) || (this.mWriteIndex >= this.mDataBuffer.length))
          break;
        this.mDataBuffer[this.mWriteIndex] = i;
        this.mWriteIndex = (1 + this.mWriteIndex);
      }
    }
    while (i != -1);
    this.mStreamEnded = true;
  }

  public void close()
    throws IOException
  {
    this.mIs.close();
  }

  public int read()
    throws IOException
  {
    int i = -1;
    if (this.mWriteIndex - this.mReadIndex > this.mSkipAtEnd)
    {
      int k = this.mDataBuffer[this.mReadIndex];
      this.mReadIndex = (1 + this.mReadIndex);
      i = k;
    }
    do
    {
      return i;
      fillBuffer();
      if (this.mWriteIndex - this.mReadIndex > this.mSkipAtEnd)
      {
        int j = this.mDataBuffer[this.mReadIndex];
        this.mReadIndex = (1 + this.mReadIndex);
        return j;
      }
    }
    while ((this.mWriteIndex - this.mReadIndex != this.mSkipAtEnd) || (!this.mStreamEnded));
    return i;
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.ikea.shared.util.CustomStream
 * JD-Core Version:    0.6.2
 */