001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 byte[] getBytes(
164                            InputStream is, int bufferSize, boolean cleanUpStream)
165                    throws IOException {
166    
167                    return getFile().getBytes(is, bufferSize, cleanUpStream);
168            }
169    
170            public static String getExtension(String fileName) {
171                    return getFile().getExtension(fileName);
172            }
173    
174            public static com.liferay.portal.kernel.util.File getFile() {
175                    return _file;
176            }
177    
178            public static String getPath(String fullFileName) {
179                    return getFile().getPath(fullFileName);
180            }
181    
182            public static String getShortFileName(String fullFileName) {
183                    return getFile().getShortFileName(fullFileName);
184            }
185    
186            public static boolean isAscii(File file) throws IOException {
187                    return getFile().isAscii(file);
188            }
189    
190            public static boolean isSameContent(File file, byte[] bytes, int length) {
191                    return getFile().isSameContent(file, bytes, length);
192            }
193    
194            public static boolean isSameContent(File file, String s) {
195                    return getFile().isSameContent(file, s);
196            }
197    
198            public static String[] listDirs(String fileName) {
199                    return getFile().listDirs(fileName);
200            }
201    
202            public static String[] listDirs(File file) {
203                    return getFile().listDirs(file);
204            }
205    
206            public static String[] listFiles(String fileName) {
207                    return getFile().listFiles(fileName);
208            }
209    
210            public static String[] listFiles(File file) {
211                    return getFile().listFiles(file);
212            }
213    
214            public static void mkdirs(String pathName) {
215                    getFile().mkdirs(pathName);
216            }
217    
218            public static boolean move(
219                    String sourceFileName, String destinationFileName) {
220    
221                    return getFile().move(sourceFileName, destinationFileName);
222            }
223    
224            public static boolean move(File source, File destination) {
225                    return getFile().move(source, destination);
226            }
227    
228            public static String read(String fileName) throws IOException {
229                    return getFile().read(fileName);
230            }
231    
232            public static String read(File file) throws IOException {
233                    return getFile().read(file);
234            }
235    
236            public static String read(File file, boolean raw) throws IOException {
237                    return getFile().read(file, raw);
238            }
239    
240            public static String replaceSeparator(String fileName) {
241                    return getFile().replaceSeparator(fileName);
242            }
243    
244            public static File[] sortFiles(File[] files) {
245                    return getFile().sortFiles(files);
246            }
247    
248            public static String stripExtension(String fileName) {
249                    return getFile().stripExtension(fileName);
250            }
251    
252            public static List<String> toList(Reader reader) {
253                    return getFile().toList(reader);
254            }
255    
256            public static List<String> toList(String fileName) {
257                    return getFile().toList(fileName);
258            }
259    
260            public static void touch(File file) throws IOException {
261                    getFile().touch(file);
262            }
263    
264            public static void touch(String fileName) throws IOException {
265                    getFile().touch(fileName);
266            }
267    
268            public static Properties toProperties(FileInputStream fis) {
269                    return getFile().toProperties(fis);
270            }
271    
272            public static Properties toProperties(String fileName) {
273                    return getFile().toProperties(fileName);
274            }
275    
276            public static void unzip(File source, File destination) {
277                    getFile().unzip(source, destination);
278            }
279    
280            public static void write(String fileName, String s) throws IOException {
281                    getFile().write(fileName, s);
282            }
283    
284            public static void write(String fileName, String s, boolean lazy)
285                    throws IOException {
286    
287                    getFile().write(fileName, s, lazy);
288            }
289    
290            public static void write(
291                            String fileName, String s, boolean lazy, boolean append)
292                    throws IOException {
293    
294                    getFile().write(fileName, s, lazy, append);
295            }
296    
297            public static void write(String pathName, String fileName, String s)
298                    throws IOException {
299    
300                    getFile().write(pathName, fileName, s);
301            }
302    
303            public static void write(
304                            String pathName, String fileName, String s, boolean lazy)
305                    throws IOException {
306    
307                    getFile().write(pathName, fileName, s, lazy);
308            }
309    
310            public static void write(
311                            String pathName, String fileName, String s, boolean lazy,
312                            boolean append)
313                    throws IOException {
314    
315                    getFile().write(pathName, fileName, s, lazy, append);
316            }
317    
318            public static void write(File file, String s) throws IOException {
319                    getFile().write(file, s);
320            }
321    
322            public static void write(File file, String s, boolean lazy)
323                    throws IOException {
324    
325                    getFile().write(file, s, lazy);
326            }
327    
328            public static void write(File file, String s, boolean lazy, boolean append)
329                    throws IOException {
330    
331                    getFile().write(file, s, lazy, append);
332            }
333    
334            public static void write(String fileName, byte[] bytes) throws IOException {
335                    getFile().write(fileName, bytes);
336            }
337    
338            public static void write(File file, byte[] bytes) throws IOException {
339                    getFile().write(file, bytes);
340            }
341    
342            public static void write(File file, byte[] bytes, int offset, int length)
343                    throws IOException {
344    
345                    getFile().write(file, bytes, offset, length);
346            }
347    
348            public static void write(String fileName, InputStream is)
349                    throws IOException {
350    
351                    getFile().write(fileName, is);
352            }
353    
354            public static void write(File file, InputStream is) throws IOException {
355                    getFile().write(file, is);
356            }
357    
358            public void setFile(com.liferay.portal.kernel.util.File file) {
359                    _file = file;
360            }
361    
362            private static com.liferay.portal.kernel.util.File _file;
363    
364    }