IOUtils.java revision 1194
1194N/A/*
1194N/A * CDDL HEADER START
1194N/A *
1194N/A * The contents of this file are subject to the terms of the
1194N/A * Common Development and Distribution License (the "License").
1194N/A * You may not use this file except in compliance with the License.
1194N/A *
1194N/A * See LICENSE.txt included in this distribution for the specific
1194N/A * language governing permissions and limitations under the License.
1194N/A *
1194N/A * When distributing Covered Code, include this CDDL HEADER in each
1194N/A * file and include the License file at LICENSE.txt.
1194N/A * If applicable, add the following below this CDDL HEADER, with the
1194N/A * fields enclosed by brackets "[]" replaced with your own identifying
1194N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1194N/A *
1194N/A * CDDL HEADER END
1194N/A */
1194N/A/*
1194N/A * Copyright (c) 2011 Trond Norbye
1194N/A */
1194N/Apackage org.opensolaris.opengrok.util;
1194N/A
1194N/Aimport java.io.IOException;
1194N/Aimport java.io.InputStream;
1194N/Aimport java.io.OutputStream;
1194N/Aimport java.io.Reader;
1194N/Aimport java.io.Writer;
1194N/Aimport java.util.logging.Level;
1194N/Aimport java.util.logging.Logger;
1194N/A
1194N/A/**
1194N/A * A small utility class to provide common functionality related to
1194N/A * IO so that we don't need to duplicate the logic all over the place.
1194N/A *
1194N/A * @author Trond Norbye <trond.norbye@gmail.com>
1194N/A */
1194N/Apublic final class IOUtils {
1194N/A
1194N/A private static final Logger log = Logger.getLogger(IOUtils.class.getName());
1194N/A
1194N/A private IOUtils() {
1194N/A // singleton
1194N/A }
1194N/A
1194N/A public static void close(InputStream in) {
1194N/A if (in != null) {
1194N/A try {
1194N/A in.close();
1194N/A } catch (IOException e) {
1194N/A log.log(Level.WARNING, "Failed to close input stream: ", e);
1194N/A }
1194N/A }
1194N/A }
1194N/A
1194N/A public static void close(OutputStream out) {
1194N/A if (out != null) {
1194N/A try {
1194N/A out.close();
1194N/A } catch (IOException e) {
1194N/A log.log(Level.WARNING, "Failed to close output stream: ", e);
1194N/A }
1194N/A }
1194N/A }
1194N/A
1194N/A public static void close(Reader in) {
1194N/A if (in != null) {
1194N/A try {
1194N/A in.close();
1194N/A } catch (IOException e) {
1194N/A log.log(Level.WARNING, "Failed to close reader: ", e);
1194N/A }
1194N/A }
1194N/A }
1194N/A
1194N/A public static void close(Writer out) {
1194N/A if (out != null) {
1194N/A try {
1194N/A out.close();
1194N/A } catch (IOException e) {
1194N/A log.log(Level.WARNING, "Failed to close writer: ", e);
1194N/A }
1194N/A }
1194N/A }
1194N/A}