Package org.xhtmlrenderer.util

Examples of org.xhtmlrenderer.util.StreamResource


     * @param uri Location of the XML source.
     * @return An XMLResource containing the image.
     */
    public XMLResource getXMLResource(String uri) {
        String ruri = _uriResolver.resolve(uri);
        StreamResource sr = new StreamResource(ruri);
        try {
            sr.connect();
            BufferedInputStream bis = sr.bufferedStream();
            return XMLResource.load(bis);
        } catch (IOException e) {
            return null;
        } finally {
            sr.close();
        }
    }
View Full Code Here


        }
    }

    public byte[] getBinaryResource(String uri) {
        String ruri = _uriResolver.resolve(uri);
        StreamResource sr = new StreamResource(ruri);
        try {
            sr.connect();
            BufferedInputStream bis = sr.bufferedStream();
            ByteArrayOutputStream result = new ByteArrayOutputStream(sr.hasStreamLength() ? sr.streamLength() : 4 * 1024);
            byte[] buf = new byte[10240];
            int i;
            while ((i = bis.read(buf)) != -1) {
                result.write(buf, 0, i);
            }

            return result.toByteArray();
        } catch (IOException e) {
            return null;
        } finally {
            sr.close();
        }
    }
View Full Code Here

    public static ImageResource loadImageResourceFromUri(final String uri) {
        if (ImageUtil.isEmbeddedBase64Image(uri)) {
            return loadEmbeddedBase64ImageResource(uri);
        } else {
            StreamResource sr = new StreamResource(uri);
            InputStream is;
            ImageResource ir = null;
            try {
                sr.connect();
                is = sr.bufferedStream();
                try {
                    BufferedImage img = ImageIO.read(is);
                    if (img == null) {
                        throw new IOException("ImageIO.read() returned null");
                    }
                    ir = createImageResource(uri, img);
                } catch (FileNotFoundException e) {
                    XRLog.exception("Can't read image file; image at URI '" + uri + "' not found");
                } catch (IOException e) {
                    XRLog.exception("Can't read image file; unexpected problem for URI '" + uri + "'", e);
                } finally {
                    sr.close();
                }
            } catch (IOException e) {
                // couldnt open stream at URI...
                XRLog.exception("Can't open stream for URI '" + uri + "': " + e.getMessage());
            }
View Full Code Here

TOP

Related Classes of org.xhtmlrenderer.util.StreamResource

Copyright © 2018 www.massapicom. 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.