net.sf.mmm.util.io.api.spi
Interface DetectorStreamProcessorFactory

All Known Implementing Classes:
AbstractDetectorStreamProcessorFactory, SimpleDetectorStreamProcessorFactory

public interface DetectorStreamProcessorFactory

This is interface represents a factory of specific DetectorStreamProcessors.

Since:
1.1.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
DetectorStream

Method Summary
 DetectorStreamProcessor createProcessor()
          This method gets a DetectorStreamProcessor instance managed by this factory.
 int getLookaheadCount()
          This method determines the required number of bytes a DetectorStreamProcessor needs as lookahead in order to make its decisions.
 

Method Detail

getLookaheadCount

int getLookaheadCount()
This method determines the required number of bytes a DetectorStreamProcessor needs as lookahead in order to make its decisions. The DetectorStream will use the maximum required lookahead of all registered processor-factories.
NOTE:
To prevent waste of memory, you should NOT use a lookahead higher than necessary. However you should NOT worry about values below 1024.
As a stupid example we assume a DetectorStreamProcessor wants to figure out if some file contains the ASCII-bytes '<?xml' or '<html'. Therefore he requires a lookahead of 5. If he consumes all data until a '<' is reached (@see ByteIterator.peek()), he can check if 4 more bytes are available. In that case he can consume all these bytes and make its decision. Otherwise he returns from DetectorStreamProcessor.process(DetectorStreamBuffer, java.util.Map, boolean) and waits for the next call that will guarantee the buffer is refilled with at least the specified lookahead.

Returns:
the required lookahead in bytes.

createProcessor

DetectorStreamProcessor createProcessor()
This method gets a DetectorStreamProcessor instance managed by this factory. Typically the factory will create a new instance per request. However if a DetectorStreamProcessor is thread-safe the factory can always return the same instance.

Returns:
the requested DetectorStreamProcessor instance.


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