Java InputStream Close close(InputStream is, boolean success)

Here you can find the source of close(InputStream is, boolean success)

Description

close

License

Apache License

Parameter

Parameter Description
success <code>false</code> if the outer method is throwing an exception.

Declaration

private static void close(InputStream is, boolean success) 

Method Source Code

//package com.java2s;
/* ====================================================================
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You 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./*from  ww w .  ja  v  a 2s.c  o  m*/
 ==================================================================== */

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

public class Main {
    /**
     * @param success <code>false</code> if the outer method is throwing an exception.
     */
    private static void close(InputStream is, boolean success) {
        try {
            is.close();
        } catch (IOException e) {
            if (success) {
                // this is a new error. ok to throw
                throw new RuntimeException(e);
            }
            // else don't subvert original exception. just print stack trace for this one
            e.printStackTrace();
        }
    }
}

Related

  1. close(InputStream is)
  2. close(InputStream is)
  3. close(InputStream is)
  4. close(InputStream is)
  5. close(InputStream is)
  6. close(InputStream is, OutputStream os)
  7. forceClose(Closeable stream)
  8. forceClosed(InputStream stream)