com.flexive.shared.media.impl
Class FxMediaNativeEngine

java.lang.Object
  extended by com.flexive.shared.media.impl.FxMediaNativeEngine

public class FxMediaNativeEngine
extends java.lang.Object

Java native Engine This engine relies on java image io and apache sanselan

Version:
$Rev: 704 $
Author:
Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)

Constructor Summary
FxMediaNativeEngine()
           
 
Method Summary
static java.lang.String detectMimeType(byte[] header, java.lang.String fileName)
          Detect the mimetype of a file based on the first n bytes and the filename
static org.apache.sanselan.ImageFormat getImageFormatByExtension(java.lang.String extension)
          Get the image format based on the extension
static org.apache.sanselan.ImageFormat getImageFormatByMimeType(java.lang.String mimeType)
          Get the image format based on the mime type
static FxMetadata identify(java.lang.String mimeType, java.io.File file)
          Identify a file, returning metadata
static java.awt.image.BufferedImage scale(java.awt.image.BufferedImage bi, int width, int height)
           
static int[] scale(java.io.File original, java.io.File scaled, java.lang.String extension, int width, int height)
          Scale an image and return the dimensions (width and height) as int array
static void streamingManipulate(byte[] data, java.io.OutputStream out, BinaryDownloadCallback callback, java.lang.String mimeType, FxMediaSelector selector)
          Manipulate image raw data and stream them back
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FxMediaNativeEngine

public FxMediaNativeEngine()
Method Detail

scale

public static int[] scale(java.io.File original,
                          java.io.File scaled,
                          java.lang.String extension,
                          int width,
                          int height)
                   throws FxApplicationException
Scale an image and return the dimensions (width and height) as int array

Parameters:
original - original file
scaled - scaled file
extension - extension
width - desired width
height - desired height
Returns:
actual width ([0]) and height ([1]) of scaled image
Throws:
FxApplicationException - on errors

scale

public static java.awt.image.BufferedImage scale(java.awt.image.BufferedImage bi,
                                                 int width,
                                                 int height)

getImageFormatByExtension

public static org.apache.sanselan.ImageFormat getImageFormatByExtension(java.lang.String extension)
Get the image format based on the extension

Parameters:
extension - image file extension
Returns:
ImageFormat (fallback to GIF if unknown)

getImageFormatByMimeType

public static org.apache.sanselan.ImageFormat getImageFormatByMimeType(java.lang.String mimeType)
Get the image format based on the mime type

Parameters:
mimeType - image mime type
Returns:
ImageFormat (fallback to GIF if unknown)

identify

public static FxMetadata identify(java.lang.String mimeType,
                                  java.io.File file)
                           throws FxApplicationException
Identify a file, returning metadata

Parameters:
mimeType - if not null it will be used to call the correct identify routine
file - the file to identify
Returns:
metadata
Throws:
FxApplicationException - on errors

streamingManipulate

public static void streamingManipulate(byte[] data,
                                       java.io.OutputStream out,
                                       BinaryDownloadCallback callback,
                                       java.lang.String mimeType,
                                       FxMediaSelector selector)
                                throws FxApplicationException
Manipulate image raw data and stream them back

Parameters:
data - raw image data
out - stream
callback - optional callback to set mimetype and size
mimeType - mimetype
selector - operations to apply
Throws:
FxApplicationException - on errors

detectMimeType

public static java.lang.String detectMimeType(byte[] header,
                                              java.lang.String fileName)
Detect the mimetype of a file based on the first n bytes and the filename

Parameters:
header - first n bytes of the file to examine
fileName - filename
Returns:
detected mimetype