net.sf.mmm.util.io.base
Class AbstractDetectorStreamProcessorFactory

java.lang.Object
  extended by net.sf.mmm.util.io.base.AbstractDetectorStreamProcessorFactory
All Implemented Interfaces:
DetectorStreamProcessorFactory
Direct Known Subclasses:
SimpleDetectorStreamProcessorFactory

public abstract class AbstractDetectorStreamProcessorFactory
extends Object
implements DetectorStreamProcessorFactory

This is the abstract base implementation of the DetectorStreamProcessorFactory interface.

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

Constructor Summary
AbstractDetectorStreamProcessorFactory()
          The constructor.
 
Method Summary
 int getLookaheadCount()
          This method determines the required number of bytes a DetectorStreamProcessor needs as lookahead in order to make its decisions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.mmm.util.io.api.spi.DetectorStreamProcessorFactory
createProcessor
 

Constructor Detail

AbstractDetectorStreamProcessorFactory

public AbstractDetectorStreamProcessorFactory()
The constructor.

Method Detail

getLookaheadCount

public 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.

Specified by:
getLookaheadCount in interface DetectorStreamProcessorFactory
Returns:
the required lookahead in bytes.


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