/*
 * @(#)AmigaGuideRecognizer.java  1.1  2002-02-12
 *
 * Copyright (c) 2000-2002 Werner Randelshofer, Immensee, Switzerland.
 * All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the
 * license agreement you entered into with Werner Randelshofer.
 * For details see accompanying license terms.
 */
package ch.randelshofer.activation;

/**
 * This Recognizer recognizes Amiga-Guide files.
 *
 * @author  Werner Randelshofer, Hausmatt 10, CH-6405 Immensee, Switzerland.
 * @version 1.1 2002-02-12 Return 'application/octet-stream' if content type
 * can not be determined.
 * 1.0  2000-10-03
 */
public class AmigaGuideRecognizer
implements Recognizer {
    private final static AmigaGuideRecognizer instance = new AmigaGuideRecognizer();
    
    private AmigaGuideRecognizer() {}
    
    public static AmigaGuideRecognizer getInstance() {
        return instance;
    }
    /**
     * Return the number of bytes needed to
     * determine the content type.
     */
    @Override
    public int getMinimalDeterminableDataLength() {
        return 11;
    }
    
    /**
     * Return the base MIME Type of this data. This method is
     * expected to ALWAYS return a valid (non-null) MIME Type.
     *
     * @param  dataSnippet the first few bytes of the data file.
     * @return 'text/x-amigaguide' or application/octet-stream' if content type
     * can not be determined.
     */
    @Override
    public String getContentType(byte[] dataSnippet) {
        String magic = new String(dataSnippet, 0, 11);
        return magic.equals("@database \"") ? "text/x-amigaguide" : Recognizer.CONTENT_TYPE_OCTET_STREAM;
    }
}
