001    /**
002     * Copyright (c) 2000-2010 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    
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 getAbsolutePath(File file) {
122                    return getFile().getAbsolutePath(file);
123            }
124    
125            public static byte[] getBytes(File file) throws IOException {
126                    return getFile().getBytes(file);
127            }
128    
129            public static byte[] getBytes(InputStream is) throws IOException {
130                    return getFile().getBytes(is);
131            }
132    
133            public static byte[] getBytes(InputStream is, int bufferSize)
134                    throws IOException {
135    
136                    return getFile().getBytes(is);
137            }
138    
139            public static String getExtension(String fileName) {
140                    return getFile().getExtension(fileName);
141            }
142    
143            public static com.liferay.portal.kernel.util.File getFile() {
144                    return _file;
145            }
146    
147            public static String getPath(String fullFileName) {
148                    return getFile().getPath(fullFileName);
149            }
150    
151            public static String getShortFileName(String fullFileName) {
152                    return getFile().getShortFileName(fullFileName);
153            }
154    
155            public static boolean isAscii(File file) throws IOException {
156                    return getFile().isAscii(file);
157            }
158    
159            public static String[] listDirs(String fileName) {
160                    return getFile().listDirs(fileName);
161            }
162    
163            public static String[] listDirs(File file) {
164                    return getFile().listDirs(file);
165            }
166    
167            public static String[] listFiles(String fileName) {
168                    return getFile().listFiles(fileName);
169            }
170    
171            public static String[] listFiles(File file) {
172                    return getFile().listFiles(file);
173            }
174    
175            public static void mkdirs(String pathName) {
176                    getFile().mkdirs(pathName);
177            }
178    
179            public static boolean move(
180                    String sourceFileName, String destinationFileName) {
181    
182                    return getFile().move(sourceFileName, destinationFileName);
183            }
184    
185            public static boolean move(File source, File destination) {
186                    return getFile().move(source, destination);
187            }
188    
189            public static String read(String fileName) throws IOException {
190                    return getFile().read(fileName);
191            }
192    
193            public static String read(File file) throws IOException {
194                    return getFile().read(file);
195            }
196    
197            public static String read(File file, boolean raw) throws IOException {
198                    return getFile().read(file, raw);
199            }
200    
201            public static String replaceSeparator(String fileName) {
202                    return getFile().replaceSeparator(fileName);
203            }
204    
205            public static File[] sortFiles(File[] files) {
206                    return getFile().sortFiles(files);
207            }
208    
209            public static String stripExtension(String fileName) {
210                    return getFile().stripExtension(fileName);
211            }
212    
213            public static List<String> toList(Reader reader) {
214                    return getFile().toList(reader);
215            }
216    
217            public static List<String> toList(String fileName) {
218                    return getFile().toList(fileName);
219            }
220    
221            public static Properties toProperties(FileInputStream fis) {
222                    return getFile().toProperties(fis);
223            }
224    
225            public static Properties toProperties(String fileName) {
226                    return getFile().toProperties(fileName);
227            }
228    
229            public static void write(String fileName, String s) throws IOException {
230                    getFile().write(fileName, s);
231            }
232    
233            public static void write(String fileName, String s, boolean lazy)
234                    throws IOException {
235    
236                    getFile().write(fileName, s, lazy);
237            }
238    
239            public static void write(
240                            String fileName, String s, boolean lazy, boolean append)
241                    throws IOException {
242    
243                    getFile().write(fileName, s, lazy, append);
244            }
245    
246            public static void write(String pathName, String fileName, String s)
247                    throws IOException {
248    
249                    getFile().write(pathName, fileName, s);
250            }
251    
252            public static void write(
253                            String pathName, String fileName, String s, boolean lazy)
254                    throws IOException {
255    
256                    getFile().write(pathName, fileName, s, lazy);
257            }
258    
259            public static void write(
260                            String pathName, String fileName, String s, boolean lazy,
261                            boolean append)
262                    throws IOException {
263    
264                    getFile().write(pathName, fileName, s, lazy, append);
265            }
266    
267            public static void write(File file, String s) throws IOException {
268                    getFile().write(file, s);
269            }
270    
271            public static void write(File file, String s, boolean lazy)
272                    throws IOException {
273    
274                    getFile().write(file, s, lazy);
275            }
276    
277            public static void write(File file, String s, boolean lazy, boolean append)
278                    throws IOException {
279    
280                    getFile().write(file, s, lazy, append);
281            }
282    
283            public static void write(String fileName, byte[] bytes) throws IOException {
284                    getFile().write(fileName, bytes);
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(String fileName, InputStream is)
298                    throws IOException {
299    
300                    getFile().write(fileName, is);
301            }
302    
303            public static void write(File file, InputStream is) throws IOException {
304                    getFile().write(file, is);
305            }
306    
307            public void setFile(com.liferay.portal.kernel.util.File file) {
308                    _file = file;
309            }
310    
311            private static com.liferay.portal.kernel.util.File _file;
312    
313    }