1 /*
2 * Copyright 2001-2006 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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 /*
17 Copyright 2002-2006 Martin van den Bemt
18
19 Licensed under the Apache License, Version 2.0 (the "License");
20 you may not use this file except in compliance with the License.
21 You may obtain a copy of the License at
22
23 http://www.apache.org/licenses/LICENSE-2.0
24
25 Unless required by applicable law or agreed to in writing, software
26 distributed under the License is distributed on an "AS IS" BASIS,
27 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 See the License for the specific language governing permissions and
29 limitations under the License.
30 */
31 package org.xulux.utils.io;
32
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.io.OutputStream;
36 import java.io.Reader;
37 import java.io.Writer;
38
39 /**
40 * Removed javadoc. The closeQuietly are all copy & paste from Apache jakarta io
41 */
42 public class IOUtils {
43
44 /**
45 * Unconditionally close an <code>Reader</code>.
46 * <p>
47 * Equivalent to {@link Reader#close()}, except any exceptions will be ignored.
48 * This is typically used in finally blocks.
49 *
50 * @param input the Reader to close, may be null or already closed
51 */
52 public static void closeQuietly(Reader input) {
53 try {
54 if (input != null) {
55 input.close();
56 }
57 } catch (IOException ioe) {
58 // ignore
59 }
60 }
61
62 /**
63 * Unconditionally close a <code>Writer</code>.
64 * <p>
65 * Equivalent to {@link Writer#close()}, except any exceptions will be ignored.
66 * This is typically used in finally blocks.
67 *
68 * @param output the Writer to close, may be null or already closed
69 */
70 public static void closeQuietly(Writer output) {
71 try {
72 if (output != null) {
73 output.close();
74 }
75 } catch (IOException ioe) {
76 // ignore
77 }
78 }
79
80 /**
81 * Unconditionally close an <code>InputStream</code>.
82 * <p>
83 * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored.
84 * This is typically used in finally blocks.
85 *
86 * @param input the InputStream to close, may be null or already closed
87 */
88 public static void closeQuietly(InputStream input) {
89 try {
90 if (input != null) {
91 input.close();
92 }
93 } catch (IOException ioe) {
94 // ignore
95 }
96 }
97
98 /**
99 * Unconditionally close an <code>OutputStream</code>.
100 * <p>
101 * Equivalent to {@link OutputStream#close()}, except any exceptions will be ignored.
102 * This is typically used in finally blocks.
103 *
104 * @param output the OutputStream to close, may be null or already closed
105 */
106 public static void closeQuietly(OutputStream output) {
107 try {
108 if (output != null) {
109 output.close();
110 }
111 } catch (IOException ioe) {
112 // ignore
113 }
114 }
115
116 /**
117 * @return the line seperator
118 */
119 public static String getLineSeperator() {
120 return System.getProperty("line.separator");
121 }
122
123 }