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.Reader;
19: import nl.hippo.cms.brokenlinkchecker.log.BrokenLinkCheckerLog;
20:
21: /**
22: * <p>
23: * A utility class to help with cleaning up readers.
24: * </p>
25: */
26: public class ReaderCleanup {
27: /**
28: * <p>
29: * The only and private constructor to prevent instantiation of this
30: * class.
31: * </p>
32: */
33: public ReaderCleanup() {
34: super ();
35: }
36:
37: /**
38: * <p>
39: * Close a reader without throwing execptions. If the closing of the
40: * reader throws an exception, the exception is logged.
41: * </p>
42: *
43: * @param reader
44: * the reader to close.
45: * @param role
46: * the role of the reader.
47: * @param log
48: * the log to which to log a messge if closing the reader
49: * throws an exception.
50: */
51: public static void close(Reader reader, String role,
52: BrokenLinkCheckerLog log) {
53: try {
54: reader.close();
55: } catch (Exception e) {
56: log.warning("An error occurred during closing of reader: "
57: + role, e);
58: }
59: }
60: }
|