Top Inners Fields Constructors Methods
com.jogamp.common.util

public Class IOUtil

extends Object
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedOutputStream, .Closeable, .File, .FileOutputStream, .FilePermission, .FileWriter, .IOException, .InputStream, .OutputStream, .PrintStream, .Reader, .SyncFailedException, java.lang.ref.WeakReference, java.lang.reflect.Constructor, java.net.URISyntaxException, .URL, .URLConnection, java.nio.ByteBuffer, java.util.regex.Pattern, jogamp.common.Debug, jogamp.common.os.AndroidUtils, .PlatformPropsImpl, com.jogamp.common.ExceptionUtils, com.jogamp.common.net.AssetURLContext, .Uri, com.jogamp.common.nio.Buffers, com.jogamp.common.os.MachineDataInfo, .Platform

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
IOUtil.ClassResources

Helper compound associating a class instance and resource paths to be resolved at a later time.

public static class

Field Summary

Modifier and TypeField and Description
public static final boolean
private static final boolean
private static final boolean
private static final boolean
private static WeakReference<byte[]>
private static final Object
private static final String
private static final Pattern
patternSingleBS

RESOURCE / FILE NAME STUFF

public static final Pattern
private static File
private static File
private static volatile boolean
public static final String
tmpSubDir

Subdirectory within platform's temporary root directory where all JogAmp related temp files are being stored: jogamp

private static final String
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static StringBuilder
public static String

Returns:

clean path string where ./ and ../ is resolved, while keeping a starting ../ at the beginning of a relative path.
cleanPathString
(String
assuming a slashified path, either denoting a file or directory, either relative or absolute.
path
)

public static void
close(final Closeable stream, final boolean throwRuntimeException)

public static IOException

Returns:

the excess IOException or null.
close
(final Closeable
the Closeable instance to close
stream
,
final IOException[]
cache for one IOException to store, if not already used (excess)
saveOneIfFree
,
final PrintStream
dump the excess IOException on this PrintStream
dumpExcess
)

Helper to simplify closing Closeables.

public static byte[]
copyStream2ByteArray(InputStream stream)

Copy the specified input stream to a byte array, which is being returned.

public static ByteBuffer
copyStream2ByteBuffer(final InputStream
input stream, which will be wrapped into a BufferedInputStream, if not already done.
stream
)

Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.

public static ByteBuffer
copyStream2ByteBuffer(InputStream
input stream, which will be wrapped into a BufferedInputStream, if not already done.
stream
,
int
initial buffer capacity in bytes, if > available bytes
initialCapacity
)

Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.

public static int
copyStream2File(final InputStream
the source
in
,
final File
the destination
outFile
,
int
informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
totalNumBytes
)

Copy the specified input stream to the specified output file.

public static int
copyStream2Stream(final InputStream
the source
in
,
final OutputStream
the destination
out
,
final int
informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
totalNumBytes
)

Copy the specified input stream to the specified output stream.

public static int
copyStream2Stream(final int
the intermediate buffer size, should be MachineDataInfo#pageSizeInBytes() for best performance.
bufferSize
,
final InputStream
the source
in
,
final OutputStream
the destination
out
,
final int
informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
totalNumBytes
)

Copy the specified input stream to the specified output stream.

public static int
copyURLConn2File(final URLConnection
the open URLConnection
conn
,
final File
the destination
outFile
)

Copy the specified URL resource to the specified output file.

public static File
createTempFile(final String prefix, final String suffix, final boolean
true if the temporary root folder needs to hold executable files, otherwise false.
executable
)

Utilizing File#createTempFile(String, String, File) using getTempDir(boolean) as the directory parameter, ie.

private static void
fillExeTestFile(final File exefile)

public static String
getBasename(String fname)

Returns the basename of the given fname w/o directory part

public static String
getClassFileName(final String clazzBinName)

public static URL

Returns:

jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/util/cache/TempJarCache.class
getClassURL
(final String
com.jogamp.common.util.cache.TempJarCache
clazzBinName
,
final ClassLoader
ClassLoader to locate the JarFile
cl
)

public static String
getDirname(String fname)

Returns unified '/' dirname including the last '/'

private static String[]
getExeTestCommandArgs(final String scriptFile)

private static String
private static String
private static File
getFile(final String fname)

public static FileOutputStream

Returns:

outputStream The resulting output stream
getFileOutputStream
(final File file, final boolean allowOverwrite)

public static String

Returns:

lowercase suffix of the file name
getFileSuffix
(final File
name of the file
file
)

Returns the lowercase suffix of the given file name (the text after the last '.' in the file name).

public static String

Returns:

lowercase suffix of the file name
getFileSuffix
(final String
name of the file
filename
)

Returns the lowercase suffix of the given file name (the text after the last '.' in the file name).

private static final Constructor<?>

Returns:

the constructor of java.io.FileOutputStream if available and no SecurityManager is installed or privileged access is granted. Otherwise null.
getFOSCtor
()

Since usage of java.io.FileOutputStream is considered security critical, we need to check it's availability for each use.

private static boolean
private static boolean
public static String

Returns:

parent of path
getParentOf
(final String
assuming a slashified path, either denotes a file or directory, either relative or absolute.
path
)

public static String
getRelativeOf(final File
denotes a directory
baseLocation
,
final String
denotes a relative file to the baseLocation
relativeFile
)

Generates a path for the 'relativeFile' relative to the 'baseLocation'.

public static URLConnection
getResource(final Class<?> context, final String resourcePath)

Locating a resource using getResource(String, ClassLoader):
  • relative: context's package name-path plus resourcePath via context's ClassLoader. This allows locations relative to JAR- and other URLs. The resourcePath may start with ../ to navigate to parent folder. This attempt is skipped if context is null.
  • absolute: resourcePath as is via context's ClassLoader. In case context is null, this class ClassLoader is being used.
public static URLConnection
getResource(final String
the resource path to locate relative or absolute
resourcePath
,
final ClassLoader
the optional ClassLoader, recommended
classLoader
,
final Class<?>
relative context, i.e. position, of the resourcePath, to perform the relative lookup, if not null.
relContext
)

Locating a resource using getResource(String, ClassLoader):

  • relative: relContext's package name-path plus resourcePath via classLoader. This allows locations relative to JAR- and other URLs. The resourcePath may start with ../ to navigate to parent folder. This attempt is skipped if relContext is null.
  • absolute: resourcePath as is via classLoader.
public static URLConnection
getResource(final String resourcePath, final ClassLoader cl)

Locating a resource using the ClassLoader's facilities.

private static File

Returns:

a temporary directory, writable by this user
getSubTempDir
(final File tmpRoot, final String tmpSubDirPrefix, final boolean executable, final String dbgMsg)

This methods finds [and creates] an available temporary sub-directory:

          File tmpBaseDir = null;
          if(null != testDir(tmpRoot, true, executable)) { // check tmpRoot first
              for(int i = 0; null == tmpBaseDir && i<=9999; i++) {
                  final String tmpDirSuffix = String.format("_%04d", i); // 4 digits for iteration
                  tmpBaseDir = testDir(new File(tmpRoot, tmpSubDirPrefix+tmpDirSuffix), true, executable);
              }
          } else {
              tmpBaseDir = null;
          }
          return tmpBaseDir;
public static File
getTempDir(final boolean
true if the user intents to launch executables from the temporary directory, otherwise false.
executable
)

Returns a platform independent writable directory for temporary files consisting of the platform's temp-root + tmpSubDir, e.g. /tmp/jogamp_0000/.

public static String
getUriFilePathOrASCII(final Uri uri)

If uri is a file scheme implementation returns Uri#toFile().

private static boolean
public static URLConnection
openURL(final URL url)

Returns the connected URLConnection, or null if not url is not available

public static URLConnection
openURL(final URL url, final String dbgmsg)

Returns the connected URLConnection, or null if not url is not available

private static final byte[]
readCode(final String fname)

public static String
slashify(final String path, final boolean startWithSlash, final boolean endWithSlash)

public static File
testDir(final File
the directory to process
dir
,
final boolean
true if the directory shall be created if not existing
create
,
final boolean
true if the user intents to launch executables from the temporary directory, otherwise false.
executable
)

Returns the directory dir, which is processed and tested as described below.

public static boolean
testDirExec(final File dir)

Returns true if the given dir

  1. exists, and
  2. is a directory, and
  3. is writeable, and
  4. files can be executed from the directory
private static File
testDirImpl(final File dir, final boolean create, final boolean executable, final String dbgMsg)

public static boolean
testFile(final File file, final boolean shallBeDir, final boolean shallBeWritable)

Test whether file exists and matches the given requirements

private static String
toLowerCase(final String arg)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait