I am developing an image scraping application. I am getting URL
URL imageUrl = new URL(imageSource);
Then I'm creating an InputStream with this URL:
InputStream is = new URL(imageUrl.toString()).openStream();
After this I wanna create an ImageInputStream to determine ImageIO readers.
ImageInputStream iis = ??????
But I couldn't initialize this. Can I implement URL or InputStream for ImageInputStream?
Since Java 9, we can use the readAllBytes() method from InputStream class to read all bytes into a byte array. This method reads all bytes from an InputStream object at once and blocks until all remaining bytes have read and end of a stream is detected, or an exception is thrown.
public interface ImageInputStream extends DataInput, Closeable. A seekable input stream interface for use by ImageReader s. Various input sources, such as InputStream s and File s, as well as future fast I/O sources may be "wrapped" by a suitable implementation of this interface for use by the Image I/O API.
this is what you are looking for :
ImageInputStream iis = ImageIO.createImageInputStream(is);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With