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