Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file 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.
  */
 package com.amazonaws.util;
 
 import java.net.URI;
 
 
 
 public class HttpUtils {
    
    
 
     @Deprecated
     public static String urlEncode(final String valuefinal boolean path) {
         return SdkHttpUtils.urlEncode(valuepath);
     }

    
 
     @Deprecated
     public static boolean isUsingNonDefaultPort(URI uri) {
         return SdkHttpUtils.isUsingNonDefaultPort(uri);
     }

    
 
     @Deprecated
     public static boolean usePayloadForQueryParameters(Request<?> request) {
         return SdkHttpUtils.usePayloadForQueryParameters(request);
     }

    
 
     @Deprecated
     public static String encodeParameters(Request<?> request) {
         return SdkHttpUtils.encodeParameters(request);
     }

    
 
     @Deprecated
     public static String appendUri(String baseUriString path) {
         return SdkHttpUtils.appendUri(baseUripath);
     }

    
 
     @Deprecated
     public static String appendUri(final String baseUriString path,
             final boolean escapeDoubleSlash) {
         return SdkHttpUtils.appendUri(baseUripathescapeDoubleSlash);
     }

    
Fetches a file from the URI given and returns an input stream to it.

Parameters:
uri the uri of the file to fetch
config optional configuration overrides
Returns:
an InputStream containing the retrieved data
Throws:
java.io.IOException on error
 
     @SuppressWarnings("deprecation")
     public static InputStream fetchFile(
             final URI uri,
             final ClientConfiguration configthrows IOException {
 
        HttpParams httpClientParams = new BasicHttpParams();
        HttpProtocolParams.setUserAgent(
                httpClientParamsgetUserAgent(config));
        HttpConnectionParams.setConnectionTimeout(
                httpClientParamsgetConnectionTimeout(config));
        HttpConnectionParams.setSoTimeout(
                httpClientParamsgetSocketTimeout(config));
        DefaultHttpClient httpclient = new DefaultHttpClient(httpClientParams);
        if (config != null) {
            String proxyHost = config.getProxyHost();
            int proxyPort = config.getProxyPort();
            if (proxyHost != null && proxyPort > 0) {
                HttpHost proxy = new HttpHost(proxyHostproxyPort);
                httpclient.getParams().setParameter(
                        .proxy);
                if (config.getProxyUsername() != null
                    && config.getProxyPassword() != null) {
                    httpclient.getCredentialsProvider().setCredentials(
                            new AuthScope(proxyHostproxyPort),
                            new NTCredentials(config.getProxyUsername(),
                                              config.getProxyPassword(),
                                              config.getProxyWorkstation(),
                                              config.getProxyDomain()));
                }
            }
        }
        HttpResponse response = httpclient.execute(new HttpGet(uri));
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new IOException("Error fetching file from " + uri + ": "
                                  + response);
        }
        return new HttpClientWrappingInputStream(
                httpclient,
                response.getEntity().getContent());
    }
    private static String getUserAgent(final ClientConfiguration config) {
        String userAgent = null;
        if (config != null) {
            userAgent = config.getUserAgent();
        }
        if (userAgent == null) {
            userAgent = .;
        } else if (!..equals(userAgent)) {
            userAgent += ", " + .;
        }
        return userAgent;
    }
    private static int getConnectionTimeout(final ClientConfiguration config) {
        if (config != null) {
            return config.getConnectionTimeout();
        }
    }
    private static int getSocketTimeout(final ClientConfiguration config) {
        if (config != null) {
            return config.getSocketTimeout();
        }
    }
New to GrepCode? Check out our FAQ X