package mircoders.entity;
-import mir.log.LoggerWrapper;
-import mir.storage.StorageObjectFailure;
-import mir.util.StreamCopier;
-import mircoders.media.ImageProcessor;
-
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.sql.SQLException;
-/**
- *
- * @author RK, mh, mir-coders
- * @version $Id: EntityImages.java,v 1.21.2.7 2005/01/23 15:36:04 zapata Exp $
- */
-
+import mir.log.LoggerWrapper;
+import mir.storage.DatabaseFailure;
+import mir.util.StreamCopier;
+import mir.media.image.ImageProcessor;
+// FIXME: delete this when finished testing ImageMagickImageProcessor
+//import mir.media.image.JAIImageProcessor;
+import mir.media.image.ImageMagickImageProcessor;
public class EntityImages extends EntityUploadedMedia
{
/**
* Retrieves the image data
*/
- public InputStream getImage() throws StorageObjectFailure {
+ public byte[] getImage() throws DatabaseFailure {
try {
return database.getBinaryField("select image_data from images where id="+getId());
}
catch (SQLException e) {
- throw new StorageObjectFailure(e);
+ throw new DatabaseFailure(e);
}
}
/**
* Processes and saves image data
*/
- public void setImage(InputStream anInputStream, String type) throws StorageObjectFailure {
+ public void setImage(InputStream anInputStream, String type) throws DatabaseFailure {
if (anInputStream != null) {
try {
- ByteArrayOutputStream inputData = new ByteArrayOutputStream();
- StreamCopier.copy(anInputStream, inputData);
+ // FIXME: delete this when finished testing ImageMagickImageProcessor
+ //ByteArrayOutputStream inputData = new ByteArrayOutputStream();
+ //StreamCopier.copy(anInputStream, inputData);
- ImageProcessor processor = new ImageProcessor(inputData.toByteArray());
+ ImageProcessor processor = new ImageMagickImageProcessor(anInputStream);
+ // FIXME: delete this when finished testing ImageMagickImageProcessor
+ //ImageProcessor processor = new JAIImageProcessor(inputData.toByteArray());
processor.descaleImage(maxImageSize, minDescaleRatio, minDescaleReduction);
ByteArrayOutputStream imageData = new ByteArrayOutputStream();
setFieldValue("icon_height", new Integer(processor.getScaledHeight()).toString());
setFieldValue("icon_width", new Integer(processor.getScaledWidth()).toString());
-
+ processor.cleanup();
update();
}
catch (Exception e) {
- throw new StorageObjectFailure(e);
+ throw new DatabaseFailure(e);
}
}
}
*
* It will also take care of closing the OutputStream.
*/
- public InputStream getIcon() throws StorageObjectFailure {
+ public byte[] getIcon() throws DatabaseFailure {
try {
return database.getBinaryField("select icon_data from images where id="+getId());
}
catch (SQLException e) {
- throw new StorageObjectFailure(e);
+ throw new DatabaseFailure(e);
}
}
}