001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.util;
016    
017    import java.io.File;
018    import java.io.FileInputStream;
019    import java.io.IOException;
020    import java.io.InputStream;
021    import java.io.Reader;
022    
023    import java.util.List;
024    import java.util.Properties;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Alexander Chow
029     */
030    public class FileUtil {
031    
032            public static void copyDirectory(
033                            String sourceDirName, String destinationDirName)
034                    throws IOException {
035    
036                    getFile().copyDirectory(sourceDirName, destinationDirName);
037            }
038    
039            public static void copyDirectory(File source, File destination)
040                    throws IOException {
041    
042                    getFile().copyDirectory(source, destination);
043            }
044    
045            public static void copyFile(String source, String destination)
046                    throws IOException {
047    
048                    getFile().copyFile(source, destination);
049            }
050    
051            public static void copyFile(
052                            String source, String destination, boolean lazy)
053                    throws IOException {
054    
055                    getFile().copyFile(source, destination, lazy);
056            }
057    
058            public static void copyFile(File source, File destination)
059                    throws IOException {
060    
061                    getFile().copyFile(source, destination);
062            }
063    
064            public static void copyFile(File source, File destination, boolean lazy)
065                    throws IOException {
066    
067                    getFile().copyFile(source, destination, lazy);
068            }
069    
070            public static File createTempFile() {
071                    return getFile().createTempFile();
072            }
073    
074            public static File createTempFile(byte[] bytes) throws IOException {
075                    return getFile().createTempFile(bytes);
076            }
077    
078            public static File createTempFile(String extension) {
079                    return getFile().createTempFile(extension);
080            }
081    
082            public static File createTempFile(InputStream is) throws IOException {
083                    return getFile().createTempFile(is);
084            }
085    
086            public static String createTempFileName() {
087                    return getFile().createTempFileName();
088            }
089    
090            public static String createTempFileName(String extension) {
091                    return getFile().createTempFileName(extension);
092            }
093    
094            public static String decodeSafeFileName(String fileName) {
095                    return getFile().decodeSafeFileName(fileName);
096            }
097    
098            public static boolean delete(String file) {
099                    return getFile().delete(file);
100            }
101    
102            public static boolean delete(File file) {
103                    return getFile().delete(file);
104            }
105    
106            public static void deltree(String directory) {
107                    getFile().deltree(directory);
108            }
109    
110            public static void deltree(File directory) {
111                    getFile().deltree(directory);
112            }
113    
114            public static String encodeSafeFileName(String fileName) {
115                    return getFile().encodeSafeFileName(fileName);
116            }
117    
118            public static boolean exists(String fileName) {
119                    return getFile().exists(fileName);
120            }
121    
122            public static boolean exists(File file) {
123                    return getFile().exists(file);
124            }
125    
126            /**
127             * Extract text from an input stream and file name.
128             *
129             * @param  is input stream of file
130             * @param  fileName full name or extension of file (e.g., "Test.doc",
131             *         ".doc")
132             * @return Extracted text if it is a supported format or an empty string if
133             *         it is an unsupported format
134             */
135            public static String extractText(InputStream is, String fileName) {
136                    return getFile().extractText(is, fileName);
137            }
138    
139            public static String[] find(
140                    String directory, String includes, String excludes) {
141    
142                    return getFile().find(directory, includes, excludes);
143            }
144    
145            public static String getAbsolutePath(File file) {
146                    return getFile().getAbsolutePath(file);
147            }
148    
149            public static byte[] getBytes(File file) throws IOException {
150                    return getFile().getBytes(file);
151            }
152    
153            public static byte[] getBytes(InputStream is) throws IOException {
154                    return getFile().getBytes(is);
155            }
156    
157            public static byte[] getBytes(InputStream is, int bufferSize)
158                    throws IOException {
159    
160                    return getFile().getBytes(is);
161            }
162    
163            public static String getExtension(String fileName) {
164                    return getFile().getExtension(fileName);
165            }
166    
167            public static com.liferay.portal.kernel.util.File getFile() {
168                    return _file;
169            }
170    
171            public static String getPath(String fullFileName) {
172                    return getFile().getPath(fullFileName);
173            }
174    
175            public static String getShortFileName(String fullFileName) {
176                    return getFile().getShortFileName(fullFileName);
177            }
178    
179            public static boolean isAscii(File file) throws IOException {
180                    return getFile().isAscii(file);
181            }
182    
183            public static boolean isSameContent(File file, byte[] bytes, int length) {
184                    return getFile().isSameContent(file, bytes, length);
185            }
186    
187            public static boolean isSameContent(File file, String s) {
188                    return getFile().isSameContent(file, s);
189            }
190    
191            public static String[] listDirs(String fileName) {
192                    return getFile().listDirs(fileName);
193            }
194    
195            public static String[] listDirs(File file) {
196                    return getFile().listDirs(file);
197            }
198    
199            public static String[] listFiles(String fileName) {
200                    return getFile().listFiles(fileName);
201            }
202    
203            public static String[] listFiles(File file) {
204                    return getFile().listFiles(file);
205            }
206    
207            public static void mkdirs(String pathName) {
208                    getFile().mkdirs(pathName);
209            }
210    
211            public static boolean move(
212                    String sourceFileName, String destinationFileName) {
213    
214                    return getFile().move(sourceFileName, destinationFileName);
215            }
216    
217            public static boolean move(File source, File destination) {
218                    return getFile().move(source, destination);
219            }
220    
221            public static String read(String fileName) throws IOException {
222                    return getFile().read(fileName);
223            }
224    
225            public static String read(File file) throws IOException {
226                    return getFile().read(file);
227            }
228    
229            public static String read(File file, boolean raw) throws IOException {
230                    return getFile().read(file, raw);
231            }
232    
233            public static String replaceSeparator(String fileName) {
234                    return getFile().replaceSeparator(fileName);
235            }
236    
237            public static File[] sortFiles(File[] files) {
238                    return getFile().sortFiles(files);
239            }
240    
241            public static String stripExtension(String fileName) {
242                    return getFile().stripExtension(fileName);
243            }
244    
245            public static List<String> toList(Reader reader) {
246                    return getFile().toList(reader);
247            }
248    
249            public static List<String> toList(String fileName) {
250                    return getFile().toList(fileName);
251            }
252    
253            public static void touch(File file) throws IOException {
254                    getFile().touch(file);
255            }
256    
257            public static void touch(String fileName) throws IOException {
258                    getFile().touch(fileName);
259            }
260    
261            public static Properties toProperties(FileInputStream fis) {
262                    return getFile().toProperties(fis);
263            }
264    
265            public static Properties toProperties(String fileName) {
266                    return getFile().toProperties(fileName);
267            }
268    
269            public static void unzip(File source, File destination) {
270                    getFile().unzip(source, destination);
271            }
272    
273            public static void write(String fileName, String s) throws IOException {
274                    getFile().write(fileName, s);
275            }
276    
277            public static void write(String fileName, String s, boolean lazy)
278                    throws IOException {
279    
280                    getFile().write(fileName, s, lazy);
281            }
282    
283            public static void write(
284                            String fileName, String s, boolean lazy, boolean append)
285                    throws IOException {
286    
287                    getFile().write(fileName, s, lazy, append);
288            }
289    
290            public static void write(String pathName, String fileName, String s)
291                    throws IOException {
292    
293                    getFile().write(pathName, fileName, s);
294            }
295    
296            public static void write(
297                            String pathName, String fileName, String s, boolean lazy)
298                    throws IOException {
299    
300                    getFile().write(pathName, fileName, s, lazy);
301            }
302    
303            public static void write(
304                            String pathName, String fileName, String s, boolean lazy,
305                            boolean append)
306                    throws IOException {
307    
308                    getFile().write(pathName, fileName, s, lazy, append);
309            }
310    
311            public static void write(File file, String s) throws IOException {
312                    getFile().write(file, s);
313            }
314    
315            public static void write(File file, String s, boolean lazy)
316                    throws IOException {
317    
318                    getFile().write(file, s, lazy);
319            }
320    
321            public static void write(File file, String s, boolean lazy, boolean append)
322                    throws IOException {
323    
324                    getFile().write(file, s, lazy, append);
325            }
326    
327            public static void write(String fileName, byte[] bytes) throws IOException {
328                    getFile().write(fileName, bytes);
329            }
330    
331            public static void write(File file, byte[] bytes) throws IOException {
332                    getFile().write(file, bytes);
333            }
334    
335            public static void write(File file, byte[] bytes, int offset, int length)
336                    throws IOException {
337    
338                    getFile().write(file, bytes, offset, length);
339            }
340    
341            public static void write(String fileName, InputStream is)
342                    throws IOException {
343    
344                    getFile().write(fileName, is);
345            }
346    
347            public static void write(File file, InputStream is) throws IOException {
348                    getFile().write(file, is);
349            }
350    
351            public void setFile(com.liferay.portal.kernel.util.File file) {
352                    _file = file;
353            }
354    
355            private static com.liferay.portal.kernel.util.File _file;
356    
357    }