db/flat/src/main/java/org/commonjava/indy/flat/data/DataFileStoreUtils.java
public static void loadFromDiskAnd( DataFileManager manager, IndyObjectMapper serializer, StoreKey key,
                                        final ChangeSummary summary, Consumer<ArtifactStore> consumer )
    {
        if ( key != null ) // Load a single file
        {
            DataFile f = manager.getDataFile( INDY_STORE, key.getPackageType(), key.getType().singularEndpointName(),
                                              key.getName() + ".json" );
            if ( f.exists() )
            {
                ArtifactStore store;
                try
                {
                    String json = f.readString();
                    store = serializer.readValue( json, key.getType().getStoreClass() );
                }
                catch ( IOException e )
                {
                    logger.error( "Failed to read file", e );
                    return;
                }
                consumer.accept( store );
            }
            return;
        }

        // Load all
        DataFile[] packageDirs = manager.getDataFile( INDY_STORE ).listFiles( ( f ) -> true );
        for ( DataFile pkgDir : packageDirs )
        {
            for ( StoreType type : StoreType.values() )
            {
                DataFile[] files = pkgDir.getChild( type.singularEndpointName() ).listFiles( f -> true );
                if ( files != null )
                {
                    for ( final DataFile f : files )
                    {
                        try
                        {
                            final String json = f.readString();
                            final ArtifactStore store = serializer.readValue( json, type.getStoreClass() );
                            if ( store == null )
                            {
                                f.delete( summary );
                            }
                            else
                            {
                                consumer.accept( store );
                            }
                        }
                        catch ( final IOException e )
                        {
                            logger.error( String.format( "Failed to load %s store: %s. Reason: %s", type, f,
                                                         e.getMessage() ), e );
                            try
                            {
                                f.delete( summary );
                            }
                            catch ( IOException e1 )
                            {
                                logger.error( "Failed to delete invalid store definition file: " + f, e );
                            }
                        }
                    }
                }
            }
        }
    }
public static void loadFromDiskAnd( DataFileManager manager, IndyObjectMapper serializer, StoreKey key,
                                        final ChangeSummary summary, Consumer<ArtifactStore> consumer )
    {
        if ( key != null ) // Load a single file
        {
            DataFile f = manager.getDataFile( INDY_STORE, key.getPackageType(), key.getType().singularEndpointName(),
                                              key.getName() + ".json" );
            if ( f.exists() )
            {
                ArtifactStore store;
                try
                {
                    String json = f.readString();
                    store = serializer.readValue( json, key.getType().getStoreClass() );
                }
                catch ( IOException e )
                {
                    logger.error( "Failed to read file", e );
                    return;
                }
                consumer.accept( store );
            }
            return;
        }

        // Load all
        DataFile[] packageDirs = manager.getDataFile( INDY_STORE ).listFiles( ( f ) -> true );
        for ( DataFile pkgDir : packageDirs )
        {
            for ( StoreType type : StoreType.values() )
            {
                DataFile[] files = pkgDir.getChild( type.singularEndpointName() ).listFiles( f -> true );
                if ( files != null )
                {
                    for ( final DataFile f : files )
                    {
                        try
                        {
                            final String json = f.readString();
                            final ArtifactStore store = serializer.readValue( json, type.getStoreClass() );
                            if ( store == null )
                            {
                                f.delete( summary );
                            }
                            else
                            {
                                consumer.accept( store );
                            }
                        }
                        catch ( final IOException e )
                        {
                            logger.error( String.format( "Failed to load %s store: %s. Reason: %s", type, f,
                                                         e.getMessage() ), e );
                            try
                            {
                                f.delete( summary );
                            }
                            catch ( IOException e1 )
                            {
                                logger.error( "Failed to delete invalid store definition file: " + f, e );
                            }
                        }
                    }
                }
            }
        }
    }
Load store definitions from disk and apply consumer function.
@param manager
@param serializer
@param key if null, load all.
@param summary
@param consumer