001    /**
002     * Copyright (c) 2000-2012 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(String source, String destination, boolean lazy)
052                    throws IOException {
053    
054                    getFile().copyFile(source, destination, lazy);
055            }
056    
057            public static void copyFile(File source, File destination)
058                    throws IOException {
059    
060                    getFile().copyFile(source, destination);
061            }
062    
063            public static void copyFile(File source, File destination, boolean lazy)
064                    throws IOException {
065    
066                    getFile().copyFile(source, destination, lazy);
067            }
068    
069            public static File createTempFile() {
070                    return getFile().createTempFile();
071            }
072    
073            public static File createTempFile(byte[] bytes) throws IOException {
074                    return getFile().createTempFile(bytes);
075            }
076    
077            public static File createTempFile(String extension) {
078                    return getFile().createTempFile(extension);
079            }
080    
081            public static File createTempFile(InputStream is) throws IOException {
082                    return getFile().createTempFile(is);
083            }
084    
085            public static String createTempFileName() {
086                    return getFile().createTempFileName();
087            }
088    
089            public static String createTempFileName(String extension) {
090                    return getFile().createTempFileName(extension);
091            }
092    
093            public static String decodeSafeFileName(String fileName) {
094                    return getFile().decodeSafeFileName(fileName);
095            }
096    
097            public static boolean delete(String file) {
098                    return getFile().delete(file);
099            }
100    
101            public static boolean delete(File file) {
102                    return getFile().delete(file);
103            }
104    
105            public static void deltree(String directory) {
106                    getFile().deltree(directory);
107            }
108    
109            public static void deltree(File directory) {
110                    getFile().deltree(directory);
111            }
112    
113            public static String encodeSafeFileName(String fileName) {
114                    return getFile().encodeSafeFileName(fileName);
115            }
116    
117            public static boolean exists(String fileName) {
118                    return getFile().exists(fileName);
119            }
120    
121            public static boolean exists(File file) {
122                    return getFile().exists(file);
123            }
124    
125            /**
126             * Extract text from an input stream and file name.
127             *
128             * @param  is input stream of file
129             * @param  fileName full name or extension of file (e.g., "Test.doc",
130             *         ".doc")
131             * @return Extracted text if it is a supported format or an empty string if
132             *         it is an unsupported format
133             */
134            public static String extractText(InputStream is, String fileName) {
135                    return getFile().extractText(is, fileName);
136            }
137    
138            public static String[] find(
139                    String directory, String includes, String excludes) {
140    
141                    return getFile().find(directory, includes, excludes);
142            }
143    
144            public static String getAbsolutePath(File file) {
145                    return getFile().getAbsolutePath(file);
146            }
147    
148            public static byte[] getBytes(File file) throws IOException {
149                    return getFile().getBytes(file);
150            }
151    
152            public static byte[] getBytes(InputStream is) throws IOException {
153                    return getFile().getBytes(is);
154            }
155    
156            public static byte[] getBytes(InputStream is, int bufferSize)
157                    throws IOException {
158    
159                    return getFile().getBytes(is);
160            }
161    
162            public static byte[] getBytes(
163                            InputStream is, int bufferSize, boolean cleanUpStream)
164                    throws IOException {
165    
166                    return getFile().getBytes(is, bufferSize, cleanUpStream);
167            }
168    
169            public static String getExtension(String fileName) {
170                    return getFile().getExtension(fileName);
171            }
172    
173            public static com.liferay.portal.kernel.util.File getFile() {
174                    return _file;
175            }
176    
177            public static String getPath(String fullFileName) {
178                    return getFile().getPath(fullFileName);
179            }
180    
181            public static String getShortFileName(String fullFileName) {
182                    return getFile().getShortFileName(fullFileName);
183            }
184    
185            public static boolean isAscii(File file) throws IOException {
186                    return getFile().isAscii(file);
187            }
188    
189            public static boolean isSameContent(File file, byte[] bytes, int length) {
190                    return getFile().isSameContent(file, bytes, length);
191            }
192    
193            public static boolean isSameContent(File file, String s) {
194                    return getFile().isSameContent(file, s);
195            }
196    
197            public static String[] listDirs(String fileName) {
198                    return getFile().listDirs(fileName);
199            }
200    
201            public static String[] listDirs(File file) {
202                    return getFile().listDirs(file);
203            }
204    
205            public static String[] listFiles(String fileName) {
206                    return getFile().listFiles(fileName);
207            }
208    
209            public static String[] listFiles(File file) {
210                    return getFile().listFiles(file);
211            }
212    
213            public static void mkdirs(String pathName) {
214                    getFile().mkdirs(pathName);
215            }
216    
217            public static boolean move(
218                    String sourceFileName, String destinationFileName) {
219    
220                    return getFile().move(sourceFileName, destinationFileName);
221            }
222    
223            public static boolean move(File source, File destination) {
224                    return getFile().move(source, destination);
225            }
226    
227            public static String read(String fileName) throws IOException {
228                    return getFile().read(fileName);
229            }
230    
231            public static String read(File file) throws IOException {
232                    return getFile().read(file);
233            }
234    
235            public static String read(File file, boolean raw) throws IOException {
236                    return getFile().read(file, raw);
237            }
238    
239            public static String replaceSeparator(String fileName) {
240                    return getFile().replaceSeparator(fileName);
241            }
242    
243            public static File[] sortFiles(File[] files) {
244                    return getFile().sortFiles(files);
245            }
246    
247            public static String stripExtension(String fileName) {
248                    return getFile().stripExtension(fileName);
249            }
250    
251            public static List<String> toList(Reader reader) {
252                    return getFile().toList(reader);
253            }
254    
255            public static List<String> toList(String fileName) {
256                    return getFile().toList(fileName);
257            }
258    
259            public static void touch(File file) throws IOException {
260                    getFile().touch(file);
261            }
262    
263            public static void touch(String fileName) throws IOException {
264                    getFile().touch(fileName);
265            }
266    
267            public static Properties toProperties(FileInputStream fis) {
268                    return getFile().toProperties(fis);
269            }
270    
271            public static Properties toProperties(String fileName) {
272                    return getFile().toProperties(fileName);
273            }
274    
275            public static void unzip(File source, File destination) {
276                    getFile().unzip(source, destination);
277            }
278    
279            public static void write(String fileName, String s) throws IOException {
280                    getFile().write(fileName, s);
281            }
282    
283            public static void write(String fileName, String s, boolean lazy)
284                    throws IOException {
285    
286                    getFile().write(fileName, s, lazy);
287            }
288    
289            public static void write(
290                            String fileName, String s, boolean lazy, boolean append)
291                    throws IOException {
292    
293                    getFile().write(fileName, s, lazy, append);
294            }
295    
296            public static void write(String pathName, String fileName, String s)
297                    throws IOException {
298    
299                    getFile().write(pathName, fileName, s);
300            }
301    
302            public static void write(
303                            String pathName, String fileName, String s, boolean lazy)
304                    throws IOException {
305    
306                    getFile().write(pathName, fileName, s, lazy);
307            }
308    
309            public static void write(
310                            String pathName, String fileName, String s, boolean lazy,
311                            boolean append)
312                    throws IOException {
313    
314                    getFile().write(pathName, fileName, s, lazy, append);
315            }
316    
317            public static void write(File file, String s) throws IOException {
318                    getFile().write(file, s);
319            }
320    
321            public static void write(File file, String s, boolean lazy)
322                    throws IOException {
323    
324                    getFile().write(file, s, lazy);
325            }
326    
327            public static void write(File file, String s, boolean lazy, boolean append)
328                    throws IOException {
329    
330                    getFile().write(file, s, lazy, append);
331            }
332    
333            public static void write(String fileName, byte[] bytes) throws IOException {
334                    getFile().write(fileName, bytes);
335            }
336    
337            public static void write(File file, byte[] bytes) throws IOException {
338                    getFile().write(file, bytes);
339            }
340    
341            public static void write(File file, byte[] bytes, int offset, int length)
342                    throws IOException {
343    
344                    getFile().write(file, bytes, offset, length);
345            }
346    
347            public static void write(String fileName, InputStream is)
348                    throws IOException {
349    
350                    getFile().write(fileName, is);
351            }
352    
353            public static void write(File file, InputStream is) throws IOException {
354                    getFile().write(file, is);
355            }
356    
357            public void setFile(com.liferay.portal.kernel.util.File file) {
358                    _file = file;
359            }
360    
361            private static com.liferay.portal.kernel.util.File _file;
362    
363    }