src/main/java/de/blau/android/osm/StorageDelegator.java
/**
     * Stores the current storage data to the default storage file
     * 
     * @param ctx Android Context
     * @throws IOException if saving failed
     */
Stores the current storage data to the default storage file

@param ctx Android Context
@throws IOException if saving failed
Stores the current storage data to the default storage file @param ctx Android Context @throws IOException if saving failed
public synchronized void writeToFile(@NonNull Context ctx) throws IOException {
        if (apiStorage == null || currentStorage == null) {
            Log.i(DEBUG_TAG, "storage delegator empty, skipping save");
            return;
        }
        if (!dirty) { 
            Log.i(DEBUG_TAG, "storage delegator not dirty, skipping save");
            return;
        }
        if (readingLock.tryLock()) {
            if (savingHelper.save(ctx, FILENAME, this, true)) {
                dirty = false;
            } else {
                if (ctx instanceof Activity) {
                    try {
                        Snack.barError((Activity) ctx, R.string.toast_statesave_failed);
                    } catch (Exception ignored) {
                        Log.e(DEBUG_TAG, "Emergency toast failed with " + ignored.getMessage());
                    } catch (Error ignored) { 
                        Log.e(DEBUG_TAG, "Emergency toast failed with " + ignored.getMessage());
                    }
                }
                SavingHelper.export(ctx, this); 
                Log.d(DEBUG_TAG, "save of state file failed, written emergency change file");
            }
            readingLock.unlock();
        } else {
            Log.i(DEBUG_TAG, "storage delegator state being read, skipping save");
        }
    }
public synchronized void writeToFile ( @ NonNull Context ctx ) throws IOException { if ( apiStorage == null || currentStorage == null ) { Log . i ( DEBUG_TAG , "storage delegator empty, skipping save" ) ; return ; } if ( ! dirty ) { Log . i ( DEBUG_TAG , "storage delegator not dirty, skipping save" ) ; return ; } if ( readingLock . tryLock ( ) ) { if ( savingHelper . save ( ctx , FILENAME , this , true ) ) { dirty = false ; } else { if ( ctx instanceof Activity ) { try { Snack . barError ( ( Activity ) ctx , R . string . toast_statesave_failed ) ; } catch ( Exception ignored ) { Log . e ( DEBUG_TAG , "Emergency toast failed with " + ignored . getMessage ( ) ) ; } catch ( Error ignored ) { Log . e ( DEBUG_TAG , "Emergency toast failed with " + ignored . getMessage ( ) ) ; } } SavingHelper . export ( ctx , this ) ; Log . d ( DEBUG_TAG , "save of state file failed, written emergency change file" ) ; } readingLock . unlock ( ) ; } else { Log . i ( DEBUG_TAG , "storage delegator state being read, skipping save" ) ; } }
Stores the current storage data to the default storage file
Stores the current storage data to the default storage file
// don't write empty state files // dirty flag should only be set if we have actually read/loaded/changed something // TODO this doesn't really help with error conditions need to throw exception // this is essentially catastrophic and can only happen if something went really wrong // running out of memory or disk, or HW failure // NOSONAR crashing is not an option // ctx == null is checked in method