diff options
author | Sven Gothel <[email protected]> | 2011-09-19 13:48:45 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-19 13:48:45 +0200 |
commit | 69d537e4f9e6e5d206719723094ea192ab51ef43 (patch) | |
tree | e9611865f1eec76d13fe4725dd3ad4f5023f49c7 /src/java/com/jogamp/common/util/IOUtil.java | |
parent | 0711792f00e462e340e0d3731dfe71b0e8ec6022 (diff) |
Enhancement/GenericStyle:
- NativeLibrary:
- add isValidNativeLibraryName(..)
- generic style
- Platform
- add getOSAndArch(), getOSAndArch(..)
- IOUtil
- add getClassFileName(..)
- add getBasename(..)
- add getDirname(..)
- added doc
- ReflectionUtil
- generic style
Diffstat (limited to 'src/java/com/jogamp/common/util/IOUtil.java')
-rw-r--r-- | src/java/com/jogamp/common/util/IOUtil.java | 45 |
1 files changed, 45 insertions, 0 deletions
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; |