com.jogamp.common.util
Class IOUtil

java.lang.Object
  extended by com.jogamp.common.util.IOUtil

public class IOUtil
extends Object


Method Summary
static byte[] copyStream2ByteArray(InputStream stream)
          Copy the specified input stream to a byte array, which is being returned.
static ByteBuffer copyStream2ByteBuffer(InputStream stream)
          Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.
static int copyStream2Stream(InputStream in, OutputStream out, int totalNumBytes)
          Copy the specified input stream to the specified output stream.
static int copyURL2File(URL url, File outFile)
          Copy the specified input stream to the specified output file.
static File createTempFile(String prefix, String suffix)
          Utilizing File.createTempFile(String, String, File) using getTempRoot() as the directory parameter, ie.
static String getBasename(String fname)
          Returns the basename of the given fname w/o directory part
static String getClassFileName(String clazzBinName)
           
static URL getClassURL(String clazzBinName, ClassLoader cl)
           
static String getDirname(String fname)
          Returns unified '/' dirname including the last '/'
static String getFileSuffix(File file)
          Returns the lowercase suffix of the given file name (the text after the last '.' in the file name).
static String getFileSuffix(String filename)
          Returns the lowercase suffix of the given file name (the text after the last '.' in the file name).
static String getRelativeOf(File baseLocation, String relativeFile)
          Generates a path for the 'relativeFile' relative to the 'baseLocation'.
static String getRelativeOf(URL baseLocation, String relativeFile)
          Generates a path for the 'relativeFile' relative to the 'baseLocation'.
static URL getResource(Class<?> context, String resourcePath)
          Locating a resource using 'getResource(String path, ClassLoader cl)', with the context's package name-path plus the resourcePath (incl.
static URL getResource(String resourcePath, ClassLoader cl)
          Locating a resource using the ClassLoader's facility if not null, the absolute URL and absolute file.
static File getTempRoot()
          On standard Java, the folder specified by java.io.tempdir is returned.
static boolean urlExists(URL url)
          Returns true, if the URL exists and a connection could be opened.
static boolean urlExists(URL url, String dbgmsg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyURL2File

public static int copyURL2File(URL url,
                               File outFile)
                        throws IOException
Copy the specified input stream to the specified output file. The total number of bytes written is returned. Both streams are closed upon completion.

Throws:
IOException

copyStream2Stream

public static int copyStream2Stream(InputStream in,
                                    OutputStream out,
                                    int totalNumBytes)
                             throws IOException
Copy the specified input stream to the specified output stream. The total number of bytes written is returned.

Parameters:
in - the source
out - the destination
totalNumBytes - informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
Returns:
Throws:
IOException

copyStream2ByteArray

public static byte[] copyStream2ByteArray(InputStream stream)
                                   throws IOException
Copy the specified input stream to a byte array, which is being returned.

Throws:
IOException

copyStream2ByteBuffer

public static ByteBuffer copyStream2ByteBuffer(InputStream stream)
                                        throws IOException
Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.

The implementation creates the ByteBuffer w/ copyStream2ByteArray(InputStream)'s returned byte array.

Throws:
IOException

getFileSuffix

public static String getFileSuffix(File file)
Returns the lowercase suffix of the given file name (the text after the last '.' in the file name). Returns null if the file name has no suffix. Only operates on the given file name; performs no I/O operations.

Parameters:
file - name of the file
Returns:
lowercase suffix of the file name
Throws:
NullPointerException - if file is null

getFileSuffix

public static String getFileSuffix(String filename)
Returns the lowercase suffix of the given file name (the text after the last '.' in the file name). Returns null if the file name has no suffix. Only operates on the given file name; performs no I/O operations.

Parameters:
filename - name of the file
Returns:
lowercase suffix of the file name
Throws:
NullPointerException - if filename is null

getClassFileName

public static String getClassFileName(String clazzBinName)
                               throws IOException
Throws:
IOException

getClassURL

public static URL getClassURL(String clazzBinName,
                              ClassLoader cl)
                       throws IOException
Parameters:
clazzBinName - com.jogamp.common.util.cache.TempJarCache
cl -
Returns:
jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/util/cache/TempJarCache.class
Throws:
IOException

getBasename

public static String getBasename(String fname)
Returns the basename of the given fname w/o directory part


getDirname

public static String getDirname(String fname)
Returns unified '/' dirname including the last '/'


getResource

public static URL getResource(Class<?> context,
                              String resourcePath)
Locating a resource using 'getResource(String path, ClassLoader cl)', with the

See Also:
getResource(String, ClassLoader)

getResource

public static URL getResource(String resourcePath,
                              ClassLoader cl)
Locating a resource using the ClassLoader's facility if not null, the absolute URL and absolute file.

See Also:
ClassLoader.getResource(String), ClassLoader.getSystemResource(String), URL.URL(String), File.File(String)

getRelativeOf

public static String getRelativeOf(File baseLocation,
                                   String relativeFile)
Generates a path for the 'relativeFile' relative to the 'baseLocation'.

Parameters:
baseLocation - denotes a directory
relativeFile - denotes a relative file to the baseLocation

getRelativeOf

public static String getRelativeOf(URL baseLocation,
                                   String relativeFile)
Generates a path for the 'relativeFile' relative to the 'baseLocation'.

Parameters:
baseLocation - denotes a URL to a file
relativeFile - denotes a relative file to the baseLocation's parent directory

urlExists

public static boolean urlExists(URL url)
Returns true, if the URL exists and a connection could be opened.


urlExists

public static boolean urlExists(URL url,
                                String dbgmsg)

createTempFile

public static File createTempFile(String prefix,
                                  String suffix)
                           throws IllegalArgumentException,
                                  IOException,
                                  SecurityException
Utilizing File.createTempFile(String, String, File) using getTempRoot() as the directory parameter, ie. location of the root temp folder.

Parameters:
prefix -
suffix -
Returns:
Throws:
IllegalArgumentException
IOException
SecurityException
See Also:
File.createTempFile(String, String), File.createTempFile(String, String, File), getTempRoot()

getTempRoot

public static File getTempRoot()
                        throws SecurityException
On standard Java, the folder specified by java.io.tempdir is returned.

On Android a temp folder relative to the applications local folder (see Context#getDir(String, int)) is returned, if the Android application/activity has registered it's Application Context via StaticContext#setContext(Context). This allows using the temp folder w/o the need for sdcard access, which would be the java.io.tempdir location on Android!

The purpose of this wrapper is to allow unique code to be used for both platforms w/o the need to handle extra permissions.

Throws:
SecurityException
See Also:
StaticContext#setContext(Context), Context#getDir(String, int)