Difference between revisions of "SMILA/Documentation/MimeTypeIdentifier"

From Eclipsepedia

Jump to: navigation, search
(New page: == Overview == A MimeTypeIdentifier can identify the mime type of a given <tt>byte[]</tt> or a file extension. == API == <source lang="java"> /** * Service interface to identify a Mime...)
 
(Overview)
Line 1: Line 1:
 
== Overview ==
 
== Overview ==
  
A MimeTypeIdentifier can identify the mime type of a given <tt>byte[]</tt> or a file extension.
+
A MimeTypeIdentifier is an OSGi service which can be used to identify the mime type of a given <tt>byte[]</tt> or a file extension. The documentation of a pipelet which uses this service can be found [http://wiki.eclipse.org/SMILA/Documentation/Bundle_org.eclipse.smila.processing.pipelets#Bundle:_org.eclipse.smila.processing.pipelets.MimeTypeIdentifyPipelet here].
  
 
== API ==
 
== API ==

Revision as of 10:00, 14 June 2011

Contents

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.