public static <T> T getObjectFromFile(@NonNull File f, @NonNull String key){
        Preconditions.checkState(f.exists(), "File must exist: %s", f);
        Preconditions.checkArgument(!(UPDATER_BIN.equalsIgnoreCase(key) || NORMALIZER_BIN.equalsIgnoreCase(key)
                        || CONFIGURATION_JSON.equalsIgnoreCase(key) || COEFFICIENTS_BIN.equalsIgnoreCase(key)
                        || NO_PARAMS_MARKER.equalsIgnoreCase(key) || PREPROCESSOR_BIN.equalsIgnoreCase(key)),
                "Invalid key: Key is reserved for internal use: \"%s\"", key);

        try (ZipFile zipFile = new ZipFile(f)) {
            ZipEntry entry = zipFile.getEntry("objects/" + key);
            if(entry == null){
                throw new IllegalStateException("No object with key \"" + key + "\" found");
            }

            Object o;
            try(ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(zipFile.getInputStream(entry)))){
                o = ois.readObject();
            }
            zipFile.close();
            return (T)o;
        } catch (IOException | ClassNotFoundException e){
            throw new RuntimeException("Error reading object (key = " + key + ") from file " + f, e);
        }
    }
public static < T > T getObjectFromFile ( @ NonNull File f , @ NonNull String key ) { Preconditions . checkState ( f . exists ( ) , "File must exist: %s" , f ) ; Preconditions . checkArgument ( ! ( UPDATER_BIN . equalsIgnoreCase ( key ) || NORMALIZER_BIN . equalsIgnoreCase ( key ) || CONFIGURATION_JSON . equalsIgnoreCase ( key ) || COEFFICIENTS_BIN . equalsIgnoreCase ( key ) || NO_PARAMS_MARKER . equalsIgnoreCase ( key ) || PREPROCESSOR_BIN . equalsIgnoreCase ( key ) ) , "Invalid key: Key is reserved for internal use: \"%s\"" , key ) ; try ( ZipFile zipFile = new ZipFile ( f ) ) { ZipEntry entry = zipFile . getEntry ( "objects/" + key ) ; if ( entry == null ) { throw new IllegalStateException ( "No object with key \"" + key + "\" found" ) ; } Object o ; try ( ObjectInputStream ois = new ObjectInputStream ( new BufferedInputStream ( zipFile . getInputStream ( entry ) ) ) ) { o = ois . readObject ( ) ; } zipFile . close ( ) ; return ( T ) o ; } catch ( IOException | ClassNotFoundException e ) { throw new RuntimeException ( "Error reading object (key = " + key + ") from file " + f , e ) ; } }
Get an object with the specified key from the model file, that was previously added to the file using
{@link #addObjectToFile(File, String, Object)}

@param f   model file to add the object to
@param key Key for the object
@param <T> Type of the object
@return The serialized object
@see #listObjectsInFile(File)