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