You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2008/12/03 09:06:44 UTC
svn commit: r722804 - in
/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader:
impl/ImageRawEPS.java impl/ImageRawStream.java
pipeline/ImageProviderPipeline.java
Author: jeremias
Date: Wed Dec 3 00:06:44 2008
New Revision: 722804
URL: http://svn.apache.org/viewvc?rev=722804&view=rev
Log:
Made it possible to create cacheable EPS images inside image converters.
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawEPS.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawEPS.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawEPS.java?rev=722804&r1=722803&r2=722804&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawEPS.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawEPS.java Wed Dec 3 00:06:44 2008
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,19 +27,28 @@
/**
* This class is an implementation of the Image interface exposing EPS file. It provides an
- * InputStream to access the EPS content and the decoded high-res bounding box.
+ * InputStream to access the EPS content and the decoded high-res bounding box.
*/
public class ImageRawEPS extends ImageRawStream {
/**
* Main constructor.
* @param info the image info object
+ * @param streamFactory the InputStreamFactory that is used to create InputStream instances
+ */
+ public ImageRawEPS(ImageInfo info, InputStreamFactory streamFactory) {
+ super(info, ImageFlavor.RAW_EPS, streamFactory);
+ }
+
+ /**
+ * Main constructor.
+ * @param info the image info object
* @param in the InputStream with the raw content
*/
public ImageRawEPS(ImageInfo info, InputStream in) {
super(info, ImageFlavor.RAW_EPS, in);
}
-
+
/**
* Returns the bounding box of the EPS image.
* @return the bounding box
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java?rev=722804&r1=722803&r2=722804&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRawStream.java Wed Dec 3 00:06:44 2008
@@ -19,6 +19,7 @@
package org.apache.xmlgraphics.image.loader.impl;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -195,4 +196,36 @@
}
+ /**
+ * InputStream factory that wraps a byte array.
+ */
+ public static class ByteArrayStreamFactory implements InputStreamFactory {
+
+ private byte[] data;
+
+ /**
+ * Main constructor.
+ * @param data the byte array
+ */
+ public ByteArrayStreamFactory(byte[] data) {
+ this.data = data;
+ }
+
+ /** {@inheritDoc} */
+ public InputStream createInputStream() {
+ return new ByteArrayInputStream(data);
+ }
+
+ /** {@inheritDoc} */
+ public void close() {
+ //nop
+ }
+
+ /** {@inheritDoc} */
+ public boolean isUsedOnceOnly() {
+ return false;
+ }
+
+ }
+
}
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java?rev=722804&r1=722803&r2=722804&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/pipeline/ImageProviderPipeline.java Wed Dec 3 00:06:44 2008
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,10 +16,9 @@
*/
/* $Id$ */
-
+
package org.apache.xmlgraphics.image.loader.pipeline;
-import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -54,7 +53,7 @@
private ImageCache cache;
private ImageLoader loader;
private List converters = new java.util.ArrayList();
-
+
/**
* Main constructor.
* @param cache the image cache (may be null if no caching is desired)
@@ -64,7 +63,7 @@
this.cache = cache;
setImageLoader(loader);
}
-
+
/**
* Constructor for operation without caching.
* @param loader the image loader to drive the pipeline with
@@ -72,7 +71,7 @@
public ImageProviderPipeline(ImageLoader loader) {
this(null, loader);
}
-
+
/**
* Default constructor without caching and without an ImageLoader (or the ImageLoader may
* be set later).
@@ -80,7 +79,7 @@
public ImageProviderPipeline() {
this(null, null);
}
-
+
/**
* Executes the image converter pipeline. First, the image indicated by the ImageInfo instance
* is loaded through an ImageLoader and then optionally converted by a series of
@@ -97,7 +96,7 @@
throws ImageException, IOException {
return execute(info, null, hints, context);
}
-
+
/**
* Executes the image converter pipeline. First, the image indicated by the ImageInfo instance
* is loaded through an ImageLoader and then optionally converted by a series of
@@ -120,10 +119,10 @@
long start, duration;
start = System.currentTimeMillis();
Image img = null;
-
+
//Remember the last image in the pipeline that is cacheable and cache that.
Image lastCacheableImage = null;
-
+
int converterCount = converters.size();
int startingPoint = 0;
if (cache != null) {
@@ -136,7 +135,7 @@
break;
}
}
-
+
if (img == null && loader != null) {
//try target flavor of loader from cache
ImageFlavor flavor = loader.getTargetFlavor();
@@ -146,7 +145,7 @@
if (img == null && originalImage != null) {
img = originalImage;
}
-
+
boolean entirelyInCache = true;
if (img == null && loader != null) {
//Load image
@@ -155,7 +154,7 @@
duration = System.currentTimeMillis() - start;
log.trace("Image loading using " + loader + " took " + duration + " ms.");
}
-
+
//Caching
entirelyInCache = false;
if (img.isCacheable()) {
@@ -166,7 +165,7 @@
throw new ImageException(
"Pipeline fails. No ImageLoader and no original Image available.");
}
-
+
if (converterCount > 0) {
for (int i = startingPoint; i < converterCount; i++) {
ImageConverter converter = getConverter(i);
@@ -176,7 +175,7 @@
duration = System.currentTimeMillis() - start;
log.trace("Image conversion using " + converter + " took " + duration + " ms.");
}
-
+
//Caching
entirelyInCache = false;
if (img.isCacheable()) {
@@ -222,7 +221,7 @@
if (log.isDebugEnabled()) {
log.debug("Image is made cacheable: " + img.getInfo());
}
-
+
//Read the whole stream and hold it in memory so the image can be cached
ByteArrayOutputStream baout = new ByteArrayOutputStream();
InputStream in = raw.createInputStream();
@@ -232,27 +231,12 @@
IOUtils.closeQuietly(in);
}
final byte[] data = baout.toByteArray();
-
- raw.setInputStreamFactory(new ImageRawStream.InputStreamFactory() {
-
- public void close() {
- //nop
- }
-
- public InputStream createInputStream() {
- return new ByteArrayInputStream(data);
- }
-
- public boolean isUsedOnceOnly() {
- return false;
- }
-
- });
+ raw.setInputStreamFactory(new ImageRawStream.ByteArrayStreamFactory(data));
return raw;
}
return null;
}
-
+
/**
* Sets the ImageLoader that is used at the beginning of the pipeline if the image is not
* loaded, yet.
@@ -261,7 +245,7 @@
public void setImageLoader(ImageLoader imageLoader) {
this.loader = imageLoader;
}
-
+
/**
* Adds an additional ImageConverter to the end of the pipeline.
* @param converter the ImageConverter instance
@@ -313,5 +297,5 @@
return null;
}
}
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org