- java.lang.Object
-
- com.machinezoo.sourceafis.FingerprintTransparency
-
- All Implemented Interfaces:
-
CloseableScope,AutoCloseable
public abstract class FingerprintTransparency extends Object implements CloseableScope
Algorithm transparency API that can capture all intermediate data structures produced by SourceAFIS algorithm. See algorithm transparency pages on SourceAFIS website for more information and a tutorial on how to use this class.Applications can subclass
FingerprintTransparencyand overridetake(String, String, byte[])method to define new transparency data logger. One default implementation ofFingerprintTransparencyis returned byzip(OutputStream)method. Applications can control what transparency data gets produced by overridingaccepts(String).FingerprintTransparencyinstance should be created in a try-with-resources construct. It will be capturing transparency data from all operations on current thread between invocation of the constructor and invocation ofclose()method, which is called automatically in the try-with-resources construct.- See Also:
- Algorithm transparency in SourceAFIS
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFingerprintTransparency()Creates an instance ofFingerprintTransparencyand activates it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaccepts(String key)Filters transparency data keys that can be passed totake(String, String, byte[]).protected voidcapture(String key, Map<String,Supplier<byte[]>> data)Deprecated.voidclose()Deactivates transparency logging and releases system resources held by this instance if any.protected voidlog(String key, Map<String,Supplier<ByteBuffer>> data)Deprecated.voidtake(String key, String mime, byte[] data)Records transparency data.static FingerprintTransparencyzip(OutputStream stream)Writes all transparency data to a ZIP file.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.machinezoo.closeablescope.CloseableScope
andFinally, andThen
-
-
-
-
Constructor Detail
-
FingerprintTransparency
protected FingerprintTransparency()
Creates an instance ofFingerprintTransparencyand activates it.Activation places the new
FingerprintTransparencyinstance in thread-local storage, which causes all operations executed by current thread to log data to thisFingerprintTransparencyinstance. If activations are nested, data is only logged to the currently innermostFingerprintTransparency.Deactivation happens in
close()method. Instances ofFingerprintTransparencyshould be created in try-with-resources construct to ensure thatclose()is always called.FingerprintTransparencyis an abstract class. This constructor is only called by subclasses.- See Also:
-
close()
-
-
Method Detail
-
accepts
public boolean accepts(String key)
Filters transparency data keys that can be passed totake(String, String, byte[]). Default implementation always returnstrue, i.e. all transparency data is passed totake(String, String, byte[]). Implementation can override this method to filter some keys out, which improves performance.This method should always return the same result for the same key. Result may be cached and this method might not be called every time something is about to be logged.
- Parameters:
-
key- transparency data key as used intake(String, String, byte[]) - Returns:
- whether transparency data under given key should be logged
- See Also:
-
take(String, String, byte[])
-
take
public void take(String key, String mime, byte[] data)
Records transparency data. Subclasses must override this method, because the default implementation does nothing. While thisFingerprintTransparencyobject is active (between call to the constructor and call toclose()), this method is called with transparency data in its parameters.Parameter
keyspecifies the kind of transparency data being logged, usually corresponding to some stage in the algorithm. Parameterdatathen contains the actual transparency data. This method may be called multiple times with the samekeyif the algorithm produces that kind of transparency data repeatedly. See algorithm transparency on SourceAFIS website for documentation of the structure of the transparency data.Transparency data is offered only if
accepts(String)returnstruefor the samekey. This allows applications to efficiently collect only transparency data that is actually needed.MIME type of the transparency data is provided, which may be useful for generic implementations, for example transparency data browser app that changes type of visualization based on the MIME type. Most transparency data is serialized in CBOR format (MIME application/cbor).
Implementations of this method should be synchronized. Although the current SourceAFIS algorithm is single-threaded, future versions of SourceAFIS might run some parts of the algorithm in parallel, which would result in concurrent calls to this method.
If this method throws, exception is propagated through SourceAFIS code.
- Parameters:
-
key- specifies the kind of transparency data being logged -
mime- MIME type of the transparency data indataparameter -
data- transparency data being logged - See Also:
-
Algorithm transparency in SourceAFIS,
accepts(String),zip(OutputStream)
-
capture
@Deprecated protected void capture(String key, Map<String,Supplier<byte[]>> data)
Deprecated.Records transparency data (deprecated). This is a deprecated variant oftake(String, String, byte[]). This method is only called iftake(String, String, byte[])is not overridden.- Parameters:
-
key- specifies the kind of transparency data being reported -
data- a map of suffixes (like.cboror.dat) toSupplierof the available transparency data - See Also:
-
take(String, String, byte[])
-
log
@Deprecated protected void log(String key, Map<String,Supplier<ByteBuffer>> data)
Deprecated.Records transparency data (deprecated). This is a deprecated variant oftake(String, String, byte[]). This method is only called iftake(String, String, byte[])andcapture(String, Map)are not overridden.- Parameters:
-
key- specifies the kind of transparency data being reported -
data- a map of suffixes (like.cboror.dat) toSupplierof the available transparency data - See Also:
-
take(String, String, byte[])
-
close
public void close()
Deactivates transparency logging and releases system resources held by this instance if any. This method is normally called automatically whenFingerprintTransparencyis used in try-with-resources construct.Deactivation stops transparency data logging to this instance of
FingerprintTransparency. Logging thus takes place between invocation of constructor (FingerprintTransparency()) and invocation of this method. If activations were nested, this method reactivates the outerFingerprintTransparency.Subclasses can override this method to perform cleanup. Default implementation of this method performs deactivation. It must be called by overriding methods for deactivation to work correctly.
- Specified by:
-
closein interfaceAutoCloseable - Specified by:
-
closein interfaceCloseableScope - See Also:
-
FingerprintTransparency()
-
zip
public static FingerprintTransparency zip(OutputStream stream)
Writes all transparency data to a ZIP file. This is a convenience method to enable easy exploration of the available data. Programmatic processing of transparency data should be done by subclassingFingerprintTransparencyand overridingtake(String, String, byte[])method.ZIP file entries have filenames like
NNN-key.extwhereNNNis a sequentially assigned ID,keycomes fromtake(String, String, byte[])parameter, andextis derived from MIME type.The returned
FingerprintTransparencyobject holds system resources and callers are responsible for callingclose()method, perhaps using try-with-resources construct. Failure to close the returnedFingerprintTransparencyinstance may result in damaged ZIP file.If the provided
streamthrowsIOException, the exception will be wrapped in an unchecked exception and propagated.- Parameters:
-
stream- output stream where ZIP file will be written (will be closed when the returnedFingerprintTransparencyis closed) - Returns:
- algorithm transparency logger that writes data to a ZIP file
- See Also:
-
Algorithm transparency in SourceAFIS,
close(),take(String, String, byte[])
-
-