Java URL to InputStream getInputStream(URLConnection c)

Here you can find the source of getInputStream(URLConnection c)

Description

get Input Stream

License

Apache License

Declaration

public static InputStream getInputStream(URLConnection c) throws IOException 

Method Source Code

//package com.java2s;
/**/*from   w w  w .  ja v a  2  s .c  o m*/
 * Copyright (C) 2017 Lucifer Wong
 *
 * 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.BufferedInputStream;

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

import java.net.URLConnection;

import java.util.zip.GZIPInputStream;

import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;

public class Main {
    private static final int TRANSFER_BUFFER = 32768;

    public static InputStream getInputStream(URLConnection c) throws IOException {
        InputStream is = c.getInputStream();
        String enc = c.getContentEncoding();

        if ("gzip".equalsIgnoreCase(enc) || "x-gzip".equalsIgnoreCase(enc)) {
            is = new GZIPInputStream(is, TRANSFER_BUFFER);
        } else if ("deflate".equalsIgnoreCase(enc)) {
            is = new InflaterInputStream(is, new Inflater(), TRANSFER_BUFFER);
        }

        return new BufferedInputStream(is);
    }
}

Related

  1. getInputStream(URL url)
  2. getInputStream(URL url)
  3. getInputStream(URL url)
  4. getInputStream(URL url)
  5. getInputStream(URL urlFile)
  6. getInputStream(URLConnection connection)
  7. getInputStream(URLConnection paramURLConnection)
  8. getInputStreamForURL(URL url)
  9. getInputStreamForURL(URL url)