Author: abelevich
Date: 2009-04-07 08:28:02 -0400 (Tue, 07 Apr 2009)
New Revision: 13404
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ImageLoader.java
Log:
change images rendering. without buffered image creation
Modified:
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ImageLoader.java
===================================================================
---
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ImageLoader.java 2009-04-06
23:43:26 UTC (rev 13403)
+++
trunk/test-applications/realworld2/web/src/main/java/org/richfaces/realworld/util/ImageLoader.java 2009-04-07
12:28:02 UTC (rev 13404)
@@ -24,13 +24,20 @@
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
+import java.util.Iterator;
import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageInputStream;
+import javax.imageio.stream.ImageOutputStream;
+import org.apache.commons.collections.BufferUtils;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
@@ -65,20 +72,22 @@
imageResource = fileManager.getFileByPath(data.toString());
}
if (imageResource != null && imageResource.exists()) {
- FileInputStream fileInputStream = new FileInputStream(imageResource);
-
- BufferedInputStream bufferedInputStream = new
BufferedInputStream(fileInputStream);
- InputStream paintData = bufferedInputStream;
- try {
- //TODO nick - pass-through writing will save us large amount of CPU time
and images quality
- BufferedImage images = ImageIO.read(paintData);
- ImageIO.write(images, Constants.JPEG, out);
- } catch (Exception e) {
- //TODO nick - any particular reason to catch not to take the whole method
body into try/catch?
- Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT,
FILE_PROCESSING_ERROR);
- } finally {
- bufferedInputStream.close();
- }
+
+ byte [] toWrite = new byte[8192];
+
+ ImageInputStream inputStream = ImageIO.createImageInputStream(imageResource);
+ ImageOutputStream outputStream = ImageIO.createImageOutputStream(out);
+
+ try {
+ while(inputStream.read(toWrite) != -1) {
+ outputStream.write(toWrite);
+ }
+
+ } finally {
+ outputStream.close();
+ inputStream.close();
+ }
+
}else{
Events.instance().raiseEvent("stopSlideshow");
Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, "Images was
deleted. Sorry");
Show replies by date