package com.worklight.location.internal.events.nativeImpl;

import com.worklight.location.internal.events.storage.Chunk;
import com.worklight.location.internal.events.storage.ChunkStringFactory;
import com.worklight.location.internal.events.storage.IChunkStorage;
import java.io.File;

public class FileChunkStorage
  implements IChunkStorage
{
  private static final String FILE_PREFIX = "ChunkFile";
  private static final String UTF8 = "UTF-8";
  private long currentIndex = 0L;
  private final ChunkStringFactory factory;
  private long startIndex = 0L;
  private final File workingDir;

  public FileChunkStorage(File paramFile, ChunkStringFactory paramChunkStringFactory)
  {
    if ((!paramFile.exists()) || (!paramFile.isDirectory()))
      throw new IllegalArgumentException("workingDir is not an existing directory");
    this.workingDir = paramFile;
    if (paramChunkStringFactory == null)
      throw new IllegalArgumentException("factory is null");
    this.factory = paramChunkStringFactory;
  }

  private File getFileForIndex(long paramLong)
  {
    return new File(this.workingDir, "ChunkFile" + paramLong);
  }

  // ERROR //
  private Chunk loadChunk(long paramLong)
    throws AssertionError
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 81	com/worklight/location/internal/events/nativeImpl/FileChunkStorage:isEmpty	()Z
    //   4: ifeq +9 -> 13
    //   7: aconst_null
    //   8: astore 10
    //   10: aload 10
    //   12: areturn
    //   13: aconst_null
    //   14: astore_3
    //   15: new 83	java/util/Scanner
    //   18: dup
    //   19: aload_0
    //   20: lload_1
    //   21: invokespecial 85	com/worklight/location/internal/events/nativeImpl/FileChunkStorage:getFileForIndex	(J)Ljava/io/File;
    //   24: ldc 13
    //   26: invokespecial 86	java/util/Scanner:<init>	(Ljava/io/File;Ljava/lang/String;)V
    //   29: astore 4
    //   31: aload 4
    //   33: ldc 88
    //   35: invokevirtual 92	java/util/Scanner:useDelimiter	(Ljava/lang/String;)Ljava/util/Scanner;
    //   38: pop
    //   39: aload_0
    //   40: getfield 51	com/worklight/location/internal/events/nativeImpl/FileChunkStorage:factory	Lcom/worklight/location/internal/events/storage/ChunkStringFactory;
    //   43: aload 4
    //   45: invokevirtual 95	java/util/Scanner:next	()Ljava/lang/String;
    //   48: invokevirtual 101	com/worklight/location/internal/events/storage/ChunkStringFactory:createChunk	(Ljava/lang/String;)Lcom/worklight/location/internal/events/storage/Chunk;
    //   51: astore 9
    //   53: aload 9
    //   55: astore 10
    //   57: aload 4
    //   59: ifnull -49 -> 10
    //   62: aload 4
    //   64: invokevirtual 104	java/util/Scanner:close	()V
    //   67: aload 10
    //   69: areturn
    //   70: astore 5
    //   72: new 74	java/lang/AssertionError
    //   75: dup
    //   76: aload 5
    //   78: invokespecial 107	java/lang/AssertionError:<init>	(Ljava/lang/Object;)V
    //   81: athrow
    //   82: astore 6
    //   84: aload_3
    //   85: ifnull +7 -> 92
    //   88: aload_3
    //   89: invokevirtual 104	java/util/Scanner:close	()V
    //   92: aload 6
    //   94: athrow
    //   95: astore 7
    //   97: new 74	java/lang/AssertionError
    //   100: dup
    //   101: aload 7
    //   103: invokespecial 107	java/lang/AssertionError:<init>	(Ljava/lang/Object;)V
    //   106: athrow
    //   107: astore 6
    //   109: aload 4
    //   111: astore_3
    //   112: goto -28 -> 84
    //   115: astore 7
    //   117: aload 4
    //   119: astore_3
    //   120: goto -23 -> 97
    //   123: astore 5
    //   125: aload 4
    //   127: astore_3
    //   128: goto -56 -> 72
    //
    // Exception table:
    //   from	to	target	type
    //   15	31	70	java/io/IOException
    //   15	31	82	finally
    //   72	82	82	finally
    //   97	107	82	finally
    //   15	31	95	org/json/JSONException
    //   31	53	107	finally
    //   31	53	115	org/json/JSONException
    //   31	53	123	java/io/IOException
  }

  public Chunk forTestOnly_loadChunk(int paramInt)
  {
    return getChunk(paramInt - this.startIndex);
  }

  public Chunk getChunk(long paramLong)
  {
    try
    {
      Chunk localChunk = loadChunk(paramLong + this.startIndex);
      return localChunk;
    }
    catch (AssertionError localAssertionError)
    {
    }
    return null;
  }

  public Chunk getFirst()
  {
    return loadChunk(this.startIndex);
  }

  public long getNumChunks()
  {
    return this.currentIndex - this.startIndex;
  }

  public long getNumChunksPersisted()
  {
    return getNumChunks();
  }

  public boolean isEmpty()
  {
    return getNumChunks() == 0L;
  }

  public void purgeAll()
  {
    while (!isEmpty())
      removeFirst();
  }

  public void removeFirst()
  {
    if (isEmpty())
      return;
    getFileForIndex(this.startIndex).delete();
    this.startIndex = (1L + this.startIndex);
  }

  public void setMaxmiumMemorySize(long paramLong)
  {
    throw new UnsupportedOperationException();
  }

  // ERROR //
  public void store(Chunk paramChunk)
  {
    // Byte code:
    //   0: aconst_null
    //   1: astore_2
    //   2: aload_0
    //   3: getfield 29	com/worklight/location/internal/events/nativeImpl/FileChunkStorage:currentIndex	J
    //   6: lstore 6
    //   8: aload_0
    //   9: lconst_1
    //   10: lload 6
    //   12: ladd
    //   13: putfield 29	com/worklight/location/internal/events/nativeImpl/FileChunkStorage:currentIndex	J
    //   16: aload_0
    //   17: lload 6
    //   19: invokespecial 85	com/worklight/location/internal/events/nativeImpl/FileChunkStorage:getFileForIndex	(J)Ljava/io/File;
    //   22: astore 8
    //   24: aload 8
    //   26: invokevirtual 138	java/io/File:createNewFile	()Z
    //   29: pop
    //   30: new 140	java/io/FileOutputStream
    //   33: dup
    //   34: aload 8
    //   36: invokespecial 143	java/io/FileOutputStream:<init>	(Ljava/io/File;)V
    //   39: astore 10
    //   41: aload 10
    //   43: aload_0
    //   44: getfield 51	com/worklight/location/internal/events/nativeImpl/FileChunkStorage:factory	Lcom/worklight/location/internal/events/storage/ChunkStringFactory;
    //   47: aload_1
    //   48: invokevirtual 147	com/worklight/location/internal/events/storage/ChunkStringFactory:createString	(Lcom/worklight/location/internal/events/storage/Chunk;)Ljava/lang/String;
    //   51: ldc 13
    //   53: invokevirtual 153	java/lang/String:getBytes	(Ljava/lang/String;)[B
    //   56: invokevirtual 157	java/io/FileOutputStream:write	([B)V
    //   59: aload 10
    //   61: invokevirtual 158	java/io/FileOutputStream:close	()V
    //   64: aload 10
    //   66: ifnull +8 -> 74
    //   69: aload 10
    //   71: invokevirtual 158	java/io/FileOutputStream:close	()V
    //   74: return
    //   75: astore 11
    //   77: new 74	java/lang/AssertionError
    //   80: dup
    //   81: aload 11
    //   83: invokespecial 107	java/lang/AssertionError:<init>	(Ljava/lang/Object;)V
    //   86: athrow
    //   87: astore 5
    //   89: new 74	java/lang/AssertionError
    //   92: dup
    //   93: aload 5
    //   95: invokespecial 107	java/lang/AssertionError:<init>	(Ljava/lang/Object;)V
    //   98: athrow
    //   99: astore_3
    //   100: aload_2
    //   101: ifnull +7 -> 108
    //   104: aload_2
    //   105: invokevirtual 158	java/io/FileOutputStream:close	()V
    //   108: aload_3
    //   109: athrow
    //   110: astore 4
    //   112: new 74	java/lang/AssertionError
    //   115: dup
    //   116: aload 4
    //   118: invokespecial 107	java/lang/AssertionError:<init>	(Ljava/lang/Object;)V
    //   121: athrow
    //   122: astore_3
    //   123: aload 10
    //   125: astore_2
    //   126: goto -26 -> 100
    //   129: astore 5
    //   131: aload 10
    //   133: astore_2
    //   134: goto -45 -> 89
    //
    // Exception table:
    //   from	to	target	type
    //   69	74	75	java/io/IOException
    //   2	41	87	java/io/IOException
    //   2	41	99	finally
    //   89	99	99	finally
    //   104	108	110	java/io/IOException
    //   41	64	122	finally
    //   41	64	129	java/io/IOException
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.worklight.location.internal.events.nativeImpl.FileChunkStorage
 * JD-Core Version:    0.6.2
 */