Jump to: navigation, search

SMILA/Documentation/MimeTypeIdentifier

Overview

A MimeTypeIdentifier is an OSGi service which can be used to identify the mime type of a given byte[] or a file extension. The documentation of a pipelet which uses this service can be found here.

API

/**
 * Service interface to identify a MimeType.
 */
public interface MimeTypeIdentifier {
 
  /**
   * Identifies a MimeType based an the given data.
   * 
   * @param data
   *          a byte[] containing the data
   * @return the detected MimeType
   * @throws MimeTypeParseException
   *           if any error occurs
   */
  String identify(byte[] data) throws MimeTypeParseException;
 
  /**
   * Identifies a MimeType based an the file extension.
   * 
   * @param extension
   *          the extension of the filename
   * @return the detected MimeType
   * @throws MimeTypeParseException
   *           if any error occurs
   */
  String identify(String extension) throws MimeTypeParseException;
 
  /**
   * Identifies a MimeType based an the given data and file extension.
   * 
   * @param data
   *          a byte[] containing the data
   * @param extension
   *          the extension of the filename
   * @return the detected MimeType
   * @throws MimeTypeParseException
   *           if any error occurs
   */
  String identify(byte[] data, String extension) throws MimeTypeParseException;
}

Implementations

It is possible to provide different implementations for the MimeTypeIdentifier interface. In general it makes sense to only activate one MimeTypeIdentifier implementation at a time. This is achieved by simply starting just the bundle with the desired implementation. If multiple implementations are started a client using the MimeTypeIdentifier has to use a filter to select between the available implementations. Otherwise it gets a reference randomly. The component name could be used for filtering.

Below is a list of the currently available implementations.

org.eclipse.smila.common.mimetype.impl

The default implementation can only identify mime types by a file extension. identification by byte[] is not supported. The mapping file mime.types (lacted inside the bundle) is used to map from file extension to mime type.

Configuration

There are no configuration options available for this bundle.