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

SMILA/Documentation/MimeTypeIdentifier

< SMILA‎ | Documentation
Revision as of 11:28, 3 June 2009 by Daniel.stucky.empolis.com (Talk | contribs) (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...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Overview

A MimeTypeIdentifier can identify the mime type of a given byte[] or a file extension.

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.

Back to the top