import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
-import org.w3c.dom.*;
-
import java.util.HashMap;
+import java.io.InputStream;
+
+import org.w3c.dom.Document;
/**
* The User Agent for fo.
return base;
}
+ /**
+ * Get an input stream for a reference.
+ * Temporary solution until API better.
+ */
+ public InputStream getStream(String uri) {
+ return null;
+ }
+
public float getPixelUnitToMillimeter() {
return 0.35277777777777777778f;
}
import java.net.URL;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_Profile;
+import java.io.InputStream;
// FOP
import org.apache.fop.pdf.PDFColor;
protected int m_height = 0;
/**
- * Image URL.
+ * Image input stream.
*/
- protected URL m_href = null;
+ protected InputStream inputStream = null;
/**
* ImageReader object (to obtain image header informations).
* <LI>image height
* </UL>
* The image data isn't kept in memory.
- * @param href image URL
+ * @param input input stream
* imgReader ImageReader object
* @return a new FopImage object
*/
- public AbstractFopImage(URL href, FopImage.ImageInfo info) {
- this.m_href = href;
+ public AbstractFopImage(FopImage.ImageInfo info) {
+ this.inputStream = info.inputStream;
this.imageInfo = info;
if(this.imageInfo.width != -1) {
m_width = imageInfo.width;
return false;
}
- /**
- * Return the image URL.
- * @return the image URL (as String)
- */
- public String getURL() {
- return this.m_href.toString();
- }
-
/**
* Return the image width.
* @return the image width
return this.m_colorSpace;
}
+ /**
+ * Get ICC profile for this image.
+ */
public ICC_Profile getICCProfile() {
return null;
}
import org.apache.fop.fo.FOUserAgent;
public class BmpImage extends AbstractFopImage {
- public BmpImage(URL href, FopImage.ImageInfo imgReader) {
- super(href, imgReader);
+ public BmpImage(FopImage.ImageInfo imgReader) {
+ super(imgReader);
}
protected boolean loadBitmap(FOUserAgent ua) {
int hpos = 22; // offset positioning for w and height in bmp files
int[] headermap = new int[54];
int filepos = 0;
- InputStream file = null;
byte palette[] = null;
try {
- file = this.m_href.openStream();
boolean eof = false;
while ((!eof) && (filepos < 54)) {
- int input = file.read();
+ int input = inputStream.read();
if (input == -1)
eof = true;
else
while (!eof && countr < palettesize) {
int count2 = 2;
while (!eof && count2 >= -1) {
- int input = file.read();
+ int input = inputStream.read();
if (input == -1)
eof = true;
else if (count2 >= 0) {
}
} catch (IOException e) {
ua.getLogger().error("Error while loading image "
- + this.m_href.toString() + " : "
+ + "" + " : "
+ e.getClass() + " - "
+ e.getMessage(), e);
return false;
else if (this.m_bitsPerPixel == 4 || this.m_bitsPerPixel == 8)
bytes = this.m_width / (8 / this.m_bitsPerPixel);
else {
- ua.getLogger().error("Image (" + this.m_href.toString()
+ ua.getLogger().error("Image (" + ""
+ ") has " + this.m_bitsPerPixel
+ " which is not a supported BMP format.");
return false;
try {
int input;
int count = 0;
- file.skip((long)(imagestart - filepos));
- while ((input = file.read()) != -1)
+ inputStream.skip((long)(imagestart - filepos));
+ while ((input = inputStream.read()) != -1)
temp[count++] = input;
- file.close();
+ inputStream.close();
+ inputStream = null;
} catch (IOException e) {
ua.getLogger().error("Error while loading image "
- + this.m_href.toString() + " : "
+ + "" + " : "
+ e.getClass() + " - "
+ e.getMessage(), e);
return false;
/**
* Initialize docName and bounding box
*/
- private void init(URL href) {
+ private void init(String name) {
bbox = new int[4];
bbox[0] = 0;
bbox[1] = 0;
bbox[2] = 0;
bbox[3] = 0;
- docName = href.toString();
+ docName = name;
}
/**
return bbox;
}
- public EPSImage(URL href, FopImage.ImageInfo imgInfo) {
- super(href, imgInfo);
- init(href);
+ public EPSImage(FopImage.ImageInfo imgInfo) {
+ super(imgInfo);
+ init("");
if (imgInfo.data instanceof EPSData) {
epsData = (EPSData) imgInfo.data;
bbox = new int[4];
*/
public boolean load(int type, FOUserAgent ua);
- // Ressource location
- public String getURL();
-
// image size
public int getWidth();
public int getHeight();
public int getRessourceBytesSize();
public static class ImageInfo {
- public InputStream stream;
+ public InputStream inputStream;
public int width;
public int height;
public Object data;
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.awt.color.ColorSpace;
+import java.io.InputStream;
// FOP
import org.apache.fop.pdf.PDFColor;
* @see FopImage
*/
public class GifImage extends AbstractFopImage {
- public GifImage(URL href, FopImage.ImageInfo imgReader) {
- super(href, imgReader);
+ public GifImage(FopImage.ImageInfo imgReader) {
+ super(imgReader);
}
protected boolean loadBitmap(FOUserAgent ua) {
int[] tmpMap = null;
+
try {
- ImageProducer ip = (ImageProducer) this.m_href.getContent();
+ ImageProducer ip = null;
+ // todo: how to load gif image from stream
+ //ip = (ImageProducer) inputStream.getContent();
+ inputStream.close();
+ inputStream = null;
FopImageConsumer consumer = new FopImageConsumer(ip);
ip.startProduction(consumer);
} else if (transparencyType ==
java.awt.Transparency.BITMASK) {
if (cm instanceof IndexColorModel) {
+ IndexColorModel indexcm = (IndexColorModel) cm;
this.m_isTransparent = false;
- byte[] alphas = new byte[
- ((IndexColorModel) cm).getMapSize()];
- byte[] reds = new byte[
- ((IndexColorModel) cm).getMapSize()];
- byte[] greens = new byte[
- ((IndexColorModel) cm).getMapSize()];
- byte[] blues = new byte[
- ((IndexColorModel) cm).getMapSize()];
- ((IndexColorModel) cm).getAlphas(alphas);
- ((IndexColorModel) cm).getReds(reds);
- ((IndexColorModel) cm).getGreens(greens);
- ((IndexColorModel) cm).getBlues(blues);
+ byte[] alphas = new byte[indexcm.getMapSize()];
+ byte[] reds = new byte[indexcm.getMapSize()];
+ byte[] greens = new byte[indexcm.getMapSize()];
+ byte[] blues = new byte[indexcm.getMapSize()];
+ indexcm.getAlphas(alphas);
+ indexcm.getReds(reds);
+ indexcm.getGreens(greens);
+ indexcm.getBlues(blues);
for (int i = 0;
- i < ((IndexColorModel) cm).getMapSize();
+ i < indexcm.getMapSize();
i++) {
if ((alphas[i] & 0xFF) == 0) {
this.m_isTransparent = true;
}
} catch (Exception ex) {
ua.getLogger().error("Error while loading image "
- + this.m_href.toString() + " : "
+ + "" + " : "
+ ex.getClass() + " - "
+ ex.getMessage(), ex);
return false;
// Java
import java.io.IOException;
import java.io.InputStream;
+import java.io.BufferedInputStream;
import java.io.File;
import java.net.URL;
import java.net.MalformedURLException;
*/
// Get the absolute URL
URL absoluteURL = null;
- InputStream imgIS = null;
href = href.trim();
if (href.startsWith("url(") && (href.indexOf(")") != -1)) {
href = href.substring(4, href.indexOf(")")).trim();
protected static FopImage loadImage(String href, String baseURL,
FOUserAgent ua) {
Logger log = ua.getLogger();
+
+ InputStream imgIS = openStream(href, baseURL, ua);
+
+ // If not, check image type
+ FopImage.ImageInfo imgInfo = null;
+ try {
+ imgInfo = ImageReaderFactory.make(
+ href, imgIS, ua);
+ } catch (Exception e) {
+ log.error("Error while recovering Image Informations (" +
+ href + ") : " + e.getMessage(), e);
+ return null;
+ }
+ if (imgInfo == null) {
+ try {
+ imgIS.close();
+ imgIS = null;
+ } catch (Exception e) {
+ }
+ log.error("No ImageReader for this type of image (" +
+ href + ")");
+ return null;
+ }
+ // Associate mime-type to FopImage class
+ String imgMimeType = imgInfo.mimeType;
+ String imgClassName = getImageClassName(imgMimeType);
+ if (imgClassName == null) {
+ log.error("Unsupported image type (" +
+ href + ") : " + imgMimeType);
+ return null;
+ }
+
+ // load the right image class
+ // return new <FopImage implementing class>
+ Object imageInstance = null;
+ Class imageClass = null;
+ try {
+ imageClass = Class.forName(imgClassName);
+ Class[] imageConstructorParameters = new Class[1];
+ imageConstructorParameters[0] = org.apache.fop.image.FopImage.ImageInfo.class;
+ Constructor imageConstructor =
+ imageClass.getDeclaredConstructor(
+ imageConstructorParameters);
+ Object[] initArgs = new Object[1];
+ initArgs[0] = imgInfo;
+ imageInstance = imageConstructor.newInstance(initArgs);
+ } catch (java.lang.reflect.InvocationTargetException ex) {
+ Throwable t = ex.getTargetException();
+ String msg;
+ if (t != null) {
+ msg = t.getMessage();
+ } else {
+ msg = ex.getMessage();
+ }
+ log.error("Error creating FopImage object (" +
+ href + ") : " + msg, (t == null) ? ex:t);
+ return null;
+ }
+ catch (Exception ex) {
+ log.error("Error creating FopImage object (" +
+ href + ") : " + ex.getMessage(), ex);
+ return null;
+ }
+ if (!(imageInstance instanceof org.apache.fop.image.FopImage)) {
+ log.error("Error creating FopImage object (" +
+ href + ") : " + "class " +
+ imageClass.getName() + " doesn't implement org.apache.fop.image.FopImage interface");
+ return null;
+ }
+ return (FopImage) imageInstance;
+ }
+
+ /**
+ * create an FopImage objects.
+ * @param href image URL as a String
+ * @return a new FopImage object
+ */
+ protected static InputStream openStream(String href, String baseURL,
+ FOUserAgent ua) {
+ Logger log = ua.getLogger();
// Get the absolute URL
URL absoluteURL = null;
- InputStream imgIS = null;
+ InputStream imgIS = ua.getStream(href);
+ if(imgIS != null) {
+ return imgIS;
+ }
try {
// try url as complete first, this can cause
// a problem with relative uri's if there is an
}
}
+ BufferedInputStream bis = null;
// If not, check image type
FopImage.ImageInfo imgInfo = null;
try {
if (imgIS == null) {
imgIS = absoluteURL.openStream();
}
- imgInfo = ImageReaderFactory.make(
- absoluteURL.toExternalForm(), imgIS, ua);
+ bis = new BufferedInputStream(imgIS);
} catch (Exception e) {
- log.error("Error while recovering Image Informations (" +
- absoluteURL.toString() + ") : " + e.getMessage(), e);
+ log.error("Error while opening stream for (" +
+ href + ") : " + e.getMessage(), e);
return null;
}
- finally { if (imgIS != null) {
- try {
- imgIS.close();
- } catch (IOException e) {}
- }
- } if (imgInfo == null) {
- log.error("No ImageReader for this type of image (" +
- absoluteURL.toString() + ")");
- return null;
- }
- // Associate mime-type to FopImage class
- String imgMimeType = imgInfo.mimeType;
+ return bis;
+ }
+
+ private static String getImageClassName(String imgMimeType) {
String imgClassName = null;
if ("image/gif".equals(imgMimeType)) {
imgClassName = "org.apache.fop.image.GifImage";
} else if ("text/xml".equals(imgMimeType)) {
imgClassName = "org.apache.fop.image.XMLImage";
}
- if (imgClassName == null) {
- log.error("Unsupported image type (" +
- absoluteURL.toString() + ") : " + imgMimeType);
- return null;
- }
-
- // load the right image class
- // return new <FopImage implementing class>
- Object imageInstance = null;
- Class imageClass = null;
- try {
- imageClass = Class.forName(imgClassName);
- Class[] imageConstructorParameters = new Class[2];
- imageConstructorParameters[0] = java.net.URL.class;
- imageConstructorParameters[1] = org.apache.fop.image.FopImage.ImageInfo.class;
- Constructor imageConstructor =
- imageClass.getDeclaredConstructor(
- imageConstructorParameters);
- Object[] initArgs = new Object[2];
- initArgs[0] = absoluteURL;
- initArgs[1] = imgInfo;
- imageInstance = imageConstructor.newInstance(initArgs);
- } catch (java.lang.reflect.InvocationTargetException ex) {
- Throwable t = ex.getTargetException();
- String msg;
- if (t != null) {
- msg = t.getMessage();
- } else {
- msg = ex.getMessage();
- }
- log.error("Error creating FopImage object (" +
- absoluteURL.toString() + ") : " + msg, (t == null) ? ex:t);
- return null;
- }
- catch (Exception ex) {
- log.error("Error creating FopImage object (" +
- absoluteURL.toString() + ") : " + ex.getMessage(), ex);
- return null;
- }
- if (!(imageInstance instanceof org.apache.fop.image.FopImage)) {
- log.error("Error creating FopImage object (" +
- absoluteURL.toString() + ") : " + "class " +
- imageClass.getName() + " doesn't implement org.apache.fop.image.FopImage interface");
- return null;
- }
- return (FopImage) imageInstance;
+ return imgClassName;
}
-
}
class BasicImageCache implements ImageCache {
// Java
import java.net.URL;
import java.io.InputStream;
-import java.io.BufferedInputStream;
+import java.io.InputStream;
// AWT
import java.awt.image.ColorModel;
*/
public class JAIImage extends AbstractFopImage {
- public JAIImage(URL href, FopImage.ImageInfo imgReader) {
- super(href, imgReader);
+ public JAIImage(FopImage.ImageInfo imgReader) {
+ super(imgReader);
}
protected void loadImage() {
try {
- InputStream inputStream = this.m_href.openStream();
- /*
- * BufferedInputStream inputStream = this.m_imageReader.getInputStream();
- * inputStream.reset();
- */
com.sun.media.jai.codec.FileCacheSeekableStream seekableInput =
new FileCacheSeekableStream(inputStream);
RenderedOp imageOp = JAI.create("stream", seekableInput);
+ inputStream.close();
+ inputStream = null;
this.m_height = imageOp.getHeight();
this.m_width = imageOp.getWidth();
}
catch (Exception ex) {
/*throw new FopImageException("Error while loading image "
- + this.m_href.toString() + " : "
+ + "" + " : "
+ ex.getClass() + " - "
+ ex.getMessage());
*/}
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.awt.color.ColorSpace;
+import java.io.InputStream;
// Jimi
import com.sun.jimi.core.*;
* @see FopImage
*/
public class JimiImage extends AbstractFopImage {
- public JimiImage(URL href, FopImage.ImageInfo imgReader) {
- super(href, imgReader);
+ public JimiImage(FopImage.ImageInfo imgReader) {
+ super(imgReader);
try {
Class c = Class.forName("com.sun.jimi.core.Jimi");
} catch (ClassNotFoundException e) {
int[] tmpMap = null;
try {
ImageProducer ip =
- Jimi.getImageProducer(this.m_href.openStream(),
+ Jimi.getImageProducer(inputStream,
Jimi.SYNCHRONOUS | Jimi.IN_MEMORY);
FopImageConsumer consumer = new FopImageConsumer(ip);
ip.startProduction(consumer);
this.m_height = consumer.getHeight();
this.m_width = consumer.getWidth();
+ inputStream.close();
+ inputStream = null;
+
try {
tmpMap = consumer.getImage();
} catch (Exception ex) {
}
} catch (Throwable ex) {
log.error("Error while loading image "
- + this.m_href.toString(), ex);
+ + "", ex);
return;
}
boolean found_icc_profile = false;
boolean found_dimensions = false;
- public JpegImage(URL href, FopImage.ImageInfo imgReader) {
- super(href, imgReader);
+ public JpegImage(FopImage.ImageInfo imgReader) {
+ super(imgReader);
}
protected boolean loadOriginalData(FOUserAgent ua) {
boolean cont = true;
try {
- inStream = this.m_href.openStream();
+ inStream = inputStream;
while ((bytes_read = inStream.read(readBuf)) != -1) {
baos.write(readBuf, 0, bytes_read);
}
+ inputStream.close();
+ inputStream = null;
} catch (java.io.IOException ex) {
ua.getLogger().error("Error while loading image " +
- this.m_href.toString() + " : " + ex.getClass() +
+ "" + " : " + ex.getClass() +
" - " + ex.getMessage(), ex);
return false;
}
ColorSpace.CS_CIEXYZ);
} else {
ua.getLogger().error("Unknown ColorSpace for image: "
- + this.m_href.toString());
+ + "");
return false;
}
}
} else {
ua.getLogger().error( "1 Error while loading image " +
- this.m_href.toString() +
+ "" +
" : JpegImage - Invalid JPEG Header.");
return false;
}
iccStream.write(align);
} catch (Exception e) {
ua.getLogger().error( "1 Error while loading image " +
- this.m_href.toString() + " : " +
+ "" + " : " +
e.getMessage(), e);
return false;
}
iccProfile = ICC_Profile.getInstance(iccStream.toByteArray());
} else if(this.m_colorSpace == null) {
ua.getLogger().error("ColorSpace not specified for image: "
- + this.m_href.toString());
+ + "");
return false;
}
return true;
// Java
import java.net.URL;
import org.w3c.dom.Document;
+import java.io.InputStream;
// FOP
import org.apache.fop.apps.Driver;
Document doc;
String ns = "";
- public XMLImage(URL href, FopImage.ImageInfo imgInfo) {
- super(href, imgInfo);
+ public XMLImage(FopImage.ImageInfo imgInfo) {
+ super(imgInfo);
if(imgInfo.data instanceof Document) {
doc = (Document)imgInfo.data;
loaded = loaded | ORIGINAL_DATA;
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.IOException;
// FOP
protected static final int BMP_SIG_LENGTH = 26;
/** @see org.apache.fop.image.analyser.ImageReader */
- public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream bis,
+ public FopImage.ImageInfo verifySignature(String uri, InputStream bis,
FOUserAgent ua) throws IOException {
byte[] header = getDefaultHeader(bis);
boolean supported = ((header[0] == (byte) 0x42)
&& (header[1] == (byte) 0x4d));
if (supported) {
- return getDimension(header);
+ FopImage.ImageInfo info = getDimension(header);
+ info.inputStream = bis;
+ return info;
} else {
return null;
}
return info;
}
- private byte[] getDefaultHeader(BufferedInputStream imageStream)
+ private byte[] getDefaultHeader(InputStream imageStream)
throws IOException {
byte[] header = new byte[BMP_SIG_LENGTH];
try {
return header;
}
-}
\ No newline at end of file
+}
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
private static final byte[] BOUNDINGBOX = "%%BoundingBox: ".getBytes();
/** @see org.apache.fop.image.analyser.ImageReader */
- public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream bis,
+ public FopImage.ImageInfo verifySignature(String uri, InputStream bis,
FOUserAgent ua) throws IOException {
boolean isEPS = false;
if (data.bbox != null) {
info.width = (int) (data.bbox[2] - data.bbox[0]);
info.height = (int) (data.bbox[3] - data.bbox[1]);
+
+ // image data read
+ bis.close();
+ info.inputStream = null;
+
return info;
} else {
// Ain't eps if no BoundingBox
* @param data EPSData object to write the results to
* @exception IOException If an I/O error occurs
*/
- private void readEPSImage(BufferedInputStream bis, EPSImage.EPSData data)
+ private void readEPSImage(InputStream bis, EPSImage.EPSData data)
throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] file;
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.IOException;
// FOP
private static final int GIF_SIG_LENGTH = 10;
/** @see org.apache.fop.image.analyser.ImageReader */
- public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream bis,
+ public FopImage.ImageInfo verifySignature(String uri, InputStream bis,
FOUserAgent ua) throws IOException {
byte[] header = getDefaultHeader(bis);
boolean supported = ((header[0] == 'G')
if (supported) {
FopImage.ImageInfo info = getDimension(header);
info.mimeType = getMimeType();
+ info.inputStream = bis;
return info;
} else {
return null;
return info;
}
- private byte[] getDefaultHeader(BufferedInputStream imageStream)
+ private byte[] getDefaultHeader(InputStream imageStream)
throws IOException {
byte[] header = new byte[GIF_SIG_LENGTH];
try {
return header;
}
-}
\ No newline at end of file
+}
+
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.IOException;
// FOP
* @return <code>true</code> if image type is the handled one
* @exception IOException if an I/O error occurs
*/
- FopImage.ImageInfo verifySignature(String uri, BufferedInputStream bis,
+ FopImage.ImageInfo verifySignature(String uri, InputStream bis,
FOUserAgent ua)
throws IOException;
// Java
import java.io.InputStream;
-import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
FOUserAgent ua) {
ImageReader reader;
- BufferedInputStream bis = new BufferedInputStream(in);
try {
for (int count = 0; count < formats.size(); count++) {
reader = (ImageReader) formats.get(count);
- FopImage.ImageInfo info = reader.verifySignature(uri, bis, ua);
+ FopImage.ImageInfo info = reader.verifySignature(uri, in, ua);
if (info != null) {
return info;
}
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.IOException;
// FOP
private static final int JPG_SIG_LENGTH = 2;
/** @see org.apache.fop.image.analyser.ImageReader */
- public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
+ public FopImage.ImageInfo verifySignature(String uri, InputStream fis,
FOUserAgent ua) throws IOException {
byte[] header = getDefaultHeader(fis);
boolean supported = ((header[0] == (byte) 0xff)
if (supported) {
FopImage.ImageInfo info = getDimension(fis);
info.mimeType = getMimeType();
+ info.inputStream = fis;
return info;
} else {
return null;
return "image/jpeg";
}
- private byte[] getDefaultHeader(BufferedInputStream imageStream) throws IOException {
+ private byte[] getDefaultHeader(InputStream imageStream) throws IOException {
byte[] header = new byte[JPG_SIG_LENGTH];
try {
imageStream.mark(JPG_SIG_LENGTH + 1);
return header;
}
- private FopImage.ImageInfo getDimension(BufferedInputStream imageStream) throws IOException {
+ private FopImage.ImageInfo getDimension(InputStream imageStream) throws IOException {
FopImage.ImageInfo info = new FopImage.ImageInfo();
try {
+ imageStream.mark(imageStream.available());
int marker = NULL;
long length, skipped;
- outer:
+outer:
while (imageStream.available() > 0) {
while ((marker = imageStream.read()) != MARK) {
//nop, simply skip
}
}
}
+ imageStream.reset();
} catch (IOException ioe) {
try {
imageStream.reset();
return info;
}
- private int read2bytes(BufferedInputStream imageStream) throws IOException {
+ private int read2bytes(InputStream imageStream) throws IOException {
int byte1 = imageStream.read();
int byte2 = imageStream.read();
return (int) ((byte1 << 8) | byte2);
}
- private long skip(BufferedInputStream imageStream, long n) throws IOException {
+ private long skip(InputStream imageStream, long n) throws IOException {
long discarded = 0;
while (discarded != n) {
imageStream.read();
return discarded; // scope for exception
}
-}
\ No newline at end of file
+}
+
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.IOException;
// FOP
private static final int PNG_SIG_LENGTH = 24;
/** @see org.apache.fop.image.analyser.ImageReader */
- public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream bis,
+ public FopImage.ImageInfo verifySignature(String uri, InputStream bis,
FOUserAgent ua) throws IOException {
byte[] header = getDefaultHeader(bis);
boolean supported = ((header[0] == (byte) 0x89)
if (supported) {
FopImage.ImageInfo info = getDimension(header);
info.mimeType = getMimeType();
+ info.inputStream = bis;
return info;
} else {
return null;
return info;
}
- private byte[] getDefaultHeader(BufferedInputStream imageStream)
+ private byte[] getDefaultHeader(InputStream imageStream)
throws IOException {
byte[] header = new byte[PNG_SIG_LENGTH];
try {
return header;
}
-}
\ No newline at end of file
+}
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.IOException;
import java.io.InputStream;
import java.awt.geom.AffineTransform;
private boolean batik = true;
/** @see org.apache.fop.image.analyser.ImageReader */
- public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
+ public FopImage.ImageInfo verifySignature(String uri, InputStream fis,
FOUserAgent ua)
throws IOException {
- return loadImage(uri, fis, ua);
+ FopImage.ImageInfo info = loadImage(uri, fis, ua);
+ if (info != null) {
+ try {
+ fis.close();
+ } catch (Exception e) {
+ }
+ }
+ return info;
}
/**
* @param ua @todo Description of the Parameter
* @return @todo Description of the Return Value
*/
- private FopImage.ImageInfo loadImage(String uri, BufferedInputStream bis,
+ private FopImage.ImageInfo loadImage(String uri, InputStream bis,
FOUserAgent ua) {
if (batik) {
try {
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.IOException;
// FOP
private static final int TIFF_SIG_LENGTH = 8;
/** @see org.apache.fop.image.analyser.ImageReader */
- public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream bis,
+ public FopImage.ImageInfo verifySignature(String uri, InputStream bis,
FOUserAgent ua) throws IOException {
byte[] header = getDefaultHeader(bis);
boolean supported = false;
if (supported) {
FopImage.ImageInfo info = getDimension(header);
info.mimeType = getMimeType();
+ info.inputStream = bis;
return info;
} else {
return null;
return info;
}
- private byte[] getDefaultHeader(BufferedInputStream imageStream)
+ private byte[] getDefaultHeader(InputStream imageStream)
throws IOException {
byte[] header = new byte[TIFF_SIG_LENGTH];
try {
package org.apache.fop.image.analyser;
// Java
-import java.io.BufferedInputStream;
+import java.io.InputStream;
import java.io.IOException;
import java.util.Map;
}
/** @see org.apache.fop.image.analyser.ImageReader */
- public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
+ public FopImage.ImageInfo verifySignature(String uri, InputStream fis,
FOUserAgent ua)
throws IOException {
- return loadImage(uri, fis, ua);
+ FopImage.ImageInfo info = loadImage(uri, fis, ua);
+ if (info != null) {
+ try {
+ fis.close();
+ } catch (Exception e) {
+ }
+ }
+ return info;
}
/**
* @param ua The user agent
* @return An ImageInfo object describing the image
*/
- protected FopImage.ImageInfo loadImage(String uri, BufferedInputStream bis,
+ protected FopImage.ImageInfo loadImage(String uri, InputStream bis,
FOUserAgent ua) {
return createDocument(bis, ua);
}
* @param ua The user agent
* @return An ImageInfo object describing the image
*/
- public FopImage.ImageInfo createDocument(BufferedInputStream is, FOUserAgent ua) {
+ public FopImage.ImageInfo createDocument(InputStream is, FOUserAgent ua) {
Document doc = null;
FopImage.ImageInfo info = new FopImage.ImageInfo();
info.mimeType = getMimeType();
* @param height the height to draw the image
*/
public void addJpegImage(JpegImage jpeg, float x, float y, float width, float height) {
- FopPDFImage fopimage = new FopPDFImage(jpeg, jpeg.getURL());
+ FopPDFImage fopimage = new FopPDFImage(jpeg, "");
int xObjectNum = this.pdfDoc.addImage(resourceContext, fopimage).getXNumber();
AffineTransform at = getTransform();