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

All Known Implementing Classes:
AbstractDetectorStreamProvider, DetectorStreamProviderImpl

public interface DetectorStreamProvider

This is the interface of a service that provides detector-streams.
Typical usage might look like this (the cast is a little stupid but just to make it clear):

   DetectorStreamProvider provider = ...
   OutputStream outStream = ...
 
   //writeData(outStream);
   //outStream.close();
 
   DetectorOutputStream detectorOutStream = provider.wrap(outStream, detector);
   OutputStream wrappedOutStream = detectorOutStream.getStream();
   writeData(wrappedOutStream);
   wrappedOutStream.close();
 
   Map<String, Object> metadata = detectorOutStream.getMetadata(); 
   Long bytesWritten = metadata.get("filesize");
 

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

Method Summary
 DetectorInputStream wrapInputStream(InputStream stream)
          This method gets a DetectorInputStream that wrapps the given stream.
 DetectorInputStream wrapInputStream(InputStream stream, Map<String,Object> metadata)
          This method gets a DetectorInputStream that wraps the given stream.
 DetectorOutputStream wrapOutputStream(OutputStream stream)
          This method gets a DetectorOutputStream that wraps the given stream.
 DetectorOutputStream wrapOutputStream(OutputStream stream, Map<String,Object> metadata)
          This method gets a DetectorOutputStream that wraps the given stream.
 

Method Detail

wrapInputStream

DetectorInputStream wrapInputStream(InputStream stream)
This method gets a DetectorInputStream that wrapps the given stream.

Parameters:
stream - is the stream to wrap. This stream must be a fresh stream that is untouched since it was opened.
Returns:
the wrapped input stream.

wrapInputStream

DetectorInputStream wrapInputStream(InputStream stream,
                                    Map<String,Object> metadata)
This method gets a DetectorInputStream that wraps the given stream. In addition to wrapInputStream(InputStream) an additional parameter metadata is supplied. If this context contains metadata values, that are mutable, the stream wrapper manipulates the data such that the given values correspond to the data.
E.g. if the metadata contains a title and a genre and the stream points to the data of an mp3 song, the given title and genre are "written" to the ID3 tag of the song (if supported by the implementation).
If the metadata contains values that are immutable and NOT compatible with the detected values (e.g. mimetype=text/plain is supplied, but mimetype is audio/midi) then the value will simple be overridden in the detected metadata.
If the metadata contains values that are unknown to the detector implementation (e.g. foo=bar), these values will also be untouched and are also available in the detected metadata.

Parameters:
stream - is the stream to wrap. This stream must be a fresh stream that is untouched since it was opened.
metadata - is the existing metadata to apply.
Returns:
the wrapped input stream.

wrapOutputStream

DetectorOutputStream wrapOutputStream(OutputStream stream)
This method gets a DetectorOutputStream that wraps the given stream.

Parameters:
stream - is the stream to wrap. This stream must be a fresh stream that is untouched since it was opened.
Returns:
the wrapped output stream.

wrapOutputStream

DetectorOutputStream wrapOutputStream(OutputStream stream,
                                      Map<String,Object> metadata)
This method gets a DetectorOutputStream that wraps the given stream. In addition to wrapOutputStream(OutputStream) an additional parameter metadata is supplied. If this context contains metadata values, that are mutable, the stream wrapper manipulates the data such that the given values correspond to the data.
E.g. if the metadata contains a title and a genre and the stream points to the data of an mp3 song, the given title and genre are written to the ID3 tag of the song (if supported by the implementation).
If the metadata contains values that are immutable and NOT compatible with the detected values (e.g. mimetype=text/plain is supplied, but mimetype is audio/midi) then the value will simple be overridden in the detected metadata.
If the metadata contains values that are unknown to the detector implementation (e.g. foo=bar), these values will also be untouched and are also available in the detected metadata.

Parameters:
stream - is the stream to wrap. This stream must be a fresh stream that is untouched since it was opened.
metadata - is the existing metadata to apply.
Returns:
the wrapped output stream.


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