/** * <p>Returns the <tt>WebResponse</tt> for the image contained by this image element.</p> * <p><span style="color:red">POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK</span></p> * <p>If the image has not already been downloaded and <tt>downloadIfNeeded</tt> is {@code true}, this method * triggers a download and caches the image.</p> * * @param downloadIfNeeded whether or not the image should be downloaded (if it hasn't already been downloaded) * @return {@code null} if no download should be performed and one hasn't already been triggered; otherwise, * the response received when performing a request for the image referenced by this element * @throws IOException if an error occurs while downloading the image */ public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException { if (downloadIfNeeded) { downloadImageIfNeeded(); } return imageWebResponse_; }
/** * <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK.</span><br/> * If the image is not already downloaded it triggers a download. Then it stores the image in the HtmlImage * object for later use.<br/> * * @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously * @return <code>null</code> if no download should be performed and when this wasn't already done; the response * received when performing a request for the image referenced by this tag otherwise * @throws IOException if an error occurs while downloading the image */ public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException { if (downloadIfNeeded) { downloadImageIfNeeded(); } return imageWebResponse_; }
/** * <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK.</span><br/> * If the image is not already downloaded it triggers a download. Then it stores the image in the HtmlImage * object for later use.<br/> * * @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously * @return <code>null</code> if no download should be performed and when this wasn't already done; the response * received when performing a request for the image referenced by this tag otherwise * @throws IOException if an error occurs while downloading the image */ public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException { if (downloadIfNeeded) { downloadImageIfNeeded(); } return imageWebResponse_; }
/** * <p>Returns the <tt>WebResponse</tt> for the image contained by this image element.</p> * <p><span style="color:red">POTENTIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK</span></p> * <p>If the image has not already been downloaded and <tt>downloadIfNeeded</tt> is {@code true}, this method * triggers a download and caches the image.</p> * * @param downloadIfNeeded whether or not the image should be downloaded (if it hasn't already been downloaded) * @return {@code null} if no download should be performed and one hasn't already been triggered; otherwise, * the response received when performing a request for the image referenced by this element * @throws IOException if an error occurs while downloading the image */ public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException { if (downloadIfNeeded) { downloadImageIfNeeded(); } return imageWebResponse_; }
/** * <span style="color:red">POTENIAL PERFORMANCE KILLER - DOWNLOADS THE IMAGE - USE AT YOUR OWN RISK.</span><br/> * If the image is not already downloaded it triggers a download. Then it stores the image in the HtmlImage * object for later use.<br/> * * @param downloadIfNeeded indicates if a request should be performed this hasn't been done previously * @return <code>null</code> if no download should be performed and when this wasn't already done; the response * received when performing a request for the image referenced by this tag otherwise * @throws IOException if an error occurs while downloading the image */ public WebResponse getWebResponse(final boolean downloadIfNeeded) throws IOException { if (downloadIfNeeded) { downloadImageIfNeeded(); } return imageWebResponse_; }
/** * Saves this image as the specified file. * @param file the file to save to * @throws IOException if an IO error occurs */ public void saveAs(final File file) throws IOException { downloadImageIfNeeded(); if (null != imageWebResponse_) { try (FileOutputStream fileOut = new FileOutputStream(file); InputStream inputStream = imageWebResponse_.getContentAsStream()) { IOUtils.copy(inputStream, fileOut); } } }
/** * Saves this image as the specified file. * @param file the file to save to * @throws IOException if an IO error occurs */ public void saveAs(final File file) throws IOException { downloadImageIfNeeded(); if (null != imageWebResponse_) { try (OutputStream fos = Files.newOutputStream(file.toPath()); InputStream inputStream = imageWebResponse_.getContentAsStream()) { IOUtils.copy(inputStream, fos); } } }
private void readImageIfNeeded() throws IOException { downloadImageIfNeeded(); if (imageReader_ == null) { final ImageInputStream iis = ImageIO.createImageInputStream(imageWebResponse_.getContentAsStream()); final Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { throw new IOException("No image detected in response"); } imageReader_ = iter.next(); imageReader_.setInput(iis); } }
private void readImageIfNeeded() throws IOException { downloadImageIfNeeded(); if (imageReader_ == null) { final ImageInputStream iis = ImageIO.createImageInputStream(imageWebResponse_.getContentAsStream()); final Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { throw new IOException("No image detected in response"); } imageReader_ = iter.next(); imageReader_.setInput(iis); } }
private void readImageIfNeeded() throws IOException { downloadImageIfNeeded(); if (imageReader_ == null) { final ImageInputStream iis = ImageIO.createImageInputStream(imageWebResponse_.getContentAsStream()); final Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { throw new IOException("No image detected in response"); } imageReader_ = iter.next(); imageReader_.setInput(iis); } }
private void readImageIfNeeded() throws IOException { downloadImageIfNeeded(); if (imageData_ == null) { if (null == imageWebResponse_) { throw new IOException("No image response available (src=" + getSrcAttribute() + ")"); } @SuppressWarnings("resource") final ImageInputStream iis = ImageIO.createImageInputStream(imageWebResponse_.getContentAsStream()); final Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { iis.close(); throw new IOException("No image detected in response"); } final ImageReader imageReader = iter.next(); imageReader.setInput(iis); imageData_ = new ImageData(imageReader); // dispose all others while (iter.hasNext()) { iter.next().dispose(); } } }
private void readImageIfNeeded() throws IOException { downloadImageIfNeeded(); if (imageData_ == null) { if (null == imageWebResponse_) { throw new IOException("No image response available (src=" + getSrcAttribute() + ")"); } @SuppressWarnings("resource") final ImageInputStream iis = ImageIO.createImageInputStream(imageWebResponse_.getContentAsStream()); final Iterator<ImageReader> iter = ImageIO.getImageReaders(iis); if (!iter.hasNext()) { iis.close(); throw new IOException("No image detected in response"); } final ImageReader imageReader = iter.next(); imageReader.setInput(iis); imageData_ = new ImageData(imageReader); // dispose all others while (iter.hasNext()) { iter.next().dispose(); } } }
/** * Creates a new instance. * * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes the initial attributes */ HtmlImage(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { super(unifyLocalName(qualifiedName), page, attributes); originalQualifiedName_ = qualifiedName; if (page.getWebClient().getOptions().isDownloadImages()) { try { downloadImageIfNeeded(); } catch (final IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Unable to download image for element " + this); } } } }
/** * Creates a new instance. * * @param qualifiedName the qualified name of the element type to instantiate * @param page the page that contains this element * @param attributes the initial attributes */ HtmlImage(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributes) { super(unifyLocalName(qualifiedName), page, attributes); originalQualifiedName_ = qualifiedName; if (page.getWebClient().getOptions().isDownloadImages()) { try { downloadImageIfNeeded(); } catch (final IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Unable to download image for element " + this); } } } }
downloadImageIfNeeded(); final int i = imageWebResponse_.getStatusCode();
downloadImageIfNeeded(); final int i = imageWebResponse_.getStatusCode();
downloadImageIfNeeded(); final int i = imageWebResponse_.getStatusCode(); ok = (i >= SC_OK && i < SC_MULTIPLE_CHOICES) || i == SC_USE_PROXY;
downloadImageIfNeeded(); final int i = imageWebResponse_.getStatusCode(); ok = (i >= SC_OK && i < SC_MULTIPLE_CHOICES) || i == SC_USE_PROXY;
downloadImageIfNeeded(); final int i = imageWebResponse_.getStatusCode(); ok = (i >= SC_OK && i < SC_MULTIPLE_CHOICES) || i == SC_USE_PROXY;