1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.util;
16  
17  import java.io.File;
18  import java.io.FileInputStream;
19  import java.io.IOException;
20  import java.io.InputStream;
21  import java.io.Reader;
22  
23  import java.util.List;
24  import java.util.Properties;
25  
26  /**
27   * <a href="FileUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   * @author Alexander Chow
31   */
32  public class FileUtil {
33  
34      public static void copyDirectory(
35          String sourceDirName, String destinationDirName) {
36  
37          getFile().copyDirectory(sourceDirName, destinationDirName);
38      }
39  
40      public static void copyDirectory(File source, File destination) {
41          getFile().copyDirectory(source, destination);
42      }
43  
44      public static void copyFile(String source, String destination) {
45          getFile().copyFile(source, destination);
46      }
47  
48      public static void copyFile(
49          String source, String destination, boolean lazy) {
50  
51          getFile().copyFile(source, destination, lazy);
52      }
53  
54      public static void copyFile(File source, File destination) {
55          getFile().copyFile(source, destination);
56      }
57  
58      public static void copyFile(File source, File destination, boolean lazy) {
59          getFile().copyFile(source, destination, lazy);
60      }
61  
62      public static File createTempFile() {
63          return getFile().createTempFile();
64      }
65  
66      public static File createTempFile(String extension) {
67          return getFile().createTempFile(extension);
68      }
69  
70      public static String createTempFileName() {
71          return getFile().createTempFileName();
72      }
73  
74      public static String createTempFileName(String extension) {
75          return getFile().createTempFileName(extension);
76      }
77  
78      public static String decodeSafeFileName(String fileName) {
79          return getFile().decodeSafeFileName(fileName);
80      }
81  
82      public static boolean delete(String file) {
83          return getFile().delete(file);
84      }
85  
86      public static boolean delete(File file) {
87          return getFile().delete(file);
88      }
89  
90      public static void deltree(String directory) {
91          getFile().deltree(directory);
92      }
93  
94      public static void deltree(File directory) {
95          getFile().deltree(directory);
96      }
97  
98      public static String encodeSafeFileName(String fileName) {
99          return getFile().encodeSafeFileName(fileName);
100     }
101 
102     public static boolean exists(String fileName) {
103         return getFile().exists(fileName);
104     }
105 
106     public static boolean exists(File file) {
107         return getFile().exists(file);
108     }
109 
110     /**
111      * Extract text from an input stream and file name.
112      *
113      * @param  is input stream of file
114      * @param  fileName full name or extension of file (e.g., "Test.doc",
115      *         ".doc")
116      * @return Extracted text if it is a supported format or an empty string if
117      *         it is an unsupported format
118      */
119     public static String extractText(InputStream is, String fileName) {
120         return getFile().extractText(is, fileName);
121     }
122 
123     public static String getAbsolutePath(File file) {
124         return getFile().getAbsolutePath(file);
125     }
126 
127     public static byte[] getBytes(File file) throws IOException {
128         return getFile().getBytes(file);
129     }
130 
131     public static byte[] getBytes(InputStream is) throws IOException {
132         return getFile().getBytes(is);
133     }
134 
135     public static byte[] getBytes(InputStream is, int bufferSize)
136         throws IOException {
137 
138         return getFile().getBytes(is);
139     }
140 
141     public static String getExtension(String fileName) {
142         return getFile().getExtension(fileName);
143     }
144 
145     public static com.liferay.portal.kernel.util.File getFile() {
146         return _file;
147     }
148 
149     public static String getPath(String fullFileName) {
150         return getFile().getPath(fullFileName);
151     }
152 
153     public static String getShortFileName(String fullFileName) {
154         return getFile().getShortFileName(fullFileName);
155     }
156 
157     public static boolean isAscii(File file) throws IOException {
158         return getFile().isAscii(file);
159     }
160 
161     public static String[] listDirs(String fileName) {
162         return getFile().listDirs(fileName);
163     }
164 
165     public static String[] listDirs(File file) {
166         return getFile().listDirs(file);
167     }
168 
169     public static String[] listFiles(String fileName) {
170         return getFile().listFiles(fileName);
171     }
172 
173     public static String[] listFiles(File file) {
174         return getFile().listFiles(file);
175     }
176 
177     public static void mkdirs(String pathName) {
178         getFile().mkdirs(pathName);
179     }
180 
181     public static boolean move(
182         String sourceFileName, String destinationFileName) {
183 
184         return getFile().move(sourceFileName, destinationFileName);
185     }
186 
187     public static boolean move(File source, File destination) {
188         return getFile().move(source, destination);
189     }
190 
191     public static String read(String fileName) throws IOException {
192         return getFile().read(fileName);
193     }
194 
195     public static String read(File file) throws IOException {
196         return getFile().read(file);
197     }
198 
199     public static String read(File file, boolean raw) throws IOException {
200         return getFile().read(file, raw);
201     }
202 
203     public static String replaceSeparator(String fileName) {
204         return getFile().replaceSeparator(fileName);
205     }
206 
207     public static File[] sortFiles(File[] files) {
208         return getFile().sortFiles(files);
209     }
210 
211     public static String stripExtension(String fileName) {
212         return getFile().stripExtension(fileName);
213     }
214 
215     public static List<String> toList(Reader reader) {
216         return getFile().toList(reader);
217     }
218 
219     public static List<String> toList(String fileName) {
220         return getFile().toList(fileName);
221     }
222 
223     public static Properties toProperties(FileInputStream fis) {
224         return getFile().toProperties(fis);
225     }
226 
227     public static Properties toProperties(String fileName) {
228         return getFile().toProperties(fileName);
229     }
230 
231     public static void write(String fileName, String s) throws IOException {
232         getFile().write(fileName, s);
233     }
234 
235     public static void write(String fileName, String s, boolean lazy)
236         throws IOException {
237 
238         getFile().write(fileName, s, lazy);
239     }
240 
241     public static void write(
242             String fileName, String s, boolean lazy, boolean append)
243         throws IOException {
244 
245         getFile().write(fileName, s, lazy, append);
246     }
247 
248     public static void write(String pathName, String fileName, String s)
249         throws IOException {
250 
251         getFile().write(pathName, fileName, s);
252     }
253 
254     public static void write(
255             String pathName, String fileName, String s, boolean lazy)
256         throws IOException {
257 
258         getFile().write(pathName, fileName, s, lazy);
259     }
260 
261     public static void write(
262             String pathName, String fileName, String s, boolean lazy,
263             boolean append)
264         throws IOException {
265 
266         getFile().write(pathName, fileName, s, lazy, append);
267     }
268 
269     public static void write(File file, String s) throws IOException {
270         getFile().write(file, s);
271     }
272 
273     public static void write(File file, String s, boolean lazy)
274         throws IOException {
275 
276         getFile().write(file, s, lazy);
277     }
278 
279     public static void write(File file, String s, boolean lazy, boolean append)
280         throws IOException {
281 
282         getFile().write(file, s, lazy, append);
283     }
284 
285     public static void write(String fileName, byte[] bytes) throws IOException {
286         getFile().write(fileName, bytes);
287     }
288 
289     public static void write(File file, byte[] bytes) throws IOException {
290         getFile().write(file, bytes);
291     }
292 
293     public static void write(File file, byte[] bytes, int offset, int length)
294         throws IOException {
295 
296         getFile().write(file, bytes, offset, length);
297     }
298 
299     public static void write(String fileName, InputStream is)
300         throws IOException {
301 
302         getFile().write(fileName, is);
303     }
304 
305     public static void write(File file, InputStream is) throws IOException {
306         getFile().write(file, is);
307     }
308 
309     public void setFile(com.liferay.portal.kernel.util.File file) {
310         _file = file;
311     }
312 
313     private static com.liferay.portal.kernel.util.File _file;
314 
315 }