aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/util/IOUtil.java
diff options
context:
space:
mode:
authorHarvey Harrison <[email protected]>2013-10-17 21:06:56 -0700
committerHarvey Harrison <[email protected]>2013-10-17 21:06:56 -0700
commit791a2749886f02ec7b8db25bf8862e8269b96da5 (patch)
treec9be31d0bbbe8033b4a6a0cfad91a22b6575ced1 /src/java/com/jogamp/common/util/IOUtil.java
parent5b77e15500b7b19d35976603dd71e8b997b2d8ea (diff)
gluegen: remove trailing whitespace
Signed-off-by: Harvey Harrison <[email protected]>
Diffstat (limited to 'src/java/com/jogamp/common/util/IOUtil.java')
-rw-r--r--src/java/com/jogamp/common/util/IOUtil.java346
1 files changed, 173 insertions, 173 deletions
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java
index 242f300..16f191b 100644
--- a/src/java/com/jogamp/common/util/IOUtil.java
+++ b/src/java/com/jogamp/common/util/IOUtil.java
@@ -56,7 +56,7 @@ import com.jogamp.common.os.Platform;
public class IOUtil {
public static final boolean DEBUG = Debug.debug("IOUtil");
-
+
/** {@value} */
public static final String SCHEME_SEPARATOR = ":";
/** {@value} */
@@ -69,28 +69,28 @@ public class IOUtil {
public static final String JAR_SCHEME = "jar";
/** A JAR subprotocol is separeted from the JAR entry w/ this separator {@value}. Even if no class is specified '!/' must follow!. */
public static final String JAR_SCHEME_SEPARATOR = "!";
-
+
/** Std. temporary directory property key <code>java.io.tmpdir</code>. */
- private static final String java_io_tmpdir_propkey = "java.io.tmpdir";
+ private static final String java_io_tmpdir_propkey = "java.io.tmpdir";
private static final String user_home_propkey = "user.home";
private static final String XDG_CACHE_HOME_envkey = "XDG_CACHE_HOME";
- /** Subdirectory within platform's temporary root directory where all JogAmp related temp files are being stored: {@code jogamp} */
+ /** Subdirectory within platform's temporary root directory where all JogAmp related temp files are being stored: {@code jogamp} */
public static final String tmpSubDir = "jogamp";
-
+
private IOUtil() {}
-
- /**
+
+ /**
* Since usage of {@link java.io.FileOutputStream} is considered security critical,
* we need to check it's availability for each use.
* <p>
* In case a SecurityManager is installed, privileged access is required.
* </p>
- *
- * @return the constructor of {@link java.io.FileOutputStream} if available and
- * no SecurityManager is installed or privileged access is granted.
+ *
+ * @return the constructor of {@link java.io.FileOutputStream} if available and
+ * no SecurityManager is installed or privileged access is granted.
* Otherwise null.
- *
+ *
*/
private static final Constructor<?> getFOSCtor() {
Constructor<?> _fosCtor;
@@ -102,7 +102,7 @@ public class IOUtil {
_fosCtor = null;
_t = t;
}
- if(DEBUG) {
+ if(DEBUG) {
System.err.println("IOUtil: java.io.FileOutputStream available: "+(null != _fosCtor));
if(null!=_t) {
_t.printStackTrace();
@@ -110,24 +110,24 @@ public class IOUtil {
}
return _fosCtor;
}
-
+
/***
- *
+ *
* STREAM COPY STUFF
- *
+ *
*/
-
+
/**
* Copy the specified URL resource to the specified output file. The total
* number of bytes written is returned. Both streams are closed upon completion.
- *
- * @param conn the open URLConnection
+ *
+ * @param conn the open URLConnection
* @param outFile the destination
* @return
* @throws IOException
*/
public static int copyURLConn2File(URLConnection conn, File outFile) throws IOException {
- conn.connect(); // redundant
+ conn.connect(); // redundant
int totalNumBytes = 0;
InputStream in = new BufferedInputStream(conn.getInputStream());
@@ -142,10 +142,10 @@ public class IOUtil {
/**
* Copy the specified input stream to the specified output file. The total
* number of bytes written is returned. Both streams are closed upon completion.
- *
- * @param in the source
+ *
+ * @param in the source
* @param outFile the destination
- * @param totalNumBytes informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
+ * @param totalNumBytes informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
* @return
* @throws IOException
*/
@@ -162,10 +162,10 @@ 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 in the source
* @param out the destination
- * @param totalNumBytes informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
+ * @param totalNumBytes informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
* @return
* @throws IOException
*/
@@ -176,11 +176,11 @@ public class IOUtil {
/**
* Copy the specified input stream to the specified output stream. The total
* number of bytes written is returned.
- *
+ *
* @param bufferSize the intermediate buffer size, should be {@link MachineDescription#pageSizeInBytes()} for best performance.
- * @param in the source
+ * @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
+ * @param totalNumBytes informal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
* @return
* @throws IOException
*/
@@ -197,7 +197,7 @@ public class IOUtil {
}
return numBytes;
}
-
+
/**
* Copy the specified input stream to a byte array, which is being returned.
*/
@@ -235,17 +235,17 @@ public class IOUtil {
/**
* Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.
* <p>The implementation creates the ByteBuffer w/ {@link #copyStream2ByteArray(InputStream)}'s returned byte array.</p>
- *
+ *
* @param stream input stream, which will be wrapped into a BufferedInputStream, if not already done.
*/
public static ByteBuffer copyStream2ByteBuffer(InputStream stream) throws IOException {
- return copyStream2ByteBuffer(stream, -1);
+ return copyStream2ByteBuffer(stream, -1);
}
-
+
/**
* Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.
* <p>The implementation creates the ByteBuffer w/ {@link #copyStream2ByteArray(InputStream)}'s returned byte array.</p>
- *
+ *
* @param stream input stream, which will be wrapped into a BufferedInputStream, if not already done.
* @param initialCapacity initial buffer capacity in bytes, if &gt; available bytes
*/
@@ -257,7 +257,7 @@ public class IOUtil {
if( initialCapacity < avail ) {
initialCapacity = avail;
}
- final MachineDescription machine = Platform.getMachineDescription();
+ final MachineDescription machine = Platform.getMachineDescription();
ByteBuffer data = Buffers.newDirectByteBuffer( machine.pageAlignedSize( initialCapacity ) );
byte[] chunk = new byte[machine.pageSizeInBytes()];
int chunk2Read = Math.min(machine.pageSizeInBytes(), avail);
@@ -269,13 +269,13 @@ public class IOUtil {
newData.put(data);
data = newData;
}
-
+
numRead = stream.read(chunk, 0, chunk2Read);
if (numRead > 0) {
data.put(chunk, 0, numRead);
}
avail = stream.available();
- chunk2Read = Math.min(machine.pageSizeInBytes(), avail);
+ chunk2Read = Math.min(machine.pageSizeInBytes(), avail);
} while ( numRead > 0 ); // EOS: -1 == numRead, EOF maybe reached earlier w/ 0 == numRead
data.flip();
@@ -283,13 +283,13 @@ public class IOUtil {
}
/***
- *
+ *
* RESOURCE / FILE NAME STUFF
- *
+ *
*/
-
+
/**
- *
+ *
* @param path
* @param startWithSlash
* @param endWithSlash
@@ -297,7 +297,7 @@ public class IOUtil {
* @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code>
*/
public static String slashify(String path, boolean startWithSlash, boolean endWithSlash) throws URISyntaxException {
- String p = path.replace('\\', '/'); // unify file separator
+ String p = path.replace('\\', '/'); // unify file separator
if (startWithSlash && !p.startsWith("/")) {
p = "/" + p;
}
@@ -306,23 +306,23 @@ public class IOUtil {
}
return cleanPathString(p);
}
-
- /**
- * Using the simple conversion via File -> URI, assuming proper characters.
+
+ /**
+ * Using the simple conversion via File -> URI, assuming proper characters.
* @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code>
- * @throws URISyntaxException if the resulting string does not comply w/ an RFC 2396 URI
+ * @throws URISyntaxException if the resulting string does not comply w/ an RFC 2396 URI
*/
public static URI toURISimple(File file) throws URISyntaxException {
- return new URI(FILE_SCHEME, null, encodeToURI(slashify(file.getAbsolutePath(), true, file.isDirectory())), null);
+ return new URI(FILE_SCHEME, null, encodeToURI(slashify(file.getAbsolutePath(), true, file.isDirectory())), null);
}
-
- /**
- * Using the simple conversion via File -> URI, assuming proper characters.
+
+ /**
+ * Using the simple conversion via File -> URI, assuming proper characters.
* @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code>
- * @throws URISyntaxException if the resulting string does not comply w/ an RFC 2396 URI
+ * @throws URISyntaxException if the resulting string does not comply w/ an RFC 2396 URI
*/
public static URI toURISimple(String protocol, String file, boolean isDirectory) throws URISyntaxException {
- return new URI(protocol, null, encodeToURI(slashify(file, true, isDirectory)), null);
+ return new URI(protocol, null, encodeToURI(slashify(file, true, isDirectory)), null);
}
/**
@@ -364,14 +364,14 @@ public class IOUtil {
return arg.toLowerCase();
}
-
+
/***
* @param file
* @param allowOverwrite
* @return outputStream The resulting output stream
- * @throws IOException if the file already exists and <code>allowOverwrite</code> is false,
+ * @throws IOException if the file already exists and <code>allowOverwrite</code> is false,
* the class {@link java.io.FileOutputStream} is not accessible or
- * the user does not have sufficient rights to access the local filesystem.
+ * the user does not have sufficient rights to access the local filesystem.
*/
public static FileOutputStream getFileOutputStream(File file, boolean allowOverwrite) throws IOException {
final Constructor<?> fosCtor = getFOSCtor();
@@ -387,14 +387,14 @@ public class IOUtil {
throw new IOException("error opening " + file + " for write. ", e);
}
}
-
+
public static String getClassFileName(String clazzBinName) {
- // or return clazzBinName.replace('.', File.separatorChar) + ".class"; ?
- return clazzBinName.replace('.', '/') + ".class";
+ // or return clazzBinName.replace('.', File.separatorChar) + ".class"; ?
+ return clazzBinName.replace('.', '/') + ".class";
}
-
+
/**
- * @param clazzBinName com.jogamp.common.util.cache.TempJarCache
+ * @param clazzBinName com.jogamp.common.util.cache.TempJarCache
* @param cl ClassLoader to locate the JarFile
* @return jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/util/cache/TempJarCache.class
* @throws IOException if the jar file could not been found by the ClassLoader
@@ -406,7 +406,7 @@ public class IOUtil {
}
return url;
}
-
+
/**
* Returns the basename of the given fname w/o directory part
* @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code>
@@ -419,7 +419,7 @@ public class IOUtil {
}
return fname;
}
-
+
/**
* Returns unified '/' dirname including the last '/'
* @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code>
@@ -432,22 +432,22 @@ public class IOUtil {
}
return fname;
}
-
+
/**
* The URI's <code><i>protocol</i>:/some/path/gluegen-rt.jar</code>
* parent dirname URI <code><i>protocol</i>:/some/path/</code> will be returned.
* <p>
* <i>protocol</i> may be "file", "http", etc..
* </p>
- *
+ *
* @param uri "<i>protocol</i>:/some/path/gluegen-rt.jar"
* @return "<i>protocol</i>:/some/path/"
* @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null
- * @throws URISyntaxException
+ * @throws URISyntaxException
*/
public static URI getURIDirname(URI uri) throws IllegalArgumentException, URISyntaxException {
if(null == uri) {
- throw new IllegalArgumentException("URI is null");
+ throw new IllegalArgumentException("URI is null");
}
String uriS = uri.toString();
if( DEBUG ) {
@@ -455,24 +455,24 @@ public class IOUtil {
}
return new URI( getURIDirname(uriS) );
}
-
+
/**
* The URI's <code><i>protocol</i>:/some/path/gluegen-rt.jar</code>
* parent dirname URI <code><i>protocol</i>:/some/path/</code> will be returned.
* <p>
* <i>protocol</i> may be "file", "http", etc..
* </p>
- *
+ *
* @param uri "<i>protocol</i>:/some/path/gluegen-rt.jar" (URI encoded)
* @return "<i>protocol</i>:/some/path/"
* @throws IllegalArgumentException if the URI doesn't match the expected formatting, or is null
- * @throws URISyntaxException
+ * @throws URISyntaxException
*/
public static String getURIDirname(String uriS) throws IllegalArgumentException, URISyntaxException {
if(null == uriS) {
- throw new IllegalArgumentException("uriS is null");
+ throw new IllegalArgumentException("uriS is null");
}
- // from
+ // from
// file:/some/path/gluegen-rt.jar _or_ rsrc:gluegen-rt.jar
// to
// file:/some/path/ _or_ rsrc:
@@ -484,15 +484,15 @@ public class IOUtil {
throw new IllegalArgumentException("URI does not contain protocol terminator ':', in <"+uriS+">");
}
}
- uriS = uriS.substring(0, idx+1); // exclude jar name, include terminal '/' or ':'
-
+ uriS = uriS.substring(0, idx+1); // exclude jar name, include terminal '/' or ':'
+
if( DEBUG ) {
System.out.println("getJarURIDirname res: "+uriS);
- }
+ }
return uriS;
}
-
- /**
+
+ /**
* Converts an {@link URI} to an {@link URL} while using a non encoded path
* for <i>file scheme</i>, i.e. <code>file:/</code>.
* Otherwise the default {@link URL} translation {@link URI#toURL()} is being used.
@@ -551,18 +551,18 @@ public class IOUtil {
}
return url;
}
-
+
/***
- *
+ *
* RESOURCE LOCATION STUFF
- *
+ *
*/
-
+
/**
* Locating a resource using {@link #getResource(String, ClassLoader)}:
* <ul>
- * <li><i>relative</i>: <code>context</code>'s package name-path plus <code>resourcePath</code> via <code>context</code>'s ClassLoader.
- * This allows locations relative to JAR- and other URLs.
+ * <li><i>relative</i>: <code>context</code>'s package name-path plus <code>resourcePath</code> via <code>context</code>'s ClassLoader.
+ * This allows locations relative to JAR- and other URLs.
* The <code>resourcePath</code> may start with <code>../</code> to navigate to parent folder.</li>
* <li><i>absolute</i>: <code>context</code>'s ClassLoader and the <code>resourcePath</code> as is (filesystem)</li>
* </ul>
@@ -570,7 +570,7 @@ public class IOUtil {
* <p>
* Returns the resolved and open URLConnection or null if not found.
* </p>
- *
+ *
* @see #getResource(String, ClassLoader)
* @see ClassLoader#getResource(String)
* @see ClassLoader#getSystemResource(String)
@@ -578,11 +578,11 @@ public class IOUtil {
public static URLConnection getResource(Class<?> context, String resourcePath) {
if(null == resourcePath) {
return null;
- }
+ }
ClassLoader contextCL = (null!=context)?context.getClassLoader():IOUtil.class.getClassLoader();
URLConnection conn = null;
if(null != context) {
- // scoping the path within the class's package
+ // scoping the path within the class's package
final String className = context.getName().replace('.', '/');
final int lastSlash = className.lastIndexOf('/');
if (lastSlash >= 0) {
@@ -647,7 +647,7 @@ public class IOUtil {
/**
* Generates a path for the 'relativeFile' relative to the 'baseLocation'.
- *
+ *
* @param baseLocation denotes a directory
* @param relativeFile denotes a relative file to the baseLocation
* @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code>
@@ -656,7 +656,7 @@ public class IOUtil {
if(null == relativeFile) {
return null;
}
-
+
if (baseLocation != null) {
final File file = new File(baseLocation, relativeFile);
// Handle things on Windows
@@ -668,14 +668,14 @@ public class IOUtil {
/**
* @param path assuming a slashified path beginning with "/" as it's root directory, either denotes a file or directory.
* @return parent of path
- * @throws URISyntaxException if path is empty or has no parent directory available
+ * @throws URISyntaxException if path is empty or has no parent directory available
*/
public static String getParentOf(String path) throws URISyntaxException {
final int pl = null!=path ? path.length() : 0;
if(pl == 0) {
throw new IllegalArgumentException("path is empty <"+path+">");
}
-
+
final int e = path.lastIndexOf("/");
if( e < 0 ) {
throw new URISyntaxException(path, "path contains no '/'");
@@ -688,7 +688,7 @@ public class IOUtil {
// path is file, return it's parent directory
return path.substring(0, e+1);
}
- final int j = path.lastIndexOf("!") + 1; // '!' Separates JARFile entry -> local start of path
+ final int j = path.lastIndexOf("!") + 1; // '!' Separates JARFile entry -> local start of path
// path is a directory ..
final int p = path.lastIndexOf("/", e-1);
if( p >= j) {
@@ -696,10 +696,10 @@ public class IOUtil {
}
throw new URISyntaxException(path, "parent of path contains no '/'");
}
-
+
/**
* @param path assuming a slashified path beginning with "/" as it's root directory, either denotes a file or directory.
- * @return clean path string where <code>../</code> and <code>./</code> is resolved.
+ * @return clean path string where <code>../</code> and <code>./</code> is resolved.
* @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code>
*/
public static String cleanPathString(String path) throws URISyntaxException {
@@ -712,47 +712,47 @@ public class IOUtil {
}
return path;
}
-
+
/**
* Generates a URI for the <i>relativePath</i> relative to the <i>baseURI</i>,
* hence the result is a absolute location.
* <p>
- * Impl. operates on the <i>scheme-specific-part</i>, and hence is sub-protocol savvy.
+ * Impl. operates on the <i>scheme-specific-part</i>, and hence is sub-protocol savvy.
* </p>
* <p>
- * In case <i>baseURI</i> is not a path ending w/ '/', it's a assumed to be a file and it's parent is being used.
+ * In case <i>baseURI</i> is not a path ending w/ '/', it's a assumed to be a file and it's parent is being used.
* </p>
- *
+ *
* @param baseURI denotes a URI to a directory ending w/ '/', or a file. In the latter case the file's directory is being used.
* @param relativePath denotes a relative file to the baseLocation's parent directory
* @throws URISyntaxException if path is empty or has no parent directory available while resolving <code>../</code>
*/
- public static URI getRelativeOf(URI baseURI, String relativePath) throws URISyntaxException {
+ public static URI getRelativeOf(URI baseURI, String relativePath) throws URISyntaxException {
return compose(baseURI.getScheme(), baseURI.getSchemeSpecificPart(), encodeToURI(relativePath), baseURI.getFragment());
}
-
+
/**
* Wraps {@link #getRelativeOf(URI, String)} for convenience.
* @throws IOException
*/
- public static URL getRelativeOf(URL baseURL, String relativePath) throws IOException {
+ public static URL getRelativeOf(URL baseURL, String relativePath) throws IOException {
try {
return getRelativeOf(baseURL.toURI(), relativePath).toURL();
} catch (URISyntaxException e) {
throw new IOException(e);
}
}
-
+
/**
* Generates a URI for the <i>relativePath</i> relative to the <i>schemeSpecificPart</i>,
* hence the result is a absolute location.
* <p>
- * <i>schemeSpecificPart</i>'s query, if exist is split to <i>path</i> and <i>query</i>.
+ * <i>schemeSpecificPart</i>'s query, if exist is split to <i>path</i> and <i>query</i>.
* </p>
* <p>
- * In case <i>path</i> is not a path ending w/ '/', it's a assumed to be a file and it's parent is being used.
+ * In case <i>path</i> is not a path ending w/ '/', it's a assumed to be a file and it's parent is being used.
* </p>
- *
+ *
* @param scheme scheme of the resulting URI
* @param schemeSpecificPart may include a query, which is separated while processing (URI encoded)
* @param relativePath denotes a relative file to the baseLocation's parent directory (URI encoded)
@@ -778,12 +778,12 @@ public class IOUtil {
}
schemeSpecificPart = cleanPathString( schemeSpecificPart );
return new URI(scheme, null == query ? schemeSpecificPart : schemeSpecificPart + "?" + query, fragment);
- }
-
+ }
+
private static final Pattern patternSpaceRaw = Pattern.compile(" ");
private static final Pattern patternSpaceEnc = Pattern.compile("%20");
-
- /**
+
+ /**
* Escapes characters not complying w/ RFC 2396 and the {@link URI#URI(String)} ctor.
* <ul>
* <li>SPACE -> %20</li>
@@ -792,21 +792,21 @@ public class IOUtil {
public static String encodeToURI(String s) {
return patternSpaceRaw.matcher(s).replaceAll("%20");
}
-
- /**
+
+ /**
* Reverses escaping of characters as performed via {@link #encodeToURI(String)}.
*/
public static String decodeFromURI(String s) {
return patternSpaceEnc.matcher(s).replaceAll(" ");
}
-
+
/**
* Returns the connected URLConnection, or null if not url is not available
*/
public static URLConnection openURL(URL url) {
return openURL(url, ".");
}
-
+
/**
* Returns the connected URLConnection, or null if not url is not available
*/
@@ -819,19 +819,19 @@ public class IOUtil {
System.err.println("IOUtil: urlExists("+url+") ["+dbgmsg+"] - true");
}
return c;
- } catch (IOException ioe) {
+ } catch (IOException ioe) {
if(DEBUG) {
System.err.println("IOUtil: urlExists("+url+") ["+dbgmsg+"] - false - "+ioe.getClass().getSimpleName()+": "+ioe.getMessage());
ioe.printStackTrace();
- }
+ }
}
} else if(DEBUG) {
System.err.println("IOUtil: no url - urlExists(null) ["+dbgmsg+"]");
- }
-
+ }
+
return null;
}
-
+
private static String getShellSuffix() {
switch(PlatformPropsImpl.OS_TYPE) {
case WINDOWS:
@@ -840,18 +840,18 @@ public class IOUtil {
return ".sh";
}
}
-
+
private static boolean getOSHasNoexecFS() {
switch(PlatformPropsImpl.OS_TYPE) {
case WINDOWS:
case OPENKODE:
return false;
-
+
default:
return true;
}
}
-
+
/**
* @see <a href="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">Free-Desktop - XDG Base Directory Specification</a>
*/
@@ -862,26 +862,26 @@ public class IOUtil {
case WINDOWS:
case OPENKODE:
return false;
-
+
default:
return true;
}
}
-
+
/**
* Test whether {@code file} exists and matches the given requirements
- *
+ *
* @param file
* @param shallBeDir
* @param shallBeWritable
* @return
*/
- public static boolean testFile(File file, boolean shallBeDir, boolean shallBeWritable) {
+ public static boolean testFile(File file, boolean shallBeDir, boolean shallBeWritable) {
if (!file.exists()) {
if(DEBUG) {
System.err.println("IOUtil.testFile: <"+file.getAbsolutePath()+">: does not exist");
}
- return false;
+ return false;
}
if (shallBeDir && !file.isDirectory()) {
if(DEBUG) {
@@ -893,7 +893,7 @@ public class IOUtil {
if(DEBUG) {
System.err.println("IOUtil.testFile: <"+file.getAbsolutePath()+">: is not writable");
}
- return false;
+ return false;
}
return true;
}
@@ -904,9 +904,9 @@ public class IOUtil {
* <li>exists, and</li>
* <li>is a directory, and</li>
* <li>is writeable, and</li>
- * <li>files can be executed from the directory</li>
+ * <li>files can be executed from the directory</li>
* </ol>
- *
+ *
* @throws SecurityException if file creation and process execution is not allowed within the current security context
* @param dir
*/
@@ -914,12 +914,12 @@ public class IOUtil {
throws SecurityException
{
if (!testFile(dir, true, true)) {
- return false;
+ return false;
}
if(!getOSHasNoexecFS()) {
return true;
}
-
+
File exetst;
try {
exetst = File.createTempFile("jogamp_exe_tst", getShellSuffix(), dir);
@@ -951,31 +951,31 @@ public class IOUtil {
return 0 == ok;
}
- private static File testDirImpl(File dir, boolean create, boolean executable)
+ private static File testDirImpl(File dir, boolean create, boolean executable)
throws SecurityException
{
if (create && !dir.exists()) {
- dir.mkdirs();
+ dir.mkdirs();
}
if( executable ) {
if(testDirExec(dir)) {
return dir;
}
} else if(testFile(dir, true, true)) {
- return dir;
+ return dir;
}
return null;
}
-
+
/**
* Returns the directory {@code dir}, which is processed and tested as described below.
* <ol>
* <li>If {@code create} is {@code true} and the directory does not exist yet, it is created incl. all sub-directories.</li>
* <li>If {@code dirName} exists, but is not a directory, {@code null} is being returned.</li>
* <li>If the directory does not exist or is not writeable, {@code null} is being returned.</li>
- * <li>If {@code executable} is {@code true} and files cannot be executed from the directory, {@code null} is being returned.</li>
+ * <li>If {@code executable} is {@code true} and files cannot be executed from the directory, {@code null} is being returned.</li>
* </ol>
- *
+ *
* @param dir the directory to process
* @param create true if the directory shall be created if not existing
* @param executable true if the user intents to launch executables from the temporary directory, otherwise false.
@@ -985,14 +985,14 @@ public class IOUtil {
throws SecurityException
{
return testDirImpl(dir, create, executable);
- }
-
- private static boolean isStringSet(String s) { return null != s && 0 < s.length(); }
-
+ }
+
+ private static boolean isStringSet(String s) { return null != s && 0 < s.length(); }
+
/**
* This methods finds [and creates] an available temporary sub-directory:
* <pre>
- File tmpBaseDir = null;
+ 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
@@ -1015,7 +1015,7 @@ public class IOUtil {
private static File getSubTempDir(File tmpRoot, String tmpSubDirPrefix, boolean executable)
throws SecurityException
{
- File tmpBaseDir = null;
+ File tmpBaseDir = null;
if(null != testDirImpl(tmpRoot, true /* create */, executable)) { // check tmpRoot first
for(int i = 0; null == tmpBaseDir && i<=9999; i++) {
final String tmpDirSuffix = String.format("_%04d", i); // 4 digits for iteration
@@ -1024,16 +1024,16 @@ public class IOUtil {
}
return tmpBaseDir;
}
-
+
/**
* Returns a platform independent writable directory for temporary files
- * consisting of the platform's {@code temp-root} + {@link #tmpSubDir},
- * e.g. {@code /tmp/jogamp_0000/}.
+ * consisting of the platform's {@code temp-root} + {@link #tmpSubDir},
+ * e.g. {@code /tmp/jogamp_0000/}.
* <p>
* On standard Java the {@code temp-root} folder is specified by <code>java.io.tempdir</code>.
- * </p>
+ * </p>
* <p>
- * On Android the {@code temp-root} folder is relative to the applications local folder
+ * On Android the {@code temp-root} folder is relative to the applications local folder
* (see {@link Context#getDir(String, int)}) is returned, if
* the Android application/activity has registered it's Application Context
* via {@link jogamp.common.os.android.StaticContext.StaticContext#init(Context, ClassLoader) StaticContext.init(..)}.
@@ -1042,12 +1042,12 @@ public class IOUtil {
* </p>
* <p>
* In case {@code temp-root} is the users home folder,
- * a dot is being prepended to {@link #tmpSubDir}, i.e.: {@code /home/user/.jogamp_0000/}.
+ * a dot is being prepended to {@link #tmpSubDir}, i.e.: {@code /home/user/.jogamp_0000/}.
* </p>
* @param executable true if the user intents to launch executables from the temporary directory, otherwise false.
* @throws RuntimeException if no temporary directory could be determined
* @throws SecurityException if access to <code>java.io.tmpdir</code> is not allowed within the current security context
- *
+ *
* @see PropertyAccess#getProperty(String, boolean)
* @see Context#getDir(String, int)
*/
@@ -1066,40 +1066,40 @@ public class IOUtil {
return tempRootExec;
}
}
-
+
final String java_io_tmpdir = PropertyAccess.getProperty(java_io_tmpdir_propkey, false);
final String user_home = PropertyAccess.getProperty(user_home_propkey, false);
-
+
final String xdg_cache_home;
{
String _xdg_cache_home;
- if( getOSHasFreeDesktopXDG() ) {
+ if( getOSHasFreeDesktopXDG() ) {
_xdg_cache_home = System.getenv(XDG_CACHE_HOME_envkey);
if( !isStringSet(_xdg_cache_home) && isStringSet(user_home) ) {
_xdg_cache_home = user_home + File.separator + ".cache" ; // default
- }
+ }
} else {
_xdg_cache_home = null;
}
xdg_cache_home = _xdg_cache_home;
}
-
+
// 1) java.io.tmpdir/jogamp
if( null == tempRootExec && isStringSet(java_io_tmpdir) ) {
tempRootExec = getSubTempDir(new File(java_io_tmpdir), tmpSubDir, true /* executable */);
}
-
+
// 2) $XDG_CACHE_HOME/jogamp
if(null == tempRootExec && isStringSet(xdg_cache_home)) {
- tempRootExec = getSubTempDir(new File(xdg_cache_home), tmpSubDir, true /* executable */);
+ tempRootExec = getSubTempDir(new File(xdg_cache_home), tmpSubDir, true /* executable */);
}
-
+
// 3) $HOME/.jogamp
- if(null == tempRootExec && isStringSet(user_home)) {
+ if(null == tempRootExec && isStringSet(user_home)) {
tempRootExec = getSubTempDir(new File(user_home), "." + tmpSubDir, true /* executable */);
- }
-
-
+ }
+
+
if(null != tempRootExec) {
tempRootNoexec = tempRootExec;
} else {
@@ -1107,18 +1107,18 @@ public class IOUtil {
if( null == tempRootNoexec && isStringSet(java_io_tmpdir) ) {
tempRootNoexec = getSubTempDir(new File(java_io_tmpdir), tmpSubDir, false /* executable */);
}
-
+
// 2) $XDG_CACHE_HOME/jogamp
if(null == tempRootNoexec && isStringSet(xdg_cache_home)) {
- tempRootNoexec = getSubTempDir(new File(xdg_cache_home), tmpSubDir, false /* executable */);
+ tempRootNoexec = getSubTempDir(new File(xdg_cache_home), tmpSubDir, false /* executable */);
}
-
+
// 3) $HOME/.jogamp
- if(null == tempRootNoexec && isStringSet(user_home)) {
+ if(null == tempRootNoexec && isStringSet(user_home)) {
tempRootNoexec = getSubTempDir(new File(user_home), "." + tmpSubDir, false /* executable */);
- }
+ }
}
-
+
if(DEBUG) {
System.err.println("IOUtil.getTempRoot(): temp dirs: exec: "+tempRootExec.getAbsolutePath()+", noexec: "+tempRootNoexec.getAbsolutePath());
}
@@ -1136,16 +1136,16 @@ public class IOUtil {
private static File tempRootExec = null; // writeable and executable
private static File tempRootNoexec = null; // writeable, maybe executable
private static volatile boolean tempRootSet = false;
-
+
/**
* Utilizing {@link File#createTempFile(String, String, File)} using
- * {@link #getTempDir(boolean)} as the directory parameter, ie. location
+ * {@link #getTempDir(boolean)} as the directory parameter, ie. location
* of the root temp folder.
- *
+ *
* @see File#createTempFile(String, String)
* @see File#createTempFile(String, String, File)
* @see #getTempDir(boolean)
- *
+ *
* @param prefix
* @param suffix
* @param executable true if the temporary root folder needs to hold executable files, otherwise false.
@@ -1154,9 +1154,9 @@ public class IOUtil {
* @throws IOException
* @throws SecurityException
*/
- public static File createTempFile(String prefix, String suffix, boolean executable)
- throws IllegalArgumentException, IOException, SecurityException
- {
+ public static File createTempFile(String prefix, String suffix, boolean executable)
+ throws IllegalArgumentException, IOException, SecurityException
+ {
return File.createTempFile( prefix, suffix, getTempDir(executable) );
}
@@ -1172,6 +1172,6 @@ public class IOUtil {
e.printStackTrace();
}
}
- }
+ }
}
}