1 package jp.sourceforge.stigmata.birthmarks;
3 import java.io.ByteArrayInputStream;
4 import java.io.InputStream;
6 import jp.sourceforge.stigmata.Birthmark;
7 import jp.sourceforge.stigmata.BirthmarkContext;
8 import jp.sourceforge.stigmata.BirthmarkExtractionFailedException;
9 import jp.sourceforge.stigmata.BirthmarkExtractor;
10 import jp.sourceforge.stigmata.ExtractionUnit;
11 import jp.sourceforge.stigmata.spi.BirthmarkService;
14 * Abstract class for extracting birthmark.
15 * @author Haruaki TAMADA
17 public abstract class AbstractBirthmarkExtractor implements BirthmarkExtractor{
21 private BirthmarkService spi;
24 * default constructor.
25 * @deprecated this constructor does not support service provider.
27 public AbstractBirthmarkExtractor(){
32 * @param spi service provider.
34 public AbstractBirthmarkExtractor(BirthmarkService spi){
39 * returns the provider of this extractor.
42 public BirthmarkService getProvider(){
47 * extract birthmark given stream with given environment.
50 public final Birthmark extract(InputStream in, BirthmarkContext context) throws BirthmarkExtractionFailedException{
51 return extract(createBirthmark(), in, context);
55 * extract birthmark given byte array with given environment.
58 public final Birthmark extract(Birthmark birthmark, byte[] bytecode, BirthmarkContext context) throws BirthmarkExtractionFailedException{
59 return extract(birthmark, new ByteArrayInputStream(bytecode), context);
63 * extract birthmark given byte array with given environment.
66 public final Birthmark extract(byte[] bytecode, BirthmarkContext context) throws BirthmarkExtractionFailedException{
67 return extract(createBirthmark(), new ByteArrayInputStream(bytecode), context);
71 * extract birthmark given stream with given environment.
74 public abstract Birthmark extract(Birthmark birthmark, InputStream in, BirthmarkContext context) throws BirthmarkExtractionFailedException;
78 * @see jp.sourceforge.stigmata.BirthmarkExtractor#createBirthmark()
81 public Birthmark createBirthmark(){
82 return new PlainBirthmark(getProvider().getType());
86 public abstract ExtractionUnit[] getAcceptableUnits();
89 public boolean isAcceptable(ExtractionUnit unit){
90 ExtractionUnit[] units = getAcceptableUnits();
92 for(int i = 0; i < units.length; i++){