From 69d537e4f9e6e5d206719723094ea192ab51ef43 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 19 Sep 2011 13:48:45 +0200 Subject: Enhancement/GenericStyle: - NativeLibrary: - add isValidNativeLibraryName(..) - generic style - Platform - add getOSAndArch(), getOSAndArch(..) - IOUtil - add getClassFileName(..) - add getBasename(..) - add getDirname(..) - added doc - ReflectionUtil - generic style --- src/java/com/jogamp/common/util/IOUtil.java | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/java/com/jogamp/common/util/IOUtil.java') diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index 79ee62a..beb3deb 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -84,6 +84,12 @@ public class IOUtil { /** * Copy the specified input stream to the specified output stream. The total * number of bytes written is returned. + * + * @param in the source + * @param out the destination + * @param totalNumBytes informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown + * @return + * @throws IOException */ public static int copyStream2Stream(InputStream in, OutputStream out, int totalNumBytes) throws IOException { final byte[] buf = new byte[Platform.getMachineDescription().pageSizeInBytes()]; @@ -207,6 +213,45 @@ public class IOUtil { return toLowerCase(filename.substring(lastDot + 1)); } + public static String getClassFileName(String clazzBinName) throws IOException { + // or return clazzBinName.replace('.', File.pathSeparatorChar) + ".class"; ? + return clazzBinName.replace('.', '/') + ".class"; + } + + /** + * @param clazzBinName com.jogamp.common.util.cache.TempJarCache + * @param cl + * @return jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/util/cache/TempJarCache.class + * @throws IOException + */ + public static URL getClassURL(String clazzBinName, ClassLoader cl) throws IOException { + return cl.getResource(getClassFileName(clazzBinName)); + } + + /** + * Returns the basename of the given fname w/o directory part + */ + public static String getBasename(String fname) { + fname = fname.replace('\\', '/'); // unify file seperator + int lios = fname.lastIndexOf('/'); // strip off dirname + if(lios>=0) { + fname = fname.substring(lios+1); + } + return fname; + } + + /** + * Returns unified '/' dirname including the last '/' + */ + public static String getDirname(String fname) { + fname = fname.replace('\\', '/'); // unify file seperator + int lios = fname.lastIndexOf('/'); // strip off dirname + if(lios>=0) { + fname = fname.substring(0, lios+1); + } + return fname; + } + private static String toLowerCase(String arg) { if (arg == null) { return null; -- cgit v1.2.3