1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.util;
16  
17  import java.io.File;
18  import java.io.FileInputStream;
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.io.Reader;
22  
23  import java.util.List;
24  import java.util.Properties;
25  
26  /**
27   * <a href="FileUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   * @author Alexander Chow
31   */
32  public class FileUtil {
33  
34      public static void copyDirectory(
35          String sourceDirName, String destinationDirName) {
36  
37          getFile().copyDirectory(sourceDirName, destinationDirName);
38      }
39  
40      public static void copyDirectory(File source, File destination) {
41          getFile().copyDirectory(source, destination);
42      }
43  
44      public static void copyFile(String source, String destination) {
45          getFile().copyFile(source, destination);
46      }
47  
48      public static void copyFile(
49          String source, String destination, boolean lazy) {
50  
51          getFile().copyFile(source, destination, lazy);
52      }
53  
54      public static void copyFile(File source, File destination) {
55          getFile().copyFile(source, destination);
56      }
57  
58      public static void copyFile(File source, File destination, boolean lazy) {
59          getFile().copyFile(source, destination, lazy);
60      }
61  
62      public static File createTempFile() {
63          return getFile().createTempFile();
64      }
65  
66      public static File createTempFile(String extension) {
67          return getFile().createTempFile(extension);
68      }
69  
70      public static String createTempFileName() {
71          return getFile().createTempFileName();
72      }
73  
74      public static String createTempFileName(String extension) {
75          return getFile().createTempFileName(extension);
76      }
77  
78      public static String decodeSafeFileName(String fileName) {
79          return getFile().decodeSafeFileName(fileName);
80      }
81  
82      public static boolean delete(String file) {
83          return getFile().delete(file);
84      }
85  
86      public static boolean delete(File file) {
87          return getFile().delete(file);
88      }
89  
90      public static void deltree(String directory) {
91          getFile().deltree(directory);
92      }
93  
94      public static void deltree(File directory) {
95          getFile().deltree(directory);
96      }
97  
98      public static String encodeSafeFileName(String fileName) {
99          return getFile().encodeSafeFileName(fileName);
100     }
101 
102     public static boolean exists(String fileName) {
103         return getFile().exists(fileName);
104     }
105 
106     public static boolean exists(File file) {
107         return getFile().exists(file);
108     }
109 
110     /**
111      * Extract text from an input stream and file name.
112      *
113      * @param  is input stream of file
114      * @param  fileName full name or extension of file (e.g., "Test.doc",
115      *         ".doc")
116      * @return Extracted text if it is a supported format or an empty string if
117      *         it is an unsupported format
118      */
119     public static String extractText(InputStream is, String fileName) {
120         return getFile().extractText(is, fileName);
121     }
122 
123     public static String[] find(
124         String directory, String includes, String excludes) {
125 
126         return getFile().find(directory, includes, excludes);
127     }
128 
129     public static String getAbsolutePath(File file) {
130         return getFile().getAbsolutePath(file);
131     }
132 
133     public static byte[] getBytes(File file) throws IOException {
134         return getFile().getBytes(file);
135     }
136 
137     public static byte[] getBytes(InputStream is) throws IOException {
138         return getFile().getBytes(is);
139     }
140 
141     public static byte[] getBytes(InputStream is, int bufferSize)
142         throws IOException {
143 
144         return getFile().getBytes(is);
145     }
146 
147     public static String getExtension(String fileName) {
148         return getFile().getExtension(fileName);
149     }
150 
151     public static com.liferay.portal.kernel.util.File getFile() {
152         return _file;
153     }
154 
155     public static String getPath(String fullFileName) {
156         return getFile().getPath(fullFileName);
157     }
158 
159     public static String getShortFileName(String fullFileName) {
160         return getFile().getShortFileName(fullFileName);
161     }
162 
163     public static boolean isAscii(File file) throws IOException {
164         return getFile().isAscii(file);
165     }
166 
167     public static String[] listDirs(String fileName) {
168         return getFile().listDirs(fileName);
169     }
170 
171     public static String[] listDirs(File file) {
172         return getFile().listDirs(file);
173     }
174 
175     public static String[] listFiles(String fileName) {
176         return getFile().listFiles(fileName);
177     }
178 
179     public static String[] listFiles(File file) {
180         return getFile().listFiles(file);
181     }
182 
183     public static void mkdirs(String pathName) {
184         getFile().mkdirs(pathName);
185     }
186 
187     public static boolean move(
188         String sourceFileName, String destinationFileName) {
189 
190         return getFile().move(sourceFileName, destinationFileName);
191     }
192 
193     public static boolean move(File source, File destination) {
194         return getFile().move(source, destination);
195     }
196 
197     public static String read(String fileName) throws IOException {
198         return getFile().read(fileName);
199     }
200 
201     public static String read(File file) throws IOException {
202         return getFile().read(file);
203     }
204 
205     public static String read(File file, boolean raw) throws IOException {
206         return getFile().read(file, raw);
207     }
208 
209     public static String replaceSeparator(String fileName) {
210         return getFile().replaceSeparator(fileName);
211     }
212 
213     public static File[] sortFiles(File[] files) {
214         return getFile().sortFiles(files);
215     }
216 
217     public static String stripExtension(String fileName) {
218         return getFile().stripExtension(fileName);
219     }
220 
221     public static List<String> toList(Reader reader) {
222         return getFile().toList(reader);
223     }
224 
225     public static List<String> toList(String fileName) {
226         return getFile().toList(fileName);
227     }
228 
229     public static Properties toProperties(FileInputStream fis) {
230         return getFile().toProperties(fis);
231     }
232 
233     public static Properties toProperties(String fileName) {
234         return getFile().toProperties(fileName);
235     }
236 
237     public static void write(String fileName, String s) throws IOException {
238         getFile().write(fileName, s);
239     }
240 
241     public static void write(String fileName, String s, boolean lazy)
242         throws IOException {
243 
244         getFile().write(fileName, s, lazy);
245     }
246 
247     public static void write(
248             String fileName, String s, boolean lazy, boolean append)
249         throws IOException {
250 
251         getFile().write(fileName, s, lazy, append);
252     }
253 
254     public static void write(String pathName, String fileName, String s)
255         throws IOException {
256 
257         getFile().write(pathName, fileName, s);
258     }
259 
260     public static void write(
261             String pathName, String fileName, String s, boolean lazy)
262         throws IOException {
263 
264         getFile().write(pathName, fileName, s, lazy);
265     }
266 
267     public static void write(
268             String pathName, String fileName, String s, boolean lazy,
269             boolean append)
270         throws IOException {
271 
272         getFile().write(pathName, fileName, s, lazy, append);
273     }
274 
275     public static void write(File file, String s) throws IOException {
276         getFile().write(file, s);
277     }
278 
279     public static void write(File file, String s, boolean lazy)
280         throws IOException {
281 
282         getFile().write(file, s, lazy);
283     }
284 
285     public static void write(File file, String s, boolean lazy, boolean append)
286         throws IOException {
287 
288         getFile().write(file, s, lazy, append);
289     }
290 
291     public static void write(String fileName, byte[] bytes) throws IOException {
292         getFile().write(fileName, bytes);
293     }
294 
295     public static void write(File file, byte[] bytes) throws IOException {
296         getFile().write(file, bytes);
297     }
298 
299     public static void write(File file, byte[] bytes, int offset, int length)
300         throws IOException {
301 
302         getFile().write(file, bytes, offset, length);
303     }
304 
305     public static void write(String fileName, InputStream is)
306         throws IOException {
307 
308         getFile().write(fileName, is);
309     }
310 
311     public static void write(File file, InputStream is) throws IOException {
312         getFile().write(file, is);
313     }
314 
315     public void setFile(com.liferay.portal.kernel.util.File file) {
316         _file = file;
317     }
318 
319     private static com.liferay.portal.kernel.util.File _file;
320 
321 }