1,6 → 1,11 |
package jomm.utils; |
|
import org.apache.log4j.Logger; |
|
import java.io.*; |
import java.net.URISyntaxException; |
import java.net.URL; |
import java.net.URLDecoder; |
import java.security.DigestInputStream; |
import java.security.MessageDigest; |
import java.util.zip.ZipEntry; |
14,8 → 19,11 |
*/ |
public class FilesUtils |
{ |
private static final Logger logger = Logger.getLogger(FilesUtils.class); |
|
public static String getExtension(String filename) |
{ |
|
String extension = ""; |
if(filename == null) |
return extension; |
230,6 → 238,47 |
return false; |
} |
|
/** |
* Relative path without / |
* @param path |
* @return |
*/ |
public static File getFileFromRelativeContextClassLoaderPath(String path) |
{ |
File f; |
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); |
|
URL fileUrl = classLoader.getResource(path); |
|
|
try { |
try { |
f = new File(fileUrl.toURI()); |
System.out.println(f.toString()); |
System.out.println(f.getAbsolutePath()); |
return f; |
} catch (URISyntaxException ex) { |
logger.error(ex,ex); |
return null; |
} catch (IllegalArgumentException ex) { |
|
|
try { |
System.out.println("Decoding from fileUrl.getFile"); |
f = new File(URLDecoder.decode(fileUrl.getFile(), "UTF-8")); |
System.out.println(f.getAbsolutePath()); |
return f; |
} catch (Exception ex2) { |
logger.error(ex2,ex2); |
} |
} |
}catch (Throwable e) { |
throw new IllegalArgumentException("The properties file " |
+ fileUrl.toExternalForm() + " could not be loaded.", e); |
} |
return null; |
} |
|
public static void main(String[] args) throws Exception { |
System.out.println(getMD5Checksum(new File("/Volumes/Home/jorgemachado/Documents/FileZilla_3.24.0_macosx-x86.app.tar.bz2"))); |
|