Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "SMILA/Documentation/MimeTypeIdentifier"

(Overview)
(org.eclipse.smila.common.mimetype.impl)
Line 56: Line 56:
 
===org.eclipse.smila.common.mimetype.impl===
 
===org.eclipse.smila.common.mimetype.impl===
  
The default implementation can only identify mime types by a file extension. identification by <tt>byte[]</tt> is not supported. The mapping file <tt>mime.types</tt> (lacted inside the bundle) is used to map from file extension to mime type.
+
The default implementation can only identify mime types by a file extension. identification by <tt>byte[]</tt> is not supported. The mapping file <tt>mime.types</tt> (located inside the bundle) is used to map from file extension to mime type.
  
 
==== Configuration ====
 
==== Configuration ====
 
There are no configuration options available for this bundle.
 
There are no configuration options available for this bundle.

Revision as of 04:18, 19 September 2011

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 (located inside the bundle) is used to map from file extension to mime type.

Configuration

There are no configuration options available for this bundle.

Back to the top