01: /*
02: * Copyright 2007 Hippo.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package nl.hippo.cms.brokenlinkchecker.util;
17:
18: import java.io.InputStream;
19: import java.io.OutputStream;
20: import nl.hippo.cms.brokenlinkchecker.log.BrokenLinkCheckerLog;
21:
22: /**
23: * <p>
24: * A utility class to help with cleaning up streams.
25: * </p>
26: */
27: public class StreamCleanup {
28: /**
29: * <p>
30: * The only and private constructor to prevent instantiation of this
31: * class.
32: * </p>
33: */
34: public StreamCleanup() {
35: super ();
36: }
37:
38: /**
39: * <p>
40: * Close an input stream without throwing execptions. If the closing of
41: * the stream throws an exception, the exception is logged.
42: * </p>
43: *
44: * @param input
45: * the input stream to close.
46: * @param role
47: * the role of the input stream.
48: * @param log
49: * the log to which to log a messge if closing the stream
50: * throws an exception.
51: */
52: public static void close(InputStream input, String role,
53: BrokenLinkCheckerLog log) {
54: try {
55: input.close();
56: } catch (Exception e) {
57: log.warning(
58: "An error occurred during closing of input stream: "
59: + role, e);
60: }
61: }
62:
63: /**
64: * <p>
65: * Close an output stream without throwing execptions. If the closing of
66: * the stream throws an exception, the exception is logged.
67: * </p>
68: *
69: * @param output
70: * the output stream to close.
71: * @param role
72: * the role of the output stream.
73: * @param log
74: * the log to which to log a messge if closing the stream
75: * throws an exception.
76: */
77: public static void close(OutputStream output, String role,
78: BrokenLinkCheckerLog log) {
79: try {
80: output.close();
81: } catch (Exception e) {
82: log.warning(
83: "An error occurred during closing of output stream: "
84: + role, e);
85: }
86: }
87: }
|