the storage manager org.eclipse.osgi.storagemanager.StorageManager cacheStorageManager = new StorageManager("d:/sharedFolder/bar/", false); //$NON-NLS-1$ try { cacheStorageManager.open(true); } catch (IOException e) { // Ignore the exception. The registry will be rebuilt from source. } //To read from a file java.io.File fileA = cacheStorageManager.lookup("fileA", false)); java.io.File fileB = cacheStorageManager.lookup("fileB", false)); //Do the reading code new java.io.FileOutputStream(fileA); //To write in files cacheStorageManager.add("fileC"); //add the file to the filemanager (in this case we assume it is not already here) cacheStorageManager.add("fileD"); // The file is never written directly into the file name, so we create some temporary file java.io.File fileC = cacheStorageManager.createTempFile("fileC"); java.io.File fileD = cacheStorageManager.createTempFile("fileD"); //Do the actual writing here... //Finally update the storagemanager with the actual file to manage. cacheStorageManager.update(new String[] {"fileC", "fileD"}, new String[] {fileC.getName(), fileD.getName()}; //Close the file manager at the end cacheStorageManager.close();
Implementation details
The following implementation details are provided to help with understanding the behavior of this class. The general principle is to maintain a table which maps user-level file names onto an actual disk files. If a file needs to be modified, it is stored into a new file. The old content is not removed from disk until all entities have closed there instance of the storage manager. Once the instance has been created, open() must be called before performing any other operation. On open the storage manager obtains a snapshot of the current managed files contents. If an entity updates a managed file, the storage manager will save the content for that instance of the storage manager, all other storage manager instances will still have access to that managed file's content as it was when the instance was first opened.
@since 3.2