net.sf.mmm.util.io.api
Interface DetectorStream

All Known Subinterfaces:
DetectorInputStream, DetectorOutputStream
All Known Implementing Classes:
AbstractDetectorStream, ProcessableDetectorInputStream, ProcessableDetectorOutputStream, ProcessableDetectorStream

public interface DetectorStream

This is the abstract base interface for a container of a wrapped stream together with metadata that is detected while streaming the data.
If a reasonable application transfers data from a source to a sink it does NOT load the entire data into memory but uses streams ( InputStream and OutputStream). A typical example is a file that is uploaded via HTTP and written into a database. In many situations it is desirable to get metadata (e.g. mimetype, md5sum, etc.) about the actual data. Most solutions to detect metadata need random access to seek in the data. Therefore you would need to save the data to a temporary file, analyze it and then transfer the file to the database.
The DetectorStream allows you to get the metadata on the fly while streaming that data. All you need to do is to create a wrapper on your stream and perform your actual transfer on the wrapper stream instead. This interface is the container for the wrapper stream.
This approach requires that you read/write your data completely (at least until the detection is done).
A DetectorStream is typically used to get the actual wrapper stream, read/write the stream data and then get the metadata. After this, the object is useless and can be eaten up by the garbage collector.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
DetectorStreamProvider

Method Summary
 Map<String,Object> getMetadata()
          This method gets the context with the detected metadata.
 boolean isDone()
          This method determines if the detection is done.
 

Method Detail

getMetadata

Map<String,Object> getMetadata()
This method gets the context with the detected metadata. It is immutable and should NOT be modified. This method should NOT be called, before this detector stream is done.
For the keys to use in the metadata Map have a look at net.sf.mmm.util.metakey.api.MetakeyCore.

Returns:
the metadata.

isDone

boolean isDone()
This method determines if the detection is done. If the stream has been processed to the end this method will always return true. However the detection may be done before the end of the stream was reached (e.g. because all metadata comes from the header of the data).

Returns:
true if the metadata has been completely been collected, false otherwise.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.