从URL中获取流

@param url {@link URL}
@return InputStream流
@since 3.2.1
347179
public static InputStream getStream(URL url) {
		Assert.notNull(url);
		try {
			return url.openStream();
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
449348
private InputStream connect(String url) throws IOException {
		URLConnection conn = new URL(URL_BASE + url).openConnection();
		conn.setConnectTimeout(CONNECT_TIMEOUT);
		conn.setReadTimeout(READ_TIMEOUT);
		conn.setRequestProperty("User-Agent", USER_AGENT);
		return conn.getInputStream();
	}
1139169
public static Environment of(@NonNull URL url) {
        try {
            return of(url.openStream());
        } catch (UnsupportedEncodingException e) {
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        return null;
    }
641225
@Override
    public String fetch(String url) {
        try{
            LOGGER.debug("url:"+url);
            WEB_DRIVER.get(url);
            String html = WEB_DRIVER.getPageSource();
            LOGGER.debug("html:"+html);
            return html;
        }catch (Exception e) {
            LOGGER.error("获取URL："+url+"页面出错", e);
        }
        return "";
    }
788056
public static URL getUrl(String url) {
    try {
      return new URL(url);
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }
73895
public String simpleGet(String url) throws IOException {
		final AtomicReference<String> str = new AtomicReference<>();
		simpleGetInternal(url, inputStream -> {
            try {
                str.set(IOUtils.toString(inputStream, "UTF-8"));
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }, null);

		return str.get();
	}
216028
@NonNull
    private static byte[] download(String url) throws IOException {
        InputStream is = null;
        ByteArrayOutputStream os = null;

        try {

            final URL u = new URL(url);
            final URLConnection connection = u.openConnection();
            connection.connect();

            is = connection.getInputStream();
            os = new ByteArrayOutputStream();

            final byte[] buffer = new byte[4096];
            int read;

            while (true) {
                read = is.read(buffer, 0, buffer.length);
                if (read == -1) {
                    break;
                }
                os.write(buffer, 0, read);
            }

            return os.toByteArray();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ignored) {
                }
            }
            if (os != null) {
                try {
                    os.close();
                } catch (IOException ignored) {
                }
            }
        }
    }
660381
public static Condition url(final String url) {
        return new Condition(input -> input.getUrl().equals(url));
    }
1360505
public Vector decode(final URL url) throws IOException {
    LineNumberReader reader;
    boolean isZipFile = url.getPath().toLowerCase().endsWith(".zip");
    InputStream inputStream;
    if (isZipFile) {
        inputStream = new ZipInputStream(url.openStream());
        //move stream to next entry so we can read it
        ((ZipInputStream)inputStream).getNextEntry();
    } else {
        inputStream = url.openStream();
    }
    if (owner != null) {
        reader = new LineNumberReader(
                new InputStreamReader(
                        new ProgressMonitorInputStream(owner,
                                "Loading " + url , inputStream), ENCODING));
    } else {
        reader = new LineNumberReader(new InputStreamReader(inputStream, ENCODING));
    }

    Vector v = new Vector();

    String line;
    Vector events;
    try {
        while ((line = reader.readLine()) != null) {
            StringBuffer buffer = new StringBuffer(line);
            for (int i = 0; i < 1000; i++) {
                buffer.append(reader.readLine()).append("\n");
            }
            events = decodeEvents(buffer.toString());
            if (events != null) {
                v.addAll(events);
            }
        }
    } finally {
      partialEvent = null;
      try {
        if (reader != null) {
          reader.close();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return v;
  }
747732
public static Properties load(URL url) throws IOException {
        InputStream fis = null;
        try {
            Properties props = new Properties();
            fis = url.openStream();
            props.load(fis);
            return props;
        } finally {
            IOUtils.closeQuietly(fis);
        }
    }
38354
public static byte[] toByteArray(URL url) throws IOException {
        try (InputStream inputStream = url.openStream()) {
            return ByteStreams.toByteArray(inputStream);
        }
    }
1346201
static InputStream getCachedImageStream(URI url, Context context) {
        InputStream imageStream = null;
        if (url != null) {
            if (isCDNURL(url)) {
                try {
                    FileLruCache cache = getCache(context);
                    imageStream = cache.get(url.toString());
                } catch (IOException e) {
                    Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, e.toString());
                }
            }
        }

        return imageStream;
    }
889525
public static String get(String url,
                             Map<String, String> headers,
                             String params) throws IOException {

        // 参数
        if (StringUtil.isNotEmpty(params)) {
            url += "?" + params;
        }

        HttpURLConnection httpUrlConn = httpUrlConn(url);
        httpUrlConn.setDoInput(true);
        httpUrlConn.setRequestMethod(Constant.RequestMethodGet);

        // header
        if (headers != null) {
            header(headers, httpUrlConn);
        }

        httpUrlConn.connect();

        return readIO(httpUrlConn);
    }
905592
protected static InputStream downloadMaterial(String url, String params) throws IOException {
		URL _url = new URL(url);
		HttpURLConnection conn = (HttpURLConnection) _url.openConnection();
		// 连接超时
		conn.setConnectTimeout(25000);
		// 读取超时 --服务器响应比较慢，增大时间
		conn.setReadTimeout(25000);
		conn.setRequestMethod("POST");
		conn.setRequestProperty("Content-Type", "Keep-Alive");
		conn.setRequestProperty("User-Agent", DEFAULT_USER_AGENT);
		conn.setDoOutput(true);
		conn.setDoInput(true);
		conn.connect();
		if (StrKit.notBlank(params)) {
			OutputStream out = conn.getOutputStream();
			out.write(params.getBytes(Charsets.UTF_8));
			out.flush();
			IOUtils.closeQuietly(out);
		}
		return conn.getInputStream();
	}
561738
public InputStream getInputStream() {
        try
        {
            int responseCode = this.urlConnection.getResponseCode();

            try
            {
                // HACK: manually follow redirects, for the login to work
                // HTTPUrlConnection auto redirect doesn't respect the provided headers
                if(responseCode ==302)
                {
                    HttpClient redirectClient =
                            new HttpClient(proxyHost,proxyPort, urlConnection.getHeaderField("Location"),
                                    headers, urlConnection.getRequestMethod(), callback, authHeader);
                    redirectClient.getInputStream().close();
                }
            }
            catch (Throwable e)
            {
                System.out.println("Following redirect failed");
            }

            setCookieHeader = this.urlConnection.getHeaderField("Set-Cookie");


            InputStream in = responseCode != HttpURLConnection.HTTP_OK ?
                    this.urlConnection.getErrorStream() : this.urlConnection.getInputStream();

            return in;
        } catch (Exception e) {
            return null;
        }
    }
53555
static protected String[] splitURL(String url){
		String beforePart;
		String afterPart;
		String[] l = new String[2];
		int protocolEnd = url.indexOf("://");
		if (protocolEnd == -1){	//如果没有协议信息
			protocolEnd = -3;
		}
		int pathStart = url.indexOf("/", protocolEnd + 3);
		if (pathStart == -1){//没路径信息
			pathStart = url.length();
			afterPart = "";
		}else{
			afterPart = url.substring(pathStart+1).toLowerCase();		// 斜线后的路径和参数
		}
		beforePart = url.substring(protocolEnd + 3, pathStart).toLowerCase();	// 斜线前的主机、端口和帐号
		
		String reversedBeforePart = new StringBuffer(beforePart).reverse().toString();
		l[0] = reversedBeforePart;
		l[1] = afterPart;
		return l;
	}
480411
public static Study readStudy(final URL url) throws IOException {
        checkNotNull(url);
        try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) {
            return readStudy(reader);
        }
    }