Subversion Repositories bacoAlunos

Rev

Rev 1830 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1830 Rev 1845
Line 1... Line 1...
1
package jomm.utils;
1
package jomm.utils;
2
 
2
 
-
 
3
import org.apache.log4j.Logger;
-
 
4
 
3
import java.io.*;
5
import java.io.*;
-
 
6
import java.net.URISyntaxException;
-
 
7
import java.net.URL;
-
 
8
import java.net.URLDecoder;
4
import java.security.DigestInputStream;
9
import java.security.DigestInputStream;
5
import java.security.MessageDigest;
10
import java.security.MessageDigest;
6
import java.util.zip.ZipEntry;
11
import java.util.zip.ZipEntry;
7
import java.util.zip.ZipInputStream;
12
import java.util.zip.ZipInputStream;
8
import java.util.zip.ZipOutputStream;
13
import java.util.zip.ZipOutputStream;
Line 12... Line 17...
12
 * @date 20/Jun/2008
17
 * @date 20/Jun/2008
13
 * @see jomm.utils
18
 * @see jomm.utils
14
 */
19
 */
15
public class FilesUtils
20
public class FilesUtils
16
{
21
{
-
 
22
    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(FilesUtils.class);
-
 
23
 
17
    public static 1.5.0/docs/api/java/lang/String.html">String getExtension(1.5.0/docs/api/java/lang/String.html">String filename)
24
    public static 1.5.0/docs/api/java/lang/String.html">String getExtension(1.5.0/docs/api/java/lang/String.html">String filename)
18
    {
25
    {
-
 
26
 
19
        1.5.0/docs/api/java/lang/String.html">String extension = "";
27
        1.5.0/docs/api/java/lang/String.html">String extension = "";
20
        if(filename == null)
28
        if(filename == null)
21
            return extension;
29
            return extension;
22
        if(filename.indexOf(".")>=0)
30
        if(filename.indexOf(".")>=0)
23
            extension = filename.substring(filename.lastIndexOf(".") + 1);
31
            extension = filename.substring(filename.lastIndexOf(".") + 1);
Line 228... Line 236...
228
            e.printStackTrace();
236
            e.printStackTrace();
229
        }
237
        }
230
        return false;
238
        return false;
231
    }
239
    }
232
 
240
 
-
 
241
    /**
-
 
242
     * Relative path without /
-
 
243
     * @param path
-
 
244
     * @return
-
 
245
     */
-
 
246
    public static 1.5.0/docs/api/java/io/File.html">File getFileFromRelativeContextClassLoaderPath(1.5.0/docs/api/java/lang/String.html">String path)
-
 
247
    {
-
 
248
        1.5.0/docs/api/java/io/File.html">File f;
-
 
249
        1.5.0/docs/api/java/lang/ClassLoader.html">ClassLoader classLoader = 1.5.0/docs/api/java/lang/Thread.html">Thread.currentThread().getContextClassLoader();
-
 
250
 
-
 
251
        1.5.0/docs/api/java/net/URL.html">URL fileUrl = classLoader.getResource(path);
-
 
252
 
-
 
253
 
-
 
254
        try {
-
 
255
            try {
-
 
256
                f = new 1.5.0/docs/api/java/io/File.html">File(fileUrl.toURI());
-
 
257
                1.5.0/docs/api/java/lang/System.html">System.out.println(f.toString());
-
 
258
                1.5.0/docs/api/java/lang/System.html">System.out.println(f.getAbsolutePath());
-
 
259
                return f;
-
 
260
            } catch (1.5.0/docs/api/java/net/URISyntaxException.html">URISyntaxException ex) {
-
 
261
                logger.error(ex,ex);
-
 
262
                return null;
-
 
263
            } catch (1.5.0/docs/api/java/lang/IllegalArgumentException.html">IllegalArgumentException ex) {
-
 
264
 
-
 
265
 
-
 
266
                try {
-
 
267
                    1.5.0/docs/api/java/lang/System.html">System.out.println("Decoding from fileUrl.getFile");
-
 
268
                    f = new 1.5.0/docs/api/java/io/File.html">File(1.5.0/docs/api/java/net/URLDecoder.html">URLDecoder.decode(fileUrl.getFile(), "UTF-8"));
-
 
269
                    1.5.0/docs/api/java/lang/System.html">System.out.println(f.getAbsolutePath());
-
 
270
                    return f;
-
 
271
                } catch (1.5.0/docs/api/java/lang/Exception.html">Exception ex2) {
-
 
272
                    logger.error(ex2,ex2);
-
 
273
                }
-
 
274
            }
-
 
275
        }catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) {
-
 
276
            throw new 1.5.0/docs/api/java/lang/IllegalArgumentException.html">IllegalArgumentException("The properties file "
-
 
277
                    + fileUrl.toExternalForm() + " could not be loaded.", e);
-
 
278
        }
-
 
279
        return null;
-
 
280
    }
-
 
281
 
233
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/lang/Exception.html">Exception {
282
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/lang/Exception.html">Exception {
234
        1.5.0/docs/api/java/lang/System.html">System.out.println(getMD5Checksum(new 1.5.0/docs/api/java/io/File.html">File("/Volumes/Home/jorgemachado/Documents/FileZilla_3.24.0_macosx-x86.app.tar.bz2")));
283
        1.5.0/docs/api/java/lang/System.html">System.out.println(getMD5Checksum(new 1.5.0/docs/api/java/io/File.html">File("/Volumes/Home/jorgemachado/Documents/FileZilla_3.24.0_macosx-x86.app.tar.bz2")));
235
 
284
 
236
        1.5.0/docs/api/java/lang/System.html">System.out.println(getMD5Checksum(new 1.5.0/docs/api/java/io/File.html">File("/Volumes/Home/jorgemachado/Documents/FileZilla_3.24.0_macosx-x86.app.tar.bz2")));
285
        1.5.0/docs/api/java/lang/System.html">System.out.println(getMD5Checksum(new 1.5.0/docs/api/java/io/File.html">File("/Volumes/Home/jorgemachado/Documents/FileZilla_3.24.0_macosx-x86.app.tar.bz2")));
237
        1.5.0/docs/api/java/lang/System.html">System.out.println(getMD5Checksum(new 1.5.0/docs/api/java/io/File.html">File("/Volumes/Home/jorgemachado/Documents/FileZilla_3.24.0_macosx-x86.app.tar.bz2")));
286
        1.5.0/docs/api/java/lang/System.html">System.out.println(getMD5Checksum(new 1.5.0/docs/api/java/io/File.html">File("/Volumes/Home/jorgemachado/Documents/FileZilla_3.24.0_macosx-x86.app.tar.bz2")));