Get a MIMETypedStream for the given URL. If user or password are
<code>null</code>, basic authentication will not be attempted.
547507
private MIMETypedStream getFromWeb(String url, String user, String pass,
            String knownMimeType, boolean headOnly, Context context)
            throws GeneralException, RangeNotSatisfiableException {
        logger.debug("DefaultExternalContentManager.getFromWeb({})", url);
        if (url == null) throw new GeneralException("null url");
        HttpInputStream response = null;
        try {
            if (headOnly) {
                response = m_http.head(url, true, user, pass,
                        context.getHeaderValue(HttpHeaders.IF_NONE_MATCH),
                        context.getHeaderValue(HttpHeaders.IF_MODIFIED_SINCE),
                        context.getHeaderValue("Range"));
            } else {
                response = m_http.get(
                        url, true, user, pass,
                        context.getHeaderValue(HttpHeaders.IF_NONE_MATCH),
                        context.getHeaderValue(HttpHeaders.IF_MODIFIED_SINCE),
                        context.getHeaderValue("Range"));
            }
            String mimeType =
                    response.getResponseHeaderValue(HttpHeaders.CONTENT_TYPE,
                                                    knownMimeType);
            long length = Long.parseLong(response.getResponseHeaderValue(HttpHeaders.CONTENT_LENGTH,"-1"));
            Property[] headerArray =
                    toPropertyArray(response.getResponseHeaders());
            if (mimeType == null || mimeType.isEmpty()) {
                mimeType = DEFAULT_MIMETYPE;
            }
            if (response.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
                response.close();
                Header[] respHeaders = response.getResponseHeaders();
                Property[] properties = new Property[respHeaders.length];
                for (int i = 0; i < respHeaders.length; i++){
                    properties[i] =
                        new Property(respHeaders[i].getName(), respHeaders[i].getValue());
                }
                return MIMETypedStream.getNotModified(properties);
            } else if (response.getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT) {
            	MIMETypedStream pc_response = new MIMETypedStream(mimeType, response,
                        headerArray, length);
            	pc_response.setStatusCode(HttpStatus.SC_PARTIAL_CONTENT);
            	return pc_response;
            } else if (response.getStatusCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
            	response.close();
            	throw new RangeNotSatisfiableException("External URL datastream request returned 416 Range Not Satisfiable");
            } else {
                if (headOnly) {
                    try {
                        response.close();
                    } catch (IOException ioe) {
                        logger.warn("problem closing HEAD response: {}", ioe.getMessage());
                    }
                    
                    return new MIMETypedStream(mimeType, NullInputStream.NULL_STREAM,
                            headerArray, length);
                } else {
                    return new MIMETypedStream(mimeType, response, headerArray, length);
                }
            }
        } catch (RangeNotSatisfiableException re){
        	logger.error(re.getMessage(), re);
        	throw re;                    
        } catch (Exception e) {
            throw new GeneralException("Error getting " + url, e);
        }
    }
128066
@Override
    public InputStream getInputStream() {
        try {
            LOGGER.debug("getInputStream getExternalIdentifier: {} {} ", property().getName(), getExternalIdentifier());
            return URI.create(getExternalIdentifier()).toURL().openStream();
        } catch (final MalformedURLException e) {
            throw new RepositoryRuntimeException("Malformed URL: " + getExternalIdentifier(), e);
        } catch (final Exception e) {
            throw new RepositoryRuntimeException(e);
        }
    }
645225
private static byte[] getBytes(URL url) throws IOException {
        URLConnection uc = url.openConnection();
        if (uc instanceof java.net.HttpURLConnection) {
            java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc;
            int code = huc.getResponseCode();
            if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) {
                throw new IOException("open HTTP connection failed.");
            }
        }
        int len = uc.getContentLength();
        InputStream in = new BufferedInputStream(uc.getInputStream());

        byte[] b;
        try {
            b = IOUtils.readFully(in, len, true);
        } finally {
            in.close();
        }
        return b;
    }
49111
public static byte[] loadBytes(URL url) {
        byte[] bytes = null;
        try {
            bytes = loadBytes(url.openStream());
        } catch (IOException ex) {
            // ex.printStackTrace();
        }
        return bytes;
    }
439706
public GetAppStreamResponse queryAppStream(GetAppStreamRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");
        checkStringNotEmpty(request.getApp(), "The parameter app should NOT be null or empty string.");
        checkStringNotEmpty(request.getStream(), "The parameter stream should NOT be null or empty string.");
        InternalRequest internalRequest = createRequest(HttpMethodName.GET, request, LIVE_APP,
                request.getApp(), LIVE_SESSION, request.getStream());
        return invokeHttpClient(internalRequest, GetAppStreamResponse.class);
    }
38354
public static byte[] toByteArray(URL url) throws IOException {
        try (InputStream inputStream = url.openStream()) {
            return ByteStreams.toByteArray(inputStream);
        }
    }
1247231
def _guess_content_type(url):
    '''
    
    '''
    OCTET_STREAM = 'application/octet-stream'
    n = url.rfind('.')
    if n == -1:
        return OCTET_STREAM
    return mimetypes.types_map.get(url[n:].lower(), OCTET_STREAM)
385744
private void loadMimeType(URL url) {
    try {
      Stopwatch watch = new Stopwatch(true);
      InputStream im = url.openStream();
      contentTypes.load(im);
      logger.info("Load {} content types in {}", contentTypes.size(), watch);
      im.close();
    } catch (IOException e) {
      logger.error("load " + url + " error", e);
    }
  }
288715
public static String postFrom(
                    final URL to_url,
                    final InputStream from_stream,
                    final MediaType media_type
                    )
    {
        InputStreamRequestCallback  callback =
                        new InputStreamRequestCallback( from_stream, media_type );
        String  location = _execute( to_url, HttpMethod.POST, callback,
                        new LocationHeaderResponseExtractor() );

        return location;
    }
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();
	}
99818
public static String sha1(URL url) {
		InputStream is = null;
		try {
			is = url.openStream();
			return sha1(is);
		} catch (IOException ioe) {
			log.warn("Error occourred while reading from URL: " + url, ioe);
			throw new RuntimeIOException(ioe);
		} finally {
			if (is != null) {
				try {
					is.close();
				} catch (IOException ioe) {
					log.warn("Failed to close stream for URL: " + url, ioe);
					throw new RuntimeIOException(ioe);
				}
			}
		}
	}
1196385
public static Bitmap getThumbnail(Context context, Uri uri, String mimeType) {
        if (DEBUG)
            Log.d(TAG, "Attempting to get thumbnail");

        if (!isMediaUri(uri)) {
            Log.e(TAG, "You can only retrieve thumbnails for images and videos.");
            return null;
        }

        Bitmap bm = null;
        if (uri != null) {
            final ContentResolver resolver = context.getContentResolver();
            Cursor cursor = null;
            try {
                cursor = resolver.query(uri, null, null, null, null);
                if (cursor.moveToFirst()) {
                    final int id = cursor.getInt(0);
                    if (DEBUG)
                        Log.d(TAG, "Got thumb ID: " + id);

                    if (mimeType.contains("video")) {
                        bm = MediaStore.Video.Thumbnails.getThumbnail(
                                resolver,
                                id,
                                MediaStore.Video.Thumbnails.MINI_KIND,
                                null);
                    }
                    else if (mimeType.contains(FileUtils.MIME_TYPE_IMAGE)) {
                        bm = MediaStore.Images.Thumbnails.getThumbnail(
                                resolver,
                                id,
                                MediaStore.Images.Thumbnails.MINI_KIND,
                                null);
                    }
                }
            } catch (Exception e) {
                if (DEBUG)
                    Log.e(TAG, "getThumbnail", e);
            } finally {
                if (cursor != null)
                    cursor.close();
            }
        }
        return bm;
    }
1175736
public InputStream getInputStream(URI uri, SecurityDomain securityDomain) throws NoSecurityDomainException, MalformedURLException, IOException, NoSuchAlgorithmException {
        final NodeAuthModuleContext context = NodeAuthModuleContext.getContext();
        if (!context.isTLSEnabled() && !context.isNonTLSConnectionsPermitted()) {
            throw new NoSuchAlgorithmException("TLS has been disabled for ATNA connections");
        }

        boolean tlsURI = uri.getScheme().equalsIgnoreCase("https");
        boolean useTLS = tlsURI && context.isTLSEnabled() || !context.isNonTLSConnectionsPermitted();

        if (useTLS && null == securityDomain) {
            throw new NoSecurityDomainException(uri, "Security domain provided is null");
        }

        if (useTLS) {
            securityDomain.setDomainEnvironment();
        }
        InputStream is = null;
        try {
            URLConnection connection = uri.toURL().openConnection();

            if (useTLS && !securityDomain.doDomainSpoofCheck()) {
                ((HttpsURLConnection) connection).setHostnameVerifier((urlHostName, session) -> true);
            }

            is = connection.getInputStream();
            if (useTLS) {
                logger.info("Secure connection successfully made using TLS to " + uri.toString());
            } else {
                logger.info("Unsecure connection successfully made to " + uri.toString());
            }
        } catch (IOException e) {
            if (useTLS) securityDomain.restoreSystemEnvironment();
            throw e;
        }

        if (useTLS) securityDomain.restoreSystemEnvironment();
        return is;
    }
270940
function(value) {
      if (!arguments.length) return mimeType;
      mimeType = value == null ? null : value + "";
      return request;
    }
425932
public static InputStream fromURL(URL url) throws IOException {
		if(url != null) {
			return url.openStream();
		}
		return null;
	}
1310108
public GetStreamStatisticsResponse getStreamStatistics(GetStreamStatisticsRequest request) {
        checkNotNull(request, "The parameter request should NOT be null.");

        checkStringNotEmpty(request.getDomain(), "Domain should NOT be null");
        checkStringNotEmpty(request.getApp(), "App should NOT be null");
        checkStringNotEmpty(request.getStream(), "Stream should NOT be null");

        InternalRequest internalRequest = createRequest(HttpMethodName.GET, request,
                STATISTICS, LIVE_DOMAIN, request.getDomain(), LIVE_APP, request.getApp(),
                LIVE_STREAM, request.getStream());
        if (request.getStartDate() != null) {
            internalRequest.addParameter("startDate", request.getStartDate());
        }
        if (request.getEndDate() != null) {
            internalRequest.addParameter("endDate", request.getEndDate());
        }
        if (request.getAggregate() != null) {
            internalRequest.addParameter("aggregate", request.getAggregate().toString());
        }
        return invokeHttpClient(internalRequest, GetStreamStatisticsResponse.class);
    }
217689
public static ReadableByteChannel getInstance(URL url) throws IOException
    {
        ProtocolHandler ph = map.get(url.getProtocol());
        if (ph != null)
        {
            return ph.create(url);
        }
        else
        {
            return Channels.newChannel(url.openStream());
        }
    }