Here you can find the source of closeQuietly(final InputStream inputStream)
Parameter | Description |
---|---|
inputStream | the InputStream to close |
public static void closeQuietly(final InputStream inputStream)
//package com.java2s; /*//from w ww . j a v a 2 s . com * Copyright (C) 2014 the original author or authors. * * 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 InputStream if it is not null, swallowing any exceptions. * * @param inputStream the InputStream to close */ public static void closeQuietly(final InputStream inputStream) { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // do nothing, close quietly } } } /** * Closes the OutputStream if it is not null, swallowing any exceptions. * * @param outputStream the OutputStream to close */ public static void closeQuietly(final OutputStream outputStream) { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { // do nothing, close quietly } } } /** * Closes the Reader if it is not null, swallowing any exceptions. * * @param reader the Reader to close */ public static void closeQuietly(final Reader reader) { if (reader != null) { try { reader.close(); } catch (IOException e) { // do nothing, close quietly } } } /** * Closes the Writer if it is not null, swallowing any exceptions. * * @param writer the Writer to close */ public static void closeQuietly(final Writer writer) { if (writer != null) { try { writer.close(); } catch (IOException e) { // do nothing, close quietly } } } }