src/main/java/de/blau/android/presets/AutoPreset.java
/**
     * Save a Preset to our public directory
     * 
     * @param context Android Context
     * @param preset the Preset to save
     */
Save a Preset to our public directory

@param context Android Context
@param preset the Preset to save
Save a Preset to our public directory @param context Android Context @param preset the Preset to save
public static void save(@NonNull Context context, @NonNull final Preset preset) {
        Logic logic = App.getLogic();
        ExecutorTask<Void, Void, Void> save = new ExecutorTask<Void, Void, Void>(logic.getExecutorService(), logic.getHandler()) {
            @Override
            protected Void doInBackground(Void param) {
                try {
                    File outfile = FileUtil.openFileForWriting(context,
                            FileUtil.getPublicDirectory() + "/" + Paths.DIRECTORY_PATH_AUTOPRESET + "/" + Files.FILE_NAME_AUTOPRESET);
                    try (FileOutputStream fout = new FileOutputStream(outfile); OutputStream out = new BufferedOutputStream(fout);) { 
                        Log.d(DEBUG_TAG, "Saving to " + outfile.getPath());
                        XmlSerializer s = XmlPullParserFactory.newInstance().newSerializer();
                        s.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
                        s.setOutput(out, OsmXml.UTF_8);
                        preset.toXml(s);
                        s.flush();
                    } catch (IllegalArgumentException | IllegalStateException | XmlPullParserException e) {
                        Log.e(DEBUG_TAG, "Parsing failed with " + e.getMessage());
                    }
                } catch (IOException ioex) {
                    Log.e(DEBUG_TAG, "Saving failed with " + ioex.getMessage());
                }
                return null;
            }
        };
        save.execute();
    }
public static void save ( @ NonNull Context context , @ NonNull final Preset preset ) { Logic logic = App . getLogic ( ) ; ExecutorTask < Void , Void , Void > save = new ExecutorTask < Void , Void , Void > ( logic . getExecutorService ( ) , logic . getHandler ( ) ) { @ Override protected Void doInBackground ( Void param ) { try { File outfile = FileUtil . openFileForWriting ( context , FileUtil . getPublicDirectory ( ) + "/" + Paths . DIRECTORY_PATH_AUTOPRESET + "/" + Files . FILE_NAME_AUTOPRESET ) ; try ( FileOutputStream fout = new FileOutputStream ( outfile ) ; OutputStream out = new BufferedOutputStream ( fout ) ; ) { Log . d ( DEBUG_TAG , "Saving to " + outfile . getPath ( ) ) ; XmlSerializer s = XmlPullParserFactory . newInstance ( ) . newSerializer ( ) ; s . setFeature ( "http://xmlpull.org/v1/doc/features.html#indent-output" , true ) ; s . setOutput ( out , OsmXml . UTF_8 ) ; preset . toXml ( s ) ; s . flush ( ) ; } catch ( IllegalArgumentException | IllegalStateException | XmlPullParserException e ) { Log . e ( DEBUG_TAG , "Parsing failed with " + e . getMessage ( ) ) ; } } catch ( IOException ioex ) { Log . e ( DEBUG_TAG , "Saving failed with " + ioex . getMessage ( ) ) ; } return null ; } } ; save . execute ( ) ; }
Save a Preset to our public directory
Save a Preset to our public directory
// NOSONAR