Java InputStream Close close(InputStream inputstream)

Here you can find the source of close(InputStream inputstream)

Description

Closes an input stream while inspecting its class.

License

LGPL

Exception

Parameter Description
IOException an exception

Declaration

public static void close(InputStream inputstream) throws IOException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

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

public class Main {
    /**/*from   ww w  .  j a  va  2 s . c  o m*/
     * Closes an input stream while inspecting its class. The inspection is done
     * to avoid closing streams associates with jar files that may cause later
     * errors like
     * 
     * <pre>
     * Caused by: java.io.IOException: Stream closed
     * </pre>
     * 
     * So, all streams whose class name does not start with
     * <code>sun.net.www.protocol.jar.JarURLConnection</code> will be closed
     * 
     * @throws IOException
     * 
     * @since 2016-09-20
     */
    public static void close(InputStream inputstream) throws IOException {
        if (inputstream != null) {
            String inputstreamClassName = inputstream.getClass().getName();
            if (!inputstreamClassName.startsWith("sun.net.www.protocol.jar.JarURLConnection")) {
                inputstream.close();
            }
        }
    }
}

Related

  1. close(InputStream in)
  2. close(InputStream in, boolean silent)
  3. close(InputStream in, OutputStream out)
  4. close(InputStream input)
  5. close(InputStream inputStream)
  6. close(InputStream inputStream)
  7. close(InputStream is)
  8. close(InputStream is)
  9. close(InputStream is)