Java Utililty Methods BufferedImage from URL

List of utility methods to do BufferedImage from URL

Description

The list of methods to do BufferedImage from URL are organized into topic(s).

Method

BufferedImagedownloadImage(String url)
download Image
HttpURLConnection connection = null;
try {
    connection = (HttpURLConnection) new URL(url).openConnection();
    connection.connect();
    BufferedImage image = ImageIO.read(connection.getInputStream());
    connection.disconnect();
    return image;
} catch (IOException e) {
...
BufferedImagedownloadImage(URL url)
download Image
try {
    InputStream in = new BufferedInputStream(url.openStream());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int n = 0;
    while (-1 != (n = in.read(buf))) {
        out.write(buf, 0, n);
    out.close();
    in.close();
    byte[] byteArray = out.toByteArray();
    ByteArrayInputStream inByte = new ByteArrayInputStream(byteArray);
    BufferedImage read = ImageIO.read(inByte);
    return read;
} catch (IOException ioe) {
    ioe.printStackTrace();
return null;
FilegetFileAndDownload(String urlString, String folder)
get File And Download
try {
    String[] splittedUrl = urlString.split("/");
    String fileName = splittedUrl[splittedUrl.length - 1];
    final URL url = new URL(urlString);
    final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    String mimeType = connection.getContentType();
    final BufferedImage img = ImageIO.read(connection.getInputStream());
    if (img != null) {
...
BufferedImagehttpGetImage(String url)
http Get Image
return ImageIO.read(new URL(url));
byte[]Img2ByteByUrl(String strUrl)
Img Byte By Url
ByteArrayOutputStream baos = null;
try {
    URL u = new URL(strUrl);
    BufferedImage image = ImageIO.read(u);
    baos = new ByteArrayOutputStream();
    ImageIO.write(image, "jpg", baos);
    baos.flush();
    return baos.toByteArray();
...
ImageurlToImage(String urlstring)
url To Image
try {
    URL url = new URL(urlstring);
    return Toolkit.getDefaultToolkit().createImage(url);
} catch (MalformedURLException e) {
    e.printStackTrace();
return null;
BufferedImageurlToImage(URL imageUrl)
url To Image
BufferedImage image;
try {
    image = ImageIO.read(imageUrl);
} catch (IOException e) {
    throw new RuntimeException("Failed to read image from URL: " + imageUrl, e);
return image;
inturlToJpegThumbnail(String url, String filename, double maxWidth, double maxHeight)
Uses HtmlDoc command line tool, pipes an HTML URL to GhostScript which outputs a JPEG file with the given dimensions.
File gsPath = new File("/usr/bin/gs");
if (!gsPath.exists()) {
    gsPath = new File("/sw/bin/gs");
Process process;
Runtime runtime;
java.io.InputStream input;
String command[] = { "/bin/sh", "-c",
...