View Javadoc

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