Examples of ImageSource


Examples of org.apache.xmlgraphics.image.loader.ImageSource

        if (!(source instanceof StreamSource) && !(source instanceof SAXSource)) {
            //Return any non-stream Sources and let the ImageLoaders deal with them
            return source;
        }
       
        ImageSource imageSource = null;
       
        String resolvedURI = source.getSystemId();
        URL url;
        try {
            url = new URL(resolvedURI);
        } catch (MalformedURLException e) {
            url = null;
        }
        File f = FileUtils.toFile(url);
        if (f != null) {
            boolean directFileAccess = true;
            assert (source instanceof StreamSource) || (source instanceof SAXSource);
            InputStream in = ImageUtil.getInputStream(source);
            if (in == null) {
                try {
                    in = new java.io.FileInputStream(f);
                } catch (FileNotFoundException fnfe) {
                    log.error("Error while opening file."
                            + " Could not load image from system identifier '"
                            + source.getSystemId() + "' (" + fnfe.getMessage() + ")");
                    return null;
                }
            }
            if (in != null) {
                in = ImageUtil.decorateMarkSupported(in);
                try {
                    if (ImageUtil.isGZIPCompressed(in)) {
                        //GZIPped stream are not seekable, so buffer/cache like other URLs
                        directFileAccess = false;
                    }
                } catch (IOException ioe) {
                    log.error("Error while checking the InputStream for GZIP compression."
                            + " Could not load image from system identifier '"
                            + source.getSystemId() + "' (" + ioe.getMessage() + ")");
                    return null;
                }
            }
           
            if (directFileAccess) {
                //Close as the file is reopened in a more optimal way
                IOUtils.closeQuietly(in);
                try {
                    //We let the OS' file system cache do the caching for us
                    //--> lower Java memory consumption, probably no speed loss
                    imageSource = new ImageSource(ImageIO.createImageInputStream(f),
                            resolvedURI, true);
                } catch (IOException ioe) {
                    log.error("Unable to create ImageInputStream for local file"
                            + " from system identifier '"
                            + source.getSystemId() + "' (" + ioe.getMessage() + ")");
                }
            }
        }
       
        if (imageSource == null) {
            if (ImageUtil.hasReader(source) && !ImageUtil.hasInputStream(source)) {
                //We don't handle Reader instances here so return the Source unchanged
                return source;
            }
            // Got a valid source, obtain an InputStream from it
            InputStream in = ImageUtil.getInputStream(source);
            if (in == null && url != null) {
                try {
                    in = url.openStream();
                } catch (Exception ex) {
                    log.error("Unable to obtain stream from system identifier '"
                        + source.getSystemId() + "'");
                }
            }
            if (in == null) {
                log.error("The Source that was returned from URI resolution didn't contain"
                        + " an InputStream for URI: " + uri);
                return null;
            }

            try {
                //Buffer and uncompress if necessary
                in = ImageUtil.autoDecorateInputStream(in);
                imageSource = new ImageSource(
                        ImageIO.createImageInputStream(in), source.getSystemId(), false);
            } catch (IOException ioe) {
                log.error("Unable to create ImageInputStream for InputStream"
                        + " from system identifier '"
                        + source.getSystemId() + "' (" + ioe.getMessage() + ")");
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

     * @param src the Source object
     * @return true if the Source is reusable
     */
    protected boolean isReusable(Source src) {
        if (src instanceof ImageSource) {
            ImageSource is = (ImageSource)src;
            if (is.getImageInputStream() != null) {
                return true;
            }
        }
        if (src instanceof DOMSource) {
            return true;
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

        if (!(source instanceof StreamSource) && !(source instanceof SAXSource)) {
            //Return any non-stream Sources and let the ImageLoaders deal with them
            return source;
        }

        ImageSource imageSource = null;

        String resolvedURI = source.getSystemId();
        URL url;
        try {
            url = new URL(resolvedURI);
        } catch (MalformedURLException e) {
            url = null;
        }
        File f = /*FileUtils.*/toFile(url);
        if (f != null) {
            boolean directFileAccess = true;
            assert (source instanceof StreamSource) || (source instanceof SAXSource);
            InputStream in = ImageUtil.getInputStream(source);
            if (in == null) {
                try {
                    in = new java.io.FileInputStream(f);
                } catch (FileNotFoundException fnfe) {
                    log.error("Error while opening file."
                            + " Could not load image from system identifier '"
                            + source.getSystemId() + "' (" + fnfe.getMessage() + ")");
                    return null;
                }
            }
            if (in != null) {
                in = ImageUtil.decorateMarkSupported(in);
                try {
                    if (ImageUtil.isGZIPCompressed(in)) {
                        //GZIPped stream are not seekable, so buffer/cache like other URLs
                        directFileAccess = false;
                    }
                } catch (IOException ioe) {
                    log.error("Error while checking the InputStream for GZIP compression."
                            + " Could not load image from system identifier '"
                            + source.getSystemId() + "' (" + ioe.getMessage() + ")");
                    return null;
                }
            }

            if (directFileAccess) {
                //Close as the file is reopened in a more optimal way
                IOUtils.closeQuietly(in);
                try {
                    // We let the OS' file system cache do the caching for us
                    // --> lower Java memory consumption, probably no speed loss
                    final ImageInputStream newInputStream = ImageIO
                            .createImageInputStream(f);
                    if (newInputStream == null) {
                        log.error("Unable to create ImageInputStream for local file "
                                        + f
                                        + " from system identifier '"
                                        + source.getSystemId() + "'");
                        return null;
                    } else {
                        imageSource = new ImageSource(newInputStream,
                                resolvedURI, true);
                    }
                } catch (IOException ioe) {
                    log.error("Unable to create ImageInputStream for local file"
                            + " from system identifier '"
                            + source.getSystemId() + "' (" + ioe.getMessage() + ")");
                }
            }
        }

        if (imageSource == null) {
            if (ImageUtil.hasReader(source) && !ImageUtil.hasInputStream(source)) {
                //We don't handle Reader instances here so return the Source unchanged
                return source;
            }
            // Got a valid source, obtain an InputStream from it
            InputStream in = ImageUtil.getInputStream(source);
            if (in == null && url != null) {
                try {
                    in = url.openStream();
                } catch (Exception ex) {
                    log.error("Unable to obtain stream from system identifier '"
                        + source.getSystemId() + "'");
                }
            }
            if (in == null) {
                log.error("The Source that was returned from URI resolution didn't contain"
                        + " an InputStream for URI: " + uri);
                return null;
            }

            try {
                //Buffer and uncompress if necessary
                in = ImageUtil.autoDecorateInputStream(in);
                imageSource = new ImageSource(
                        createImageInputStream(in), source.getSystemId(), false);
            } catch (IOException ioe) {
                log.error("Unable to create ImageInputStream for InputStream"
                        + " from system identifier '"
                        + source.getSystemId() + "' (" + ioe.getMessage() + ")");
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

    protected boolean isReusable(Source src) {
        if (noSourceReuse) {
            return false;
        }
        if (src instanceof ImageSource) {
            ImageSource is = (ImageSource)src;
            if (is.getImageInputStream() != null) {
                return true;
            }
        }
        if (src instanceof DOMSource) {
            return true;
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

     * @param src the Source object
     * @return the ImageInputStream
     */
    public static ImageInputStream needImageInputStream(Source src) {
        if (src instanceof ImageSource) {
            ImageSource isrc = (ImageSource)src;
            if (isrc.getImageInputStream() == null) {
                throw new IllegalArgumentException(
                        "ImageInputStream is null/cleared on ImageSource");
            }
            return isrc.getImageInputStream();
        } else {
            throw new IllegalArgumentException("Source must be an ImageSource");
        }
    }
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

     * accidental/unwanted use by a component further downstream.
     * @param src the Source object
     */
    public static void removeStreams(Source src) {
        if (src instanceof ImageSource) {
            ImageSource isrc = (ImageSource)src;
            isrc.setImageInputStream(null);
        } else if (src instanceof StreamSource) {
            StreamSource ssrc = (StreamSource)src;
            ssrc.setInputStream(null);
            ssrc.setReader(null);
        } else if (src instanceof SAXSource) {
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

            IOUtils.closeQuietly(streamSource.getInputStream());
            streamSource.setInputStream(null);
            IOUtils.closeQuietly(streamSource.getReader());
            streamSource.setReader(null);
        } else if (src instanceof ImageSource) {
            ImageSource imageSource = (ImageSource)src;
            if (imageSource.getImageInputStream() != null) {
                try {
                    imageSource.getImageInputStream().close();
                } catch (IOException ioe) {
                    //ignore
                }
                imageSource.setImageInputStream(null);
            }
        } else if (src instanceof SAXSource) {
            InputSource is = ((SAXSource)src).getInputSource();
            if (is != null) {
                IOUtils.closeQuietly(is.getByteStream());
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

        if (!(source instanceof StreamSource) && !(source instanceof SAXSource)) {
            //Return any non-stream Sources and let the ImageLoaders deal with them
            return source;
        }
       
        ImageSource imageSource = null;
       
        String resolvedURI = source.getSystemId();
        URL url;
        try {
            url = new URL(resolvedURI);
        } catch (MalformedURLException e) {
            url = null;
        }
        File f = /*FileUtils.*/toFile(url);
        if (f != null) {
            boolean directFileAccess = true;
            assert (source instanceof StreamSource) || (source instanceof SAXSource);
            InputStream in = ImageUtil.getInputStream(source);
            if (in == null) {
                try {
                    in = new java.io.FileInputStream(f);
                } catch (FileNotFoundException fnfe) {
                    log.error("Error while opening file."
                            + " Could not load image from system identifier '"
                            + source.getSystemId() + "' (" + fnfe.getMessage() + ")");
                    return null;
                }
            }
            if (in != null) {
                in = ImageUtil.decorateMarkSupported(in);
                try {
                    if (ImageUtil.isGZIPCompressed(in)) {
                        //GZIPped stream are not seekable, so buffer/cache like other URLs
                        directFileAccess = false;
                    }
                } catch (IOException ioe) {
                    log.error("Error while checking the InputStream for GZIP compression."
                            + " Could not load image from system identifier '"
                            + source.getSystemId() + "' (" + ioe.getMessage() + ")");
                    return null;
                }
            }
           
            if (directFileAccess) {
                //Close as the file is reopened in a more optimal way
                IOUtils.closeQuietly(in);
                try {
                    //We let the OS' file system cache do the caching for us
                    //--> lower Java memory consumption, probably no speed loss
                    imageSource = new ImageSource(ImageIO.createImageInputStream(f),
                            resolvedURI, true);
                } catch (IOException ioe) {
                    log.error("Unable to create ImageInputStream for local file"
                            + " from system identifier '"
                            + source.getSystemId() + "' (" + ioe.getMessage() + ")");
                }
            }
        }
       
        if (imageSource == null) {
            if (ImageUtil.hasReader(source) && !ImageUtil.hasInputStream(source)) {
                //We don't handle Reader instances here so return the Source unchanged
                return source;
            }
            // Got a valid source, obtain an InputStream from it
            InputStream in = ImageUtil.getInputStream(source);
            if (in == null && url != null) {
                try {
                    in = url.openStream();
                } catch (Exception ex) {
                    log.error("Unable to obtain stream from system identifier '"
                        + source.getSystemId() + "'");
                }
            }
            if (in == null) {
                log.error("The Source that was returned from URI resolution didn't contain"
                        + " an InputStream for URI: " + uri);
                return null;
            }

            try {
                //Buffer and uncompress if necessary
                in = ImageUtil.autoDecorateInputStream(in);
                imageSource = new ImageSource(
                        ImageIO.createImageInputStream(in), source.getSystemId(), false);
            } catch (IOException ioe) {
                log.error("Unable to create ImageInputStream for InputStream"
                        + " from system identifier '"
                        + source.getSystemId() + "' (" + ioe.getMessage() + ")");
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

    protected boolean isReusable(Source src) {
        if (noSourceReuse) {
            return false;
        }
        if (src instanceof ImageSource) {
            ImageSource is = (ImageSource)src;
            if (is.getImageInputStream() != null) {
                return true;
            }
        }
        if (src instanceof DOMSource) {
            return true;
View Full Code Here

Examples of org.apache.xmlgraphics.image.loader.ImageSource

     * @param src the Source object
     * @return the ImageInputStream
     */
    public static ImageInputStream needImageInputStream(Source src) {
        if (src instanceof ImageSource) {
            ImageSource isrc = (ImageSource)src;
            if (isrc.getImageInputStream() == null) {
                throw new IllegalArgumentException(
                        "ImageInputStream is null/cleared on ImageSource");
            }
            return isrc.getImageInputStream();
        } else {
            throw new IllegalArgumentException("Source must be an ImageSource");
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.