org.eclipse.osgi_3.7.2.v20120110-1415

: new 292	org/eclipse/osgi/storagemanager/StorageManager$Entry
    //   78: dup
    //   79: aload_0
    //   80: iconst_0
    //   81: iconst_1
    //   82: iload_2
    //   83: invokespecial 619	org/eclipse/osgi/storagemanager/StorageManager$Entry:<init>	(Lorg/eclipse/osgi/storagemanager/StorageManager;III)V
    //   86: astore_3
    //   87: aload_0
    //   88: getfield 513	org/eclipse/osgi/storagemanager/StorageManager:table	Ljava/util/Properties;
    //   91: aload_1
    //   92: aload_3
    //   93: invokevirtual 570	java/util/Properties:put	(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    //   96: pop
    //   97: aload_0
    //   98: aload_1
    //   99: invokespecial 599	org/eclipse/osgi/storagemanager/StorageManager:findOldestGeneration	(Ljava/lang/String;)I
    //   102: istore 4
    //   104: iload 4
    //   106: ifeq +11 -> 117
    //   109: aload_3
    //   110: iload 4
    //   112: iconst_1
    //   113: iadd
    //   114: invokevirtual 618	org/eclipse/osgi/storagemanager/StorageManager$Entry:setWriteId	(I)V
    //   117: aload_0
    //   118: invokespecial 594	org/eclipse/osgi/storagemanager/StorageManager:save	()V
    //   121: goto +36 -> 157
    //   124: aload_3
    //   125: invokevirtual 613	org/eclipse/osgi/storagemanager/StorageManager$Entry:getFileType	()I
    //   128: iload_2
    //   129: if_icmpeq +28 -> 157
    //   132: aload_3
    //   133: iload_2
    //   134: invokevirtual 616	org/eclipse/osgi/storagemanager/StorageManager$Entry:setFileType	(I)V
    //   137: aload_0
    //   138: invokespecial 595	org/eclipse/osgi/storagemanager/StorageManager:updateTable	()V
    //   141: aload_0
    //   142: invokespecial 594	org/eclipse/osgi/storagemanager/StorageManager:save	()V
    //   145: goto +12 -> 157
    //   148: astore 5
    //   150: aload_0
    //   151: invokespecial 593	org/eclipse/osgi/storagemanager/StorageManager:release	()V
    //   154: aload 5
    //   156: athrow
    //   157: aload_0
    //   158: invokespecial 593	org/eclipse/osgi/storagemanager/StorageManager:release	()V
    //   161: return
    // Line number table:
    //   Java source line #216	-> byte code offset #0
    //   Java source line #217	-> byte code offset #7
    //   Java source line #218	-> byte code offset #18
    //   Java source line #219	-> byte code offset #25
    //   Java source line #220	-> byte code offset #36
    //   Java source line #221	-> byte code offset #44
    //   Java source line #223	-> byte code offset #55
    //   Java source line #224	-> byte code offset #59
    //   Java source line #225	-> byte code offset #71
    //   Java source line #226	-> byte code offset #75
    //   Java source line #227	-> byte code offset #87
    //   Java source line #231	-> byte code offset #97
    //   Java source line #232	-> byte code offset #104
    //   Java source line #233	-> byte code offset #109
    //   Java source line #234	-> byte code offset #117
    //   Java source line #236	-> byte code offset #124
    //   Java source line #237	-> byte code offset #132
    //   Java source line #238	-> byte code offset #137
    //   Java source line #239	-> byte code offset #141
    //   Java source line #242	-> byte code offset #148
    //   Java source line #243	-> byte code offset #150
    //   Java source line #244	-> byte code offset #154
    //   Java source line #243	-> byte code offset #157
    //   Java source line #245	-> byte code offset #161
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	162	0	this	StorageManager
    //   0	162	1	managedFile	String
    //   0	162	2	fileType	int
    //   70	63	3	entry	Entry
    //   102	9	4	oldestGeneration	int
    //   148	7	5	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   55	148	148	finally
  }
  
  private int findOldestGeneration(String managedFile)
  {
    String[] files = base.list();
    int oldestGeneration = 0;
    if (files != null)
    {
      String name = managedFile + '.';
      int len = name.length();
      for (int i = 0; i < files.length; i++) {
        if (files[i].startsWith(name)) {
          try
          {
            int generation = Integer.parseInt(files[i].substring(len));
            if (generation > oldestGeneration) {
              oldestGeneration = generation;
            }
          }
          catch (NumberFormatException localNumberFormatException) {}
        }
      }
    }
    return oldestGeneration;
  }
  
  /* Error */
  public void update(String[] managedFiles, String[] sources)
    throws IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 501	org/eclipse/osgi/storagemanager/StorageManager:open	Z
    //   4: ifne +14 -> 18
    //   7: new 261	java/io/IOException
    //   10: dup
    //   11: getstatic 498	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:fileManager_notOpen	Ljava/lang/String;
    //   14: invokespecial 533	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   17: athrow
    //   18: aload_0
    //   19: getfield 503	org/eclipse/osgi/storagemanager/StorageManager:readOnly	Z
    //   22: ifeq +14 -> 36
    //   25: new 261	java/io/IOException
    //   28: dup
    //   29: getstatic 497	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:fileManager_illegalInReadOnlyMode	Ljava/lang/String;
    //   32: invokespecial 533	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   35: athrow
    //   36: aload_0
    //   37: iconst_1
    //   38: invokespecial 597	org/eclipse/osgi/storagemanager/StorageManager:lock	(Z)Z
    //   41: ifne +14 -> 55
    //   44: new 261	java/io/IOException
    //   47: dup
    //   48: getstatic 496	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:fileManager_cannotLock	Ljava/lang/String;
    //   51: invokespecial 533	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   54: athrow
    //   55: aload_0
    //   56: invokespecial 595	org/eclipse/osgi/storagemanager/StorageManager:updateTable	()V
    //   59: aload_1
    //   60: arraylength
    //   61: newarray <illegal type>
    //   63: astore_3
    //   64: iconst_0
    //   65: istore 4
    //   67: iconst_0
    //   68: istore 5
    //   70: goto +36 -> 106
    //   73: aload_3
    //   74: iload 5
    //   76: aload_0
    //   77: aload_1
    //   78: iload 5
    //   80: aaload
    //   81: invokevirtual 600	org/eclipse/osgi/storagemanager/StorageManager:getId	(Ljava/lang/String;)I
    //   84: iastore
    //   85: aload_0
    //   86: aload_1
    //   87: iload 5
    //   89: aaload
    //   90: aload_2
    //   91: iload 5
    //   93: aaload
    //   94: invokespecial 610	org/eclipse/osgi/storagemanager/StorageManager:update	(Ljava/lang/String;Ljava/lang/String;)Z
    //   97: ifne +6 -> 103
    //   100: iconst_1
    //   101: istore 4
    //   103: iinc 5 1
    //   106: iload 5
    //   108: aload_1
    //   109: arraylength
    //   110: if_icmplt -37 -> 73
    //   113: iload 4
    //   115: ifeq +55 -> 170
    //   118: iconst_0
    //   119: istore 5
    //   121: goto +31 -> 152
    //   124: aload_0
    //   125: getfield 513	org/eclipse/osgi/storagemanager/StorageManager:table	Ljava/util/Properties;
    //   128: aload_1
    //   129: iload 5
    //   131: aaload
    //   132: invokevirtual 566	java/util/Properties:get	(Ljava/lang/Object;)Ljava/lang/Object;
    //   135: checkcast 292	org/eclipse/osgi/storagemanager/StorageManager$Entry
    //   138: astore 6
    //   140: aload 6
    //   142: aload_3
    //   143: iload 5
    //   145: iaload
    //   146: invokevirtual 617	org/eclipse/osgi/storagemanager/StorageManager$Entry:setReadId	(I)V
    //   149: iinc 5 1
    //   152: iload 5
    //   154: aload_1
    //   155: arraylength
    //   156: if_icmplt -32 -> 124
    //   159: new 261	java/io/IOException
    //   162: dup
    //   163: getstatic 499	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:fileManager_updateFailed	Ljava/lang/String;
    //   166: invokespecial 533	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   169: athrow
    //   170: aload_0
    //   171: invokespecial 594	org/eclipse/osgi/storagemanager/StorageManager:save	()V
    //   174: goto +12 -> 186
    //   177: astore 7
    //   179: aload_0
    //   180: invokespecial 593	org/eclipse/osgi/storagemanager/StorageManager:release	()V
    //   183: aload 7
    //   185: athrow
    //   186: aload_0
    //   187: invokespecial 593	org/eclipse/osgi/storagemanager/StorageManager:release	()V
    //   190: return
    // Line number table:
    //   Java source line #287	-> byte code offset #0
    //   Java source line #288	-> byte code offset #7
    //   Java source line #289	-> byte code offset #18
    //   Java source line #290	-> byte code offset #25
    //   Java source line #291	-> byte code offset #36
    //   Java source line #292	-> byte code offset #44
    //   Java source line #294	-> byte code offset #55
    //   Java source line #295	-> byte code offset #59
    //   Java source line #296	-> byte code offset #64
    //   Java source line #297	-> byte code offset #67
    //   Java source line #298	-> byte code offset #73
    //   Java source line #299	-> byte code offset #85
    //   Java source line #300	-> byte code offset #100
    //   Java source line #297	-> byte code offset #103
    //   Java source line #302	-> byte code offset #113
    //   Java source line #304	-> byte code offset #118
    //   Java source line #305	-> byte code offset #124
    //   Java source line #306	-> byte code offset #140
    //   Java source line #304	-> byte code offset #149
    //   Java source line #308	-> byte code offset #159
    //   Java source line #310	-> byte code offset #170
    //   Java source line #311	-> byte code offset #177
    //   Java source line #312	-> byte code offset #179
    //   Java source line #313	-> byte code offset #183
    //   Java source line #312	-> byte code offset #186
    //   Java source line #314	-> byte code offset #190
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	191	0	this	StorageManager
    //   0	191	1	managedFiles	String[]
    //   0	191	2	sources	String[]
    //   63	80	3	originalReadIDs	int[]
    //   65	49	4	error	boolean
    //   68	39	5	i	int
    //   119	34	5	i	int
    //   138	3	6	entry	Entry
    //   177	7	7	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   55	177	177	finally
  }
  
  public String[] getManagedFiles()
  {
    if (!open) {
      return null;
    }
    Set<Object> set = table.keySet();
    
    String[] keys = (String[])set.toArray(new String[set.size()]);
    String[] result = new String[keys.length];
    for (int i = 0; i < keys.length; i++) {
      result[i] = new String(keys[i]);
    }
    return result;
  }
  
  public File getBase()
  {
    return base;
  }
  
  public int getId(String managedFile)
  {
    if (!open) {
      return -1;
    }
    Entry entry = (Entry)table.get(managedFile);
    if (entry == null) {
      return -1;
    }
    return entry.getReadId();
  }
  
  public boolean isReadOnly()
  {
    return readOnly;
  }
  
  private boolean lock(boolean wait)
    throws IOException
  {
    if (readOnly) {
      return false;
    }
    if (locker == null)
    {
      locker = BasicLocation.createLocker(lockFile, lockMode);
      if (locker == null) {
        throw new IOException(EclipseAdaptorMsg.fileManager_cannotLock);
      }
    }
    boolean locked = locker.lock();
    if ((locked) || (!wait)) {
      return locked;
    }
    long start = System.currentTimeMillis();
    long time;
    do
    {
      try
      {
        Thread.sleep(200L);
      }
      catch (InterruptedException localInterruptedException) {}
      locked = locker.lock();
      if (locked) {
        return true;
      }
      time = System.currentTimeMillis() - start;
    } while (time <= 5000L);
    return false;
  }
  
  public File lookup(String managedFile, boolean add)
    throws IOException
  {
    if (!open) {
      throw new IOException(EclipseAdaptorMsg.fileManager_notOpen);
    }
    Entry entry = (Entry)table.get(managedFile);
    if (entry == null) {
      if (add)
      {
        add(managedFile);
        entry = (Entry)table.get(managedFile);
      }
      else
      {
        return null;
      }
    }
    return new File(getAbsolutePath(managedFile + '.' + entry.getReadId()));
  }
  
  private boolean move(String source, String managedFile)
  {
    File original = new File(source);
    File targetFile = new File(managedFile);
    if ((!original.exists()) || (targetFile.exists())) {
      return false;
    }
    return original.renameTo(targetFile);
  }
  
  private void release()
  {
    if (locker == null) {
      return;
    }
    locker.release();
  }
  
  /* Error */
  public void remove(String managedFile)
    throws IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 501	org/eclipse/osgi/storagemanager/StorageManager:open	Z
    //   4: ifne +14 -> 18
    //   7: new 261	java/io/IOException
    //   10: dup
    //   11: getstatic 498	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:fileManager_notOpen	Ljava/lang/String;
    //   14: invokespecial 533	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   17: athrow
    //   18: aload_0
    //   19: getfield 503	org/eclipse/osgi/storagemanager/StorageManager:readOnly	Z
    //   22: ifeq +14 -> 36
    //   25: new 261	java/io/IOException
    //   28: dup
    //   29: getstatic 497	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:fileManager_illegalInReadOnlyMode	Ljava/lang/String;
    //   32: invokespecial 533	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   35: athrow
    //   36: aload_0
    //   37: iconst_1
    //   38: invokespecial 597	org/eclipse/osgi/storagemanager/StorageManager:lock	(Z)Z
    //   41: ifne +14 -> 55
    //   44: new 261	java/io/IOException
    //   47: dup
    //   48: getstatic 496	org/eclipse/core/runtime/internal/adaptor/EclipseAdaptorMsg:fileManager_cannotLock	Ljava/lang/String;
    //   51: invokespecial 533	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   54: athrow
    //   55: aload_0
    //   56: invokespecial 595	org/eclipse/osgi/storagemanager/StorageManager:updateTable	()V
    //   59: aload_0
    //   60: getfield 513	org/eclipse/osgi/storagemanager/StorageManager:table	Ljava/util/Properties;
    //   63: aload_1
    //   64: invokevirtual 567	java/util/Properties:remove	(Ljava/lang/Object;)Ljava/lang/Object;
    //   67: pop
    //   68: aload_0
    //   69: invokespecial 594	org/eclipse/osgi/storagemanager/StorageManager:save	()V
    //   72: goto +10 -> 82
    //   75: astore_2
    //   76: aload_0
    //   77: invokespecial 593	org/eclipse/osgi/storagemanager/StorageManager:release	()V
    //   80: aload_2
    //   81: athrow
    //   82: aload_0
    //   83: invokespecial 593	org/eclipse/osgi/storagemanager/StorageManager:release	()V
    //   86: return
    // Line number table:
    //   Java source line #465	-> byte code offset #0
    //   Java source line #466	-> byte code offset #7
    //   Java source line #467	-> byte code offset #18
    //   Java source line #468	-> byte code offset #25
    //   Java source line #471	-> byte code offset #36
    //   Java source line #472	-> byte code offset #44
    //   Java source line #474	-> byte code offset #55
    //   Java source line #475	-> byte code offset #59
    //   Java source line #476	-> byte code offset #68
    //   Java source line #477	-> byte code offset #75
    //   Java source line #478	-> byte code offset #76
    //   Java source line #479	-> byte code offset #80
    //   Java source line #478	-> byte code offset #82
    //   Java source line #480	-> byte code offset #86
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	87	0	this	StorageManager
    //   0	87	1	managedFile	String
    //   75	6	2	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   55	75	75	finally
  }
  
  /* Error */
  private void updateTable()
    throws IOException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 511	org/eclipse/osgi/storagemanager/StorageManager:tableFile	Ljava/io/File;
    //   4: invokestatic 572	org/eclipse/osgi/framework/internal/reliablefile/ReliableFile:lastModifiedVersion	(Ljava/io/File;)I
    //   7: istore_1
    //   8: iload_1
    //   9: aload_0
    //   10: getfield 500	org/eclipse/osgi/storagemanager/StorageManager:tableStamp	I
    //   13: if_icmpeq +8 -> 21
    //   16: iload_1
    //   17: iconst_m1
    //   18: if_icmpne +4 -> 22
    //   21: return
    //   22: new 281	java/util/Properties
    //   25: dup
    //   26: invokespecial 561	java/util/Properties:<init>	()V
    //   29: astore_2
    //   30: new 287	org/eclipse/osgi/framework/internal/reliablefile/ReliableFileInputStream
    //   33: dup
    //   34: aload_0
    //   35: getfield 511	org/eclipse/osgi/storagemanager/StorageManager:tableFile	Ljava/io/File;
    //   38: invokespecial 575	org/eclipse/osgi/framework/internal/reliablefile/ReliableFileInputStream:<init>	(Ljava/io/File;)V
    //   41: astore_3
    //   42: aload_2
    //   43: aload_3
    //   44: invokevirtual 562	java/util/Properties:load	(Ljava/io/InputStream;)V
    //   47: goto +16 -> 63
    //   50: astore 4
    //   52: aload_3
    //   53: invokevirtual 534	java/io/InputStream:close	()V
    //   56: goto +4 -> 60
    //   59: pop
    //   60: aload 4
    //   62: athrow
    //   63: aload_3
    //   64: invokevirtual 534	java/io/InputStream:close	()V
    //   67: goto +4 -> 71
    //   70: pop
    //   71: aload_0
    //   72: iload_1
    //   73: putfield 500	org/eclipse/osgi/storagemanager/StorageManager:tableStamp	I
    //   76: aload_2
    //   77: invokevirtual 563	java/util/Properties:keys	()Ljava/util/Enumeration;
    //   80: astore 4
    //   82: goto +140 -> 222
    //   85: aload 4
    //   87: invokeinterface 622 1 0
    //   92: checkcast 271	java/lang/String
    //   95: astore 5
    //   97: aload_2
    //   98: aload 5
    //   100: invokevirtual 569	java/util/Properties:getProperty	(Ljava/lang/String;)Ljava/lang/String;
    //   103: astore 6
    //   105: aload 6
    //   107: ifnull +115 -> 222
    //   110: aload_0
    //   111: getfield 513	org/eclipse/osgi/storagemanager/StorageManager:table	Ljava/util/Properties;
    //   114: aload 5
    //   116: invokevirtual 566	java/util/Properties:get	(Ljava/lang/Object;)Ljava/lang/Object;
    //   119: checkcast 292	org/eclipse/osgi/storagemanager/StorageManager$Entry
    //   122: astore 7
    //   124: aload 6
    //   126: bipush 44
    //   128: invokevirtual 544	java/lang/String:indexOf	(I)I
    //   131: istore 10
    //   133: iload 10
    //   135: iconst_m1
    //   136: if_icmpeq +33 -> 169
    //   139: aload 6
    //   141: iconst_0
    //   142: iload 10
    //   144: invokevirtual 547	java/lang/String:substring	(II)Ljava/lang/String;
    //   147: invokestatic 541	java/lang/Integer:parseInt	(Ljava/lang/String;)I
    //   150: istore 8
    //   152: aload 6
    //   154: iload 10
    //   156: iconst_1
    //   157: iadd
    //   158: invokevirtual 546	java/lang/String:substring	(I)Ljava/lang/String;
    //   161: invokestatic 541	java/lang/Integer:parseInt	(Ljava/lang/String;)I
    //   164: istore 9
    //   166: goto +13 -> 179
    //   169: aload 6
    //   171: invokestatic 541	java/lang/Integer:parseInt	(Ljava/lang/String;)I
    //   174: istore 8
    //   176: iconst_0
    //   177: istore 9
    //   179: aload 7
    //   181: ifnonnull +32 -> 213
    //   184: aload_0
    //   185: getfield 513	org/eclipse/osgi/storagemanager/StorageManager:table	Ljava/util/Properties;
    //   188: aload 5
    //   190: new 292	org/eclipse/osgi/storagemanager/StorageManager$Entry
    //   193: dup
    //   194: aload_0
    //   195: iload 8
    //   197: iload 8
    //   199: iconst_1
    //   200: iadd
    //   201: iload 9
    //   203: invokespecial 619	org/eclipse/osgi/storagemanager/StorageManager$Entry:<init>	(Lorg/eclipse/osgi/storagemanager/StorageManager;III)V
    //   206: invokevirtual 570	java/util/Properties:put	(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    //   209: pop
    //   210: goto +12 -> 222
    //   213: aload 7
    //   215: iload 8
    //   217: iconst_1
    //   218: iadd
    //   219: invokevirtual 618	org/eclipse/osgi/storagemanager/StorageManager$Entry:setWriteId	(I)V
    //   222: aload 4
    //   224: invokeinterface 621 1 0
    //   229: ifne -144 -> 85
    //   232: return
    // Line number table:
    //   Java source line #484	-> byte code offset #0
    //   Java source line #485	-> byte code offset #8
    //   Java source line #486	-> byte code offset #21
    //   Java source line #487	-> byte code offset #22
    //   Java source line #488	-> byte code offset #30
    //   Java source line #490	-> byte code offset #42
    //   Java source line #491	-> byte code offset #50
    //   Java source line #493	-> byte code offset #52
    //   Java source line #494	-> byte code offset #59
    //   Java source line #497	-> byte code offset #60
    //   Java source line #493	-> byte code offset #63
    //   Java source line #494	-> byte code offset #70
    //   Java source line #498	-> byte code offset #71
    //   Java source line #499	-> byte code offset #76
    //   Java source line #500	-> byte code offset #85
    //   Java source line #501	-> byte code offset #97
    //   Java source line #502	-> byte code offset #105
    //   Java source line #503	-> byte code offset #110
    //   Java source line #507	-> byte code offset #124
    //   Java source line #508	-> byte code offset #133
    //   Java source line #509	-> byte code offset #139
    //   Java source line #510	-> byte code offset #152
    //   Java source line #512	-> byte code offset #169
    //   Java source line #513	-> byte code offset #176
    //   Java source line #515	-> byte code offset #179
    //   Java source line #516	-> byte code offset #184
    //   Java source line #518	-> byte code offset #213
    //   Java source line #499	-> byte code offset #222
    //   Java source line #523	-> byte code offset #232
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	233	0	this	StorageManager
    //   7	66	1	stamp	int
    //   29	69	2	diskTable	Properties
    //   41	23	3	input	InputStream
    //   50	11	4	localObject1	Object
    //   80	143	4	e	Object
    //   95	94	5	file	String
    //   103	67	6	value	String
    //   122	92	7	entry	Entry
    //   150	3	8	id	int
    //   174	42	8	id	int
    //   164	3	9	fileType	int
    //   177	25	9	fileType	int
    //   131	24	10	idx	int
    //   59	1	14	localIOException1	IOException
    //   70	1	15	localIOException2	IOException
    // Exception table:
    //   from	to	target	type
    //   42	50	50	finally
    //   52	56	59	java/io/IOException
    //   63	67	70	java/io/IOException
  }
  
  private void save()
    throws IOException
  {
    if (readOnly) {
      return;
    }
    updateTable();
    
    Properties props = new Properties();
    for (Enumeration<Object> e = table.keys(); e.hasMoreElements();)
    {
      String file = (String)e.nextElement();
      entry = (Entry)table.get(file);
      String value;
      String value;
      if (entry.getFileType() != 0) {
        value = 
          Integer.toString(entry.getWriteId() - 1) + ',' + Integer.toString(entry.getFileType());
      } else {
        value = Integer.toString(entry.getWriteId() - 1);
      }
      props.put(file, value);
    }
    ReliableFileOutputStream fileStream = new ReliableFileOutputStream(tableFile);
    boolean error = true;
    try
    {
      props.store(fileStream, "safe table");
      fileStream.close();
      error = false;
    }
    finally
    {
      if (error) {
        fileStream.abort();
      }
    }
    if (saveCleanup) {
      try
      {
        cleanup(false);
      }
      catch (IOException ex)
      {
        System.out.println("Unexpected IOException is thrown inside cleanupWithLock. Please look below for stacktrace");
        ex.printStackTrace(System.out);
      }
    }
    tableStamp = ReliableFile.lastModifiedVersion(tableFile);
  }
  
  private boolean update(String managedFile, String source)
    throws IOException
  {
    Entry entry = (Entry)table.get(managedFile);
    if (entry == null) {
      add(managedFile);
    }
    int newId = entry.getWriteId();
    
    boolean success = move(getAbsolutePath(source), getAbsolutePath(managedFile) + '.' + newId);
    if (!success)
    {
      newId = findOldestGeneration(managedFile) + 1;
      success = move(getAbsolutePath(source), getAbsolutePath(managedFile) + '.' + newId);
    }
    if (!success) {
      return false;
    }
    entry.setReadId(newId);
    entry.setWriteId(newId + 1);
    return true;
  }
  
  private void cleanup(boolean doLock)
    throws IOException
  {
    if (readOnly) {
      return;
    }
    if ((doLock) && (!lock(true))) {
      throw new IOException(EclipseAdaptorMsg.fileManager_cannotLock);
    }
    try
    {
      String[] files = managerRoot.list();
      String[] files;
      if (files != null)
      {
        int i;
        for (int i = 0; i < files.length; i++) {
          if ((files[i].endsWith(".instance")) && ((instanceFile == null) || (!files[i].equalsIgnoreCase(instanceFile.getName()))))
          {
            Locker tmpLocker = BasicLocation.createLocker(new File(managerRoot, files[i]), lockMode);
            if (tmpLocker.lock())
            {
              tmpLocker.release();
              new File(managerRoot, files[i]).delete();
            }
            else
            {
              tmpLocker.release();
              return;
            }
          }
        }
      }
      updateTable();
      Collection<Map.Entry<Object, Object>> managedFiles = table.entrySet();
      for (Iterator<Map.Entry<Object, Object>> iter = managedFiles.iterator(); iter.hasNext();)
      {
        Map.Entry<Object, Object> fileEntry = (Map.Entry)iter.next();
        String fileName = (String)fileEntry.getKey();
        Entry info = (Entry)fileEntry.getValue();
        if (info.getFileType() == 1)
        {
          ReliableFile.cleanupGenerations(new File(base, fileName));
        }
        else
        {
          String readId = Integer.toString(info.getWriteId() - 1);
          deleteCopies(fileName, readId);
        }
      }
      if (tempCleanup)
      {
        files = base.list();
        if (files != null) {
          for (int i = 0; i < files.length; i++) {
            if (files[i].endsWith(".tmp")) {
              new File(base, files[i]).delete();
            }
          }
        }
      }
    }
    finally
    {
      if (doLock) {
        release();
      }
    }
    if (doLock) {
      release();
    }
  }
  
  private void deleteCopies(String fileName, String exceptionNumber)
  {
    String notToDelete = fileName + '.' + exceptionNumber;
    String[] files = base.list();
    if (files == null) {
      return;
    }
    for (int i = 0; i < files.length; i++) {
      if ((files[i].startsWith(fileName + '.')) && (!files[i].equals(notToDelete))) {
        new File(base, files[i]).delete();
      }
    }
  }
  
  public void close()
  {
    if (!open) {
      return;
    }
    open = false;
    if (readOnly) {
      return;
    }
    try
    {
      cleanup(true);
    }
    catch (IOException localIOException) {}
    if (instanceLocker != null) {
      instanceLocker.release();
    }
    if (instanceFile != null) {
      instanceFile.delete();
    }
  }
  
  public void open(boolean wait)
    throws IOException
  {
    if (!readOnly)
    {
      managerRoot.mkdirs();
      if (!managerRoot.exists()) {
        throw new IOException(EclipseAdaptorMsg.fileManager_cannotLock);
      }
      if (openCleanup) {
        cleanup(true);
      }
      locked = lock(wait);
      if ((!locked) && (wait)) {
        throw new IOException(EclipseAdaptorMsg.fileManager_cannotLock);
      }
    }
    try
    {
      initializeInstanceFile();
      updateTable();
      open = true;
    }
    finally
    {
      release();
    }
  }
  
  public File createTempFile(String file)
    throws IOException
  {
    if (readOnly) {
      throw new IOException(EclipseAdaptorMsg.fileManager_illegalInReadOnlyMode);
    }
    File tmpFile = File.createTempFile(file, ".tmp", base);
    tmpFile.deleteOnExit();
    return tmpFile;
  }
  
  public InputStream getInputStream(String managedFile)
    throws IOException
  {
    return getInputStream(managedFile, 0);
  }
  
  public InputStream[] getInputStreamSet(String[] managedFiles)
    throws IOException
  {
    InputStream[] streams = new InputStream[managedFiles.length];
    for (int i = 0; i < streams.length; i++) {
      streams[i] = getInputStream(managedFiles[i], 1);
    }
    return streams;
  }
  
  private InputStream getInputStream(String managedFiles, int openMask)
    throws IOException
  {
    if (useReliableFiles)
    {
      int id = getId(managedFiles);
      if (id == -1) {
        return null;
      }
      return new ReliableFileInputStream(new File(getBase(), managedFiles), id, openMask);
    }
    File lookup = lookup(managedFiles, false);
    if (lookup == null) {
      return null;
    }
    return new FileInputStream(lookup);
  }
  
  public ManagedOutputStream getOutputStream(String managedFile)
    throws IOException
  {
    if (useReliableFiles)
    {
      ReliableFileOutputStream out = new ReliableFileOutputStream(new File(getBase(), managedFile));
      return new ManagedOutputStream(out, this, managedFile, null);
    }
    File tmpFile = createTempFile(managedFile);
    return new ManagedOutputStream(new FileOutputStream(tmpFile), this, managedFile, tmpFile);
  }
  
  public ManagedOutputStream[] getOutputStreamSet(String[] managedFiles)
    throws IOException
  {
    int count = managedFiles.length;
    ManagedOutputStream[] streams = new ManagedOutputStream[count];
    int idx = 0;
    try
    {
      for (; idx < count; idx++)
      {
        ManagedOutputStream newStream = getOutputStream(managedFiles[idx]);
        newStream.setStreamSet(streams);
        streams[idx] = newStream;
      }
    }
    catch (IOException e)
    {
      for (int jdx = 0; jdx < idx; jdx++) {
        streams[jdx].abort();
      }
      throw e;
    }
    return streams;
  }
  
  void abortOutputStream(ManagedOutputStream out)
  {
    ManagedOutputStream[] set = out.getStreamSet();
    if (set == null) {
      set = new ManagedOutputStream[] { out };
    }
    synchronized (set)
    {
      for (int idx = 0; idx < set.length; idx++)
      {
        out = set[idx];
        if (out.getOutputFile() == null)
        {
          ReliableFileOutputStream rfos = (ReliableFileOutputStream)out.getOutputStream();
          rfos.abort();
        }
        else
        {
          if (out.getState() == 0) {
            try
            {
              out.getOutputStream().close();
            }
            catch (IOException localIOException) {}
          }
          out.getOutputFile().delete();
        }
        out.setState(1);
      }
    }
  }
  
  void closeOutputStream(ManagedOutputStream smos)
    throws IOException
  {
    if (smos.getState() != 0) {
      return;
    }
    ManagedOutputStream[] streamSet = smos.getStreamSet();
    if (smos.getOutputFile() == null)
    {
      ReliableFileOutputStream rfos = (ReliableFileOutputStream)smos.getOutputStream();
      
      File file = rfos.closeIntermediateFile();
      smos.setState(1);
      String target = smos.getTarget();
      if (streamSet == null)
      {
        add(target, 1);
        update(new String[] { smos.getTarget() }, new String[] { file.getName() });
        ReliableFile.fileUpdated(new File(getBase(), smos.getTarget()));
      }
    }
    else
    {
      OutputStream out = smos.getOutputStream();
      out.flush();
      try
      {
        ((FileOutputStream)out).getFD().sync();
      }
      catch (SyncFailedException localSyncFailedException) {}
      out.close();
      smos.setState(1);
      String target = smos.getTarget();
      if (streamSet == null)
      {
        add(target, 0);
        update(new String[] { target }, new String[] { smos.getOutputFile().getName() });
      }
    }
    if (streamSet != null) {
      synchronized (streamSet)
      {
        for (int idx = 0; idx < streamSet.length; idx++) {
          if (streamSet[idx].getState() == 0) {
            return;
          }
        }
        String[] targets = new String[streamSet.length];
        String[] sources = new String[streamSet.length];
        for (int idx = 0; idx < streamSet.length; idx++)
        {
          smos = streamSet[idx];
          targets[idx] = smos.getTarget();
          File outputFile = smos.getOutputFile();
          if (outputFile == null)
          {
            add(smos.getTarget(), 1);
            ReliableFileOutputStream rfos = (ReliableFileOutputStream)smos.getOutputStream();
            File file = rfos.closeIntermediateFile();
            sources[idx] = file.getName();
            ReliableFile.fileUpdated(new File(getBase(), smos.getTarget()));
          }
          else
          {
            add(smos.getTarget(), 0);
            sources[idx] = outputFile.getName();
          }
        }
        update(targets, sources);
      }
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.storagemanager.StorageManager
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.util;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.StringTokenizer;
import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.internal.core.Msg;
import org.eclipse.osgi.framework.internal.core.Tokenizer;
import org.osgi.framework.BundleException;

public class ManifestElement
{
  private final String mainValue;
  private final String[] valueComponents;
  private Hashtable<String, Object> attributes;
  private Hashtable<String, Object> directives;
  
  private ManifestElement(String value, String[] valueComponents)
  {
    mainValue = value;
    this.valueComponents = valueComponents;
  }
  
  public String getValue()
  {
    return mainValue;
  }
  
  public String[] getValueComponents()
  {
    return valueComponents;
  }
  
  public String getAttribute(String key)
  {
    return getTableValue(attributes, key);
  }
  
  public String[] getAttributes(String key)
  {
    return getTableValues(attributes, key);
  }
  
  public Enumeration<String> getKeys()
  {
    return getTableKeys(attributes);
  }
  
  private void addAttribute(String key, String value)
  {
    attributes = addTableValue(attributes, key, value);
  }
  
  public String getDirective(String key)
  {
    return getTableValue(directives, key);
  }
  
  public String[] getDirectives(String key)
  {
    return getTableValues(directives, key);
  }
  
  public Enumeration<String> getDirectiveKeys()
  {
    return getTableKeys(directives);
  }
  
  private void addDirective(String key, String value)
  {
    directives = addTableValue(directives, key, value);
  }
  
  private String getTableValue(Hashtable<String, Object> table, String key)
  {
    if (table == null) {
      return null;
    }
    Object result = table.get(key);
    if (result == null) {
      return null;
    }
    if ((result instanceof String)) {
      return (String)result;
    }
    List<String> valueList = (List)result;
    
    return (String)valueList.get(valueList.size() - 1);
  }
  
  private String[] getTableValues(Hashtable<String, Object> table, String key)
  {
    if (table == null) {
      return null;
    }
    Object result = table.get(key);
    if (result == null) {
      return null;
    }
    if ((result instanceof String)) {
      return new String[] { (String)result };
    }
    List<String> valueList = (List)result;
    return (String[])valueList.toArray(new String[valueList.size()]);
  }
  
  private Enumeration<String> getTableKeys(Hashtable<String, Object> table)
  {
    if (table == null) {
      return null;
    }
    return table.keys();
  }
  
  private Hashtable<String, Object> addTableValue(Hashtable<String, Object> table, String key, String value)
  {
    if (table == null) {
      table = new Hashtable(7);
    }
    Object curValue = table.get(key);
    if (curValue != null)
    {
      List<String> newList;
      List<String> newList;
      if ((curValue instanceof List))
      {
        newList = (List)curValue;
      }
      else
      {
        newList = new ArrayList(5);
        newList.add((String)curValue);
      }
      newList.add(value);
      table.put(key, newList);
    }
    else
    {
      table.put(key, value);
    }
    return table;
  }
  
  public static ManifestElement[] parseHeader(String header, String value)
    throws BundleException
  {
    if (value == null) {
      return null;
    }
    List<ManifestElement> headerElements = new ArrayList(10);
    Tokenizer tokenizer = new Tokenizer(value);
    char c;
    do
    {
      String next = tokenizer.getString(";,");
      if (next == null) {
        throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), 3);
      }
      List<String> headerValues = new ArrayList();
      StringBuffer headerValue = new StringBuffer(next);
      headerValues.add(next);
      if (Debug.DEBUG_MANIFEST) {
        Debug.print("parseHeader: " + next);
      }
      boolean directive = false;
      c = tokenizer.getChar();
      while (c == ';')
      {
        next = tokenizer.getString(";,=:");
        if (next == null) {
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), 3);
        }
        c = tokenizer.getChar();
        while (c == ':')
        {
          c = tokenizer.getChar();
          if (c != '=')
          {
            String restOfNext = tokenizer.getToken(";,=:");
            if (restOfNext == null) {
              throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), 3);
            }
            next = next + ":" + c + restOfNext;
            c = tokenizer.getChar();
          }
          else
          {
            directive = true;
          }
        }
        if ((c == ';') || (c == ',') || (c == 0))
        {
          headerValues.add(next);
          headerValue.append(";").append(next);
          if (Debug.DEBUG_MANIFEST) {
            Debug.print(";" + next);
          }
        }
      }
      ManifestElement manifestElement = new ManifestElement(headerValue.toString(), (String[])headerValues.toArray(new String[headerValues.size()]));
      while ((c == '=') || (c == ':'))
      {
        while (c == ':')
        {
          c = tokenizer.getChar();
          if (c != '=')
          {
            String restOfNext = tokenizer.getToken("=:");
            if (restOfNext == null) {
              throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), 3);
            }
            next = next + ":" + c + restOfNext;
            c = tokenizer.getChar();
          }
          else
          {
            directive = true;
          }
        }
        String preserveEscapes = null;
        if ((!directive) && (next.indexOf("List") > 0))
        {
          Tokenizer listTokenizer = new Tokenizer(next);
          String attrKey = listTokenizer.getToken(":");
          if ((attrKey != null) && (listTokenizer.getChar() == ':') && ("List".equals(listTokenizer.getToken("<")))) {
            preserveEscapes = "\\,";
          }
        }
        String val = tokenizer.getString(";,", preserveEscapes);
        if (val == null) {
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), 3);
        }
        if (Debug.DEBUG_MANIFEST) {
          Debug.print(";" + next
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

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