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(File source, File destination)
033                    throws IOException {
034    
035                    getFile().copyDirectory(source, destination);
036            }
037    
038            public static void copyDirectory(
039                            String sourceDirName, String destinationDirName)
040                    throws IOException {
041    
042                    getFile().copyDirectory(sourceDirName, destinationDirName);
043            }
044    
045            public static void copyFile(File source, File destination)
046                    throws IOException {
047    
048                    getFile().copyFile(source, destination);
049            }
050    
051            public static void copyFile(File source, File destination, boolean lazy)
052                    throws IOException {
053    
054                    getFile().copyFile(source, destination, lazy);
055            }
056    
057            public static void copyFile(String source, String destination)
058                    throws IOException {
059    
060                    getFile().copyFile(source, destination);
061            }
062    
063            public static void copyFile(String source, String 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(InputStream is) throws IOException {
078                    return getFile().createTempFile(is);
079            }
080    
081            public static File createTempFile(String extension) {
082                    return getFile().createTempFile(extension);
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(File file) {
098                    return getFile().delete(file);
099            }
100    
101            public static boolean delete(String file) {
102                    return getFile().delete(file);
103            }
104    
105            public static void deltree(File directory) {
106                    getFile().deltree(directory);
107            }
108    
109            public static void deltree(String 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(File file) {
118                    return getFile().exists(file);
119            }
120    
121            public static boolean exists(String fileName) {
122                    return getFile().exists(fileName);
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(File file) {
198                    return getFile().listDirs(file);
199            }
200    
201            public static String[] listDirs(String fileName) {
202                    return getFile().listDirs(fileName);
203            }
204    
205            public static String[] listFiles(File file) {
206                    return getFile().listFiles(file);
207            }
208    
209            public static String[] listFiles(String fileName) {
210                    return getFile().listFiles(fileName);
211            }
212    
213            public static void mkdirs(String pathName) {
214                    getFile().mkdirs(pathName);
215            }
216    
217            public static boolean move(File source, File destination) {
218                    return getFile().move(source, destination);
219            }
220    
221            public static boolean move(
222                    String sourceFileName, String destinationFileName) {
223    
224                    return getFile().move(sourceFileName, destinationFileName);
225            }
226    
227            public static String read(File file) throws IOException {
228                    return getFile().read(file);
229            }
230    
231            public static String read(File file, boolean raw) throws IOException {
232                    return getFile().read(file, raw);
233            }
234    
235            public static String read(String fileName) throws IOException {
236                    return getFile().read(fileName);
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 Properties toProperties(FileInputStream fis) {
260                    return getFile().toProperties(fis);
261            }
262    
263            public static Properties toProperties(String fileName) {
264                    return getFile().toProperties(fileName);
265            }
266    
267            public static void touch(File file) throws IOException {
268                    getFile().touch(file);
269            }
270    
271            public static void touch(String fileName) throws IOException {
272                    getFile().touch(fileName);
273            }
274    
275            public static void unzip(File source, File destination) {
276                    getFile().unzip(source, destination);
277            }
278    
279            public static void write(File file, byte[] bytes) throws IOException {
280                    getFile().write(file, bytes);
281            }
282    
283            public static void write(File file, byte[] bytes, int offset, int length)
284                    throws IOException {
285    
286                    getFile().write(file, bytes, offset, length);
287            }
288    
289            public static void write(File file, InputStream is) throws IOException {
290                    getFile().write(file, is);
291            }
292    
293            public static void write(File file, String s) throws IOException {
294                    getFile().write(file, s);
295            }
296    
297            public static void write(File file, String s, boolean lazy)
298                    throws IOException {
299    
300                    getFile().write(file, s, lazy);
301            }
302    
303            public static void write(File file, String s, boolean lazy, boolean append)
304                    throws IOException {
305    
306                    getFile().write(file, s, lazy, append);
307            }
308    
309            public static void write(String fileName, byte[] bytes) throws IOException {
310                    getFile().write(fileName, bytes);
311            }
312    
313            public static void write(String fileName, InputStream is)
314                    throws IOException {
315    
316                    getFile().write(fileName, is);
317            }
318    
319            public static void write(String fileName, String s) throws IOException {
320                    getFile().write(fileName, s);
321            }
322    
323            public static void write(String fileName, String s, boolean lazy)
324                    throws IOException {
325    
326                    getFile().write(fileName, s, lazy);
327            }
328    
329            public static void write(
330                            String fileName, String s, boolean lazy, boolean append)
331                    throws IOException {
332    
333                    getFile().write(fileName, s, lazy, append);
334            }
335    
336            public static void write(String pathName, String fileName, String s)
337                    throws IOException {
338    
339                    getFile().write(pathName, fileName, s);
340            }
341    
342            public static void write(
343                            String pathName, String fileName, String s, boolean lazy)
344                    throws IOException {
345    
346                    getFile().write(pathName, fileName, s, lazy);
347            }
348    
349            public static void write(
350                            String pathName, String fileName, String s, boolean lazy,
351                            boolean append)
352                    throws IOException {
353    
354                    getFile().write(pathName, fileName, s, lazy, append);
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    }