Here you can find the source of close(InputStream in)
Parameter | Description |
---|---|
in | The InputStream to close. |
Parameter | Description |
---|---|
IOException | Signals that an I/O exception has occurred. |
public static void close(InputStream in) throws IOException
//package com.java2s; /**// w ww.j a va2 s .c o m * Copyright (C) 2007 Asterios Raptis * * 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.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; public class Main { /** * Closes the given InputStream. * * @param in * The InputStream to close. * @throws IOException * Signals that an I/O exception has occurred. */ public static void close(InputStream in) throws IOException { try { if (in != null) { in.close(); in = null; } } catch (final IOException e) { throw e; } finally { if (in != null) { in.close(); } } } /** * Closes the given OutputStream. * * @param out * The OutputStream to close. * @throws IOException * Signals that an I/O exception has occurred. */ public static void close(OutputStream out) throws IOException { try { if (out != null) { out.flush(); out.close(); out = null; } } catch (final IOException e) { throw e; } finally { if (out != null) { out.flush(); out.close(); } } } /** * Closes the given Reader. * * @param reader * The Reader to close. * @throws IOException * Signals that an I/O exception has occurred. */ public static void close(Reader reader) throws IOException { try { if (reader != null) { reader.close(); reader = null; } } catch (final IOException e) { throw e; } finally { if (reader != null) { reader.close(); } } } /** * Closes the given Writer. * * @param writer * The Writer to close. * @throws IOException * Signals that an I/O exception has occurred. */ public static void close(Writer writer) throws IOException { try { if (writer != null) { writer.flush(); writer.close(); writer = null; } } catch (final IOException e) { throw e; } finally { if (writer != null) { writer.flush(); writer.close(); } } } }