Java URL Connection imageFromUrl(String url)

Here you can find the source of imageFromUrl(String url)

Description

image From Url

License

Apache License

Declaration

public static InputStream imageFromUrl(String url) 

Method Source Code


//package com.java2s;
/*/* w w w  .j  ava2  s .c  o m*/
 * Copyright 2017 John Grosh <john.a.grosh@gmail.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;
import java.io.InputStream;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static InputStream imageFromUrl(String url) {
        if (url == null)
            return null;
        try {
            URL u = new URL(url);
            URLConnection urlConnection = u.openConnection();
            urlConnection.setRequestProperty("user-agent",
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36");
            return urlConnection.getInputStream();
        } catch (IOException | IllegalArgumentException e) {
        }
        return null;
    }
}

Related

  1. getUrlSource(String url)
  2. getURLStream(URL url, int level)
  3. getWebPageHtmlContent(String url)
  4. getWebsiteContents(URL url)
  5. httpPost(String urlString, String postPath, Map keyValuePairs)
  6. isJarDirectory(JarURLConnection conn)
  7. isOnline(String url)
  8. isUrlReachable(String url)
  9. isValidToc(URL url)