src/main/java/de/blau/android/util/SavingHelper.java
/**
     * Sync export an Exportable to a file named with the current date and type
     * 
     * @param ctx an optional Android Context
     * @param exportable the Exportable
     * @return if successful the path the export was to
     */
Sync export an Exportable to a file named with the current date and type

@param ctx an optional Android Context
@param exportable the Exportable
@return if successful the path the export was to
Sync export an Exportable to a file named with the current date and type @param ctx an optional Android Context @param exportable the Exportable @return if successful the path the export was to
@Nullable
    public static String export(@Nullable Context ctx, @NonNull Exportable exportable) {
        String filename = DateFormatter.getFormattedString(DATE_PATTERN_EXPORT_FILE_NAME_PART) + "." + exportable.exportExtension();
        try {
            File outfile = new File(FileUtil.getPublicDirectory(), filename);
            try (FileOutputStream fout = new FileOutputStream(outfile); OutputStream outputStream = new BufferedOutputStream(fout)) {
                exportable.export(outputStream);
                Log.i(DEBUG_TAG, "Successful export to " + filename);
                if (ctx != null) {
                    new Handler(ctx.getMainLooper()).post(() -> Snack.toastTopInfo(ctx, ctx.getResources().getString(R.string.toast_export_success, filename)));
                }
                return outfile.getAbsolutePath();
            }
        } catch (Exception e) {
            Log.e(DEBUG_TAG, "Export failed - " + filename);
            if (ctx != null) {
                new Handler(ctx.getMainLooper()).post(() -> Snack.toastTopError(ctx, R.string.toast_export_failed));
            }
        }
        return null;
    }
@ Nullable public static String export ( @ Nullable Context ctx , @ NonNull Exportable exportable ) { String filename = DateFormatter . getFormattedString ( DATE_PATTERN_EXPORT_FILE_NAME_PART ) + "." + exportable . exportExtension ( ) ; try { File outfile = new File ( FileUtil . getPublicDirectory ( ) , filename ) ; try ( FileOutputStream fout = new FileOutputStream ( outfile ) ; OutputStream outputStream = new BufferedOutputStream ( fout ) ) { exportable . export ( outputStream ) ; Log . i ( DEBUG_TAG , "Successful export to " + filename ) ; if ( ctx != null ) { new Handler ( ctx . getMainLooper ( ) ) . post ( ( ) -> Snack . toastTopInfo ( ctx , ctx . getResources ( ) . getString ( R . string . toast_export_success , filename ) ) ) ; } return outfile . getAbsolutePath ( ) ; } } catch ( Exception e ) { Log . e ( DEBUG_TAG , "Export failed - " + filename ) ; if ( ctx != null ) { new Handler ( ctx . getMainLooper ( ) ) . post ( ( ) -> Snack . toastTopError ( ctx , R . string . toast_export_failed ) ) ; } } return null ; }
Sync export an Exportable to a file named with the current date and type
Sync export an Exportable to a file named with the current date and type