/** {@inheritDoc} */ public String toString() { return (isFastSource() ? "FAST " : "") + "ImageSource: " + getSystemId() + " " + getImageInputStream(); }
/** * Returns the ImageInputStream of a Source object. * @param src the Source object * @return the ImageInputStream (or null if there's not ImageInputStream available) */ public static ImageInputStream getImageInputStream(Source src) { if (src instanceof ImageSource) { return ((ImageSource) src).getImageInputStream(); } else { return null; } }
private static ImageSource createImageSource(InputStream in, Source source) { try { //Buffer and uncompress if necessary return new ImageSource(createImageInputStream(ImageUtil.autoDecorateInputStream(in)), source.getSystemId(), false); } catch (IOException ioe) { log.error("Unable to create ImageInputStream for InputStream" + " from system identifier '" + source.getSystemId() + "' (" + ioe.getMessage() + ")"); } return null; }
final ImageSource imageSource = (ImageSource) source; final StreamSource streamSource = new StreamSource(imageSource .getInputStream()); retVal = this.parseStreamSource(streamSource); } else if (source instanceof DOMSource) {
/** * Removes any references to InputStreams or Readers from the given Source to prohibit * 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) { InputSource is = ((SAXSource) src).getInputSource(); if (is != null) { is.setByteStream(null); is.setCharacterStream(null); } } }
/** * Indicates whether a Source is reusable. A Source object is reusable if it's an * {@link ImageSource} (containing an {@link ImageInputStream}) or a {@link DOMSource}. * @param src the Source object * @return true if the Source is reusable */ 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; } return false; }
return null; } else { imageSource = new ImageSource(newInputStream, resolvedURI, true);
/** * Returns the ImageInputStream of a Source object. This method throws an * IllegalArgumentException if there's no ImageInputStream instance available from the * Source object. * @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"); } }
/** * Returns the {@link InputStream} that is backing the given {@link Source} object. * * @param src is backed by an {@link InputStream} * @return the input stream */ public static InputStream getInputStream(Source src) { try { if (src instanceof StreamSource) { return ((StreamSource) src).getInputStream(); } else if (src instanceof DOMSource) { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); StreamResult xmlSource = new StreamResult(outStream); TransformerFactory.newInstance().newTransformer().transform(src, xmlSource); return new ByteArrayInputStream(outStream.toByteArray()); } else if (src instanceof SAXSource) { return ((SAXSource) src).getInputSource().getByteStream(); } else if (src instanceof ImageSource) { return new ImageInputStreamAdapter(((ImageSource) src).getImageInputStream()); } } catch (Exception e) { // TODO: How do we want to handle these? They all come from the TransformerFactory } return null; }