28import java.io.BufferedInputStream;
29import java.io.BufferedOutputStream;
30import java.io.Closeable;
32import java.io.FileOutputStream;
33import java.io.FilePermission;
34import java.io.FileWriter;
35import java.io.IOException;
36import java.io.InputStream;
37import java.io.OutputStream;
38import java.io.PrintStream;
40import java.net.URISyntaxException;
42import java.net.URLConnection;
43import java.nio.ByteBuffer;
44import java.security.PrivilegedAction;
45import java.util.ArrayList;
47import java.util.Locale;
48import java.util.regex.Pattern;
50import org.jau.lang.ExceptionUtils;
51import org.jau.lang.InterruptSource;
52import org.jau.lang.ReflectionUtil;
53import org.jau.sec.SecurityUtil;
54import org.jau.sys.AndroidUtil;
55import org.jau.sys.Debug;
56import org.jau.sys.MachineDataInfo;
57import org.jau.sys.PlatformProps;
58import org.jau.sys.PlatformTypes;
59import org.jau.sys.PropertyAccess;
62 public static final boolean DEBUG;
63 private static final boolean DEBUG_EXE;
64 private static final boolean DEBUG_EXE_NOSTREAM;
65 private static final boolean DEBUG_EXE_EXISTING_FILE;
66 private static final boolean testTempDirExec;
67 private static final boolean useNativeExeFile;
69 private static final String auc_name =
"org.jau.net.AssetURLContext";
70 private static final ReflectionUtil.MethodAccessor aucGetRes;
73 final boolean _props[] = {
false,
false,
false,
false,
false,
false };
86 }
catch (
final Throwable t) {
97 DEBUG_EXE = _props[i++];
98 DEBUG_EXE_NOSTREAM = _props[i++];
99 DEBUG_EXE_EXISTING_FILE = _props[i++];
100 testTempDirExec = _props[i++];
101 useNativeExeFile = _props[i++];
107 }
catch (
final Throwable t) {}
111 System.err.println(
"IOUtil: Available <"+auc_name+
">, getResource avail "+(
null != aucGetRes ? aucGetRes.available() :
false));
116 System.err.println(
"IOUtil: Not available <"+auc_name+
">");
123 private static final String java_io_tmpdir_propkey =
"java.io.tmpdir";
124 private static final String user_home_propkey =
"user.home";
125 private static final String XDG_CACHE_HOME_envkey =
"XDG_CACHE_HOME";
147 public static int copyURLConn2File(
final URLConnection conn,
final File outFile)
throws IOException {
150 int totalNumBytes = 0;
151 final InputStream in =
new BufferedInputStream(conn.getInputStream());
157 return totalNumBytes;
170 public static int copyStream2File(
final InputStream in,
final File outFile,
int totalNumBytes)
throws IOException {
171 final OutputStream out =
new BufferedOutputStream(
new FileOutputStream(outFile));
177 return totalNumBytes;
190 public static int copyStream2Stream(
final InputStream in,
final OutputStream out,
final int totalNumBytes)
throws IOException {
205 public static int copyStream2Stream(
final int bufferSize,
final InputStream in,
final OutputStream out,
final int totalNumBytes)
throws IOException {
206 final byte[] buf =
new byte[bufferSize];
210 if ((count = in.read(buf)) == -1) {
213 out.write(buf, 0, count);
219 public static StringBuilder
appendCharStream(
final StringBuilder sb,
final Reader r)
throws IOException {
220 final char[] cbuf =
new char[1024];
222 while( 0 < ( count = r.read(cbuf) ) ) {
223 sb.append(cbuf, 0, count);
232 if( !(stream instanceof BufferedInputStream) ) {
233 stream =
new BufferedInputStream(stream);
236 int avail = stream.available();
237 byte[] data =
new byte[avail];
240 if (totalRead + avail > data.length) {
241 final byte[] newData =
new byte[totalRead + avail];
242 System.arraycopy(data, 0, newData, 0, totalRead);
245 numRead = stream.read(data, totalRead, avail);
247 totalRead += numRead;
249 avail = stream.available();
250 }
while (avail > 0 && numRead >= 0);
253 if (totalRead != data.length) {
254 final byte[] newData =
new byte[totalRead];
255 System.arraycopy(data, 0, newData, 0, totalRead);
279 if( !(stream instanceof BufferedInputStream) ) {
280 stream =
new BufferedInputStream(stream);
282 int avail = stream.available();
283 if( initialCapacity < avail ) {
284 initialCapacity = avail;
288 final byte[] chunk =
new byte[machine.pageSizeInBytes()];
289 int chunk2Read = Math.min(machine.pageSizeInBytes(), avail);
292 if (avail > data.remaining()) {
299 numRead = stream.read(chunk, 0, chunk2Read);
301 data.put(chunk, 0, numRead);
303 avail = stream.available();
304 chunk2Read = Math.min(machine.pageSizeInBytes(), avail);
305 }
while ( numRead > 0 );
317 private static final Pattern patternSingleBS = Pattern.compile(
"\\\\{1}");
327 public static String
slashify(
final String path,
final boolean startWithSlash,
final boolean endWithSlash)
throws URISyntaxException {
328 String p = patternSingleBS.matcher(path).replaceAll(
"/");
329 if (startWithSlash && !p.startsWith(
"/")) {
332 if (endWithSlash && !p.endsWith(
"/")) {
364 final int lastDot = filename.lastIndexOf(
'.');
368 return toLowerCase(filename.substring(lastDot + 1));
370 private static String toLowerCase(
final String arg) {
375 return arg.toLowerCase();
386 public static FileOutputStream
getFileOutputStream(
final File file,
final boolean allowOverwrite)
throws IOException {
387 if (file.exists() && !allowOverwrite) {
388 throw new IOException(
"File already exists (" + file +
") and overwrite=false");
391 return new FileOutputStream( file );
392 }
catch (
final Exception e) {
393 throw new IOException(
"error opening " + file +
" for write. ", e);
399 return clazzBinName.replace(
'.',
'/') +
".class";
408 public static URL
getClassURL(
final String clazzBinName,
final ClassLoader cl)
throws IOException {
411 throw new IOException(
"Cannot not find: "+clazzBinName);
420 public static String
getBasename(String fname)
throws URISyntaxException {
421 fname =
slashify(fname,
false ,
false );
422 final int lios = fname.lastIndexOf(
'/');
424 fname = fname.substring(lios+1);
433 public static String
getDirname(String fname)
throws URISyntaxException {
434 fname =
slashify(fname,
false ,
false );
435 final int lios = fname.lastIndexOf(
'/');
437 fname = fname.substring(0, lios+1);
473 throw new IllegalArgumentException(
"resourcePath["+i+
"] is null");
477 this.contextCL = relContext;
486 public URLConnection
resolve(
final int uriIndex)
throws ArrayIndexOutOfBoundsException {
512 public static URLConnection
getResource(
final String resourcePath,
final ClassLoader classLoader,
final Class<?> relContext) {
513 if(
null == resourcePath) {
516 URLConnection conn =
null;
517 if(
null != relContext) {
519 final String className = relContext.getName().replace(
'.',
'/');
520 final int lastSlash = className.lastIndexOf(
'/');
521 if (lastSlash >= 0) {
522 final String pkgName = className.substring(0, lastSlash + 1);
523 conn =
getResource(pkgName + resourcePath, classLoader);
525 System.err.println(
"IOUtil: found <"+resourcePath+
"> within class package <"+pkgName+
"> of given class <"+relContext.getName()+
">: "+(
null!=conn));
529 System.err.println(
"IOUtil: null context, skip rel. lookup");
534 System.err.println(
"IOUtil: found <"+resourcePath+
"> by classloader: "+(
null!=conn));
554 public static URLConnection
getResource(
final String resourcePath,
final ClassLoader cl) {
555 if(
null != aucGetRes && aucGetRes.available() ) {
556 return aucGetRes.callStaticMethod(resourcePath, cl);
569 public static String
getRelativeOf(
final File baseLocation,
final String relativeFile)
throws URISyntaxException {
570 if(
null == relativeFile) {
574 if (baseLocation !=
null) {
575 final File file =
new File(baseLocation, relativeFile);
577 return slashify(file.getPath(),
false ,
false );
587 public static String
getParentOf(
final String path)
throws URISyntaxException {
588 final int pl =
null!=path ? path.length() : 0;
590 throw new IllegalArgumentException(
"path is empty <"+path+
">");
593 final int e = path.lastIndexOf(
"/");
595 throw new URISyntaxException(path,
"path contains no '/': <"+path+
">");
599 throw new URISyntaxException(path,
"path has no parents: <"+path+
">");
603 return path.substring(0, e+1);
605 final int j = path.lastIndexOf(
"!") + 1;
607 final int p = path.lastIndexOf(
"/", e-1);
610 return path.substring(0, p+1);
613 final String parent = path.substring(j, e);
614 if( parent.equals(
"..") ) {
615 throw new URISyntaxException(path,
"parent is unresolved: <"+path+
">");
618 return path.substring(0, j);
631 int idx = path.length() - 1;
632 while ( idx >= 1 && ( idx = path.lastIndexOf(
"./", idx) ) >= 0 ) {
633 if( 0 < idx && path.charAt(idx-1) ==
'.' ) {
636 path = path.substring(0, idx) + path.substring(idx+2);
641 while ( ( idx = path.indexOf(
"../", idx) ) >= 0 ) {
645 path =
getParentOf(path.substring(0, idx)) + path.substring(idx+3);
657 public static URLConnection
openURL(
final URL url) {
664 public static URLConnection
openURL(
final URL url,
final String dbgmsg) {
667 final URLConnection c = url.openConnection();
670 System.err.println(
"IOUtil: urlExists("+url+
") ["+dbgmsg+
"] - true");
673 }
catch (
final IOException ioe) {
679 System.err.println(
"IOUtil: no url - urlExists(null) ["+dbgmsg+
"]");
685 private static String getExeTestFileSuffix() {
697 private static String getExeTestShellCode() {
698 switch(PlatformProps.OS) {
700 return "echo off"+PlatformProps.NEWLINE;
702 return "#!/bin/test"+PlatformProps.NEWLINE;
704 return "#!/bin/true"+PlatformProps.NEWLINE;
707 private static String[] getExeTestCommandArgs(
final String scriptFile) {
708 switch(PlatformProps.OS) {
712 return new String[] { scriptFile };
716 private static void fillExeTestFile(
final File exefile)
throws IOException {
717 final String shellCode = getExeTestShellCode();
718 if( isStringSet(shellCode) ) {
719 final FileWriter fout =
new FileWriter(exefile);
721 fout.write(shellCode);
724 }
catch (
final IOException sfe) {
725 ExceptionUtils.dumpThrowable(
"", sfe);
732 private static boolean getOSHasNoexecFS() {
733 switch(PlatformProps.OS) {
745 private static boolean getOSHasFreeDesktopXDG() {
746 switch(PlatformProps.OS) {
767 public static boolean testFile(
final File file,
final boolean shallBeDir,
final boolean shallBeWritable) {
768 if (!file.exists()) {
770 System.err.println(
"IOUtil.testFile: <"+file.getAbsolutePath()+
">: does not exist");
774 if (shallBeDir && !file.isDirectory()) {
776 System.err.println(
"IOUtil.testFile: <"+file.getAbsolutePath()+
">: is not a directory");
780 if (shallBeWritable && !file.canWrite()) {
782 System.err.println(
"IOUtil.testFile: <"+file.getAbsolutePath()+
">: is not writable");
790 private final InputStream[] istreams;
791 private final boolean[] eos;
792 private final PrintStream ostream;
793 private final String prefix;
794 public StreamMonitor(
final InputStream[] streams,
final PrintStream ostream,
final String prefix) {
795 this.istreams = streams;
796 this.eos =
new boolean[streams.length];
797 this.ostream = ostream;
798 this.prefix = prefix;
799 final InterruptSource.Thread t =
new InterruptSource.
Thread(
null,
this,
"StreamMonitor-"+Thread.currentThread().getName());
807 final byte[] buffer =
new byte[4096];
809 final int streamCount = istreams.length;
812 for(
int i=0; i<istreams.length; i++) {
814 final int numReadI = istreams[i].read(buffer);
816 if(
null != ostream ) {
817 if(
null != prefix ) {
818 ostream.write(prefix.getBytes());
820 ostream.write(buffer, 0, numReadI);
829 if(
null != ostream ) {
832 }
while ( eosCount < streamCount );
833 }
catch (
final IOException e) {
835 if(
null != ostream ) {
843 private static final Boolean isNioExecutableFile(
final File file) {
845 return java.nio.file.Files.isExecutable( file.toPath() );
846 }
catch (
final Throwable t) {
847 throw new RuntimeException(
"error invoking Files.isExecutable(file.toPath())", t);
864 throws SecurityException
866 final boolean debug = DEBUG_EXE ||
DEBUG;
868 if( !testTempDirExec ) {
870 System.err.println(
"IOUtil.testDirExec: <"+dir.getAbsolutePath()+
">: Disabled TestTempDirExec");
876 System.err.println(
"IOUtil.testDirExec: <"+dir.getAbsolutePath()+
">: Not writeable dir");
880 if(!getOSHasNoexecFS()) {
882 System.err.println(
"IOUtil.testDirExec: <"+dir.getAbsolutePath()+
">: Always executable");
887 final long t0 = debug ? System.currentTimeMillis() : 0;
888 final File exeTestFile;
889 final boolean existingExe;
891 final File permExeTestFile = DEBUG_EXE_EXISTING_FILE ?
new File(dir,
"jau_exe_tst"+getExeTestFileSuffix()) :
null;
892 if(
null != permExeTestFile && permExeTestFile.exists() ) {
893 exeTestFile = permExeTestFile;
896 exeTestFile = File.createTempFile(
"jau_exe_tst", getExeTestFileSuffix(), dir);
898 fillExeTestFile(exeTestFile);
900 }
catch (
final SecurityException se) {
902 }
catch (
final IOException e) {
908 final long t1 = debug ? System.currentTimeMillis() : 0;
912 Boolean isNioExec =
null;
913 if( existingExe || exeTestFile.setExecutable(
true ,
true ) ) {
914 t2 = debug ? System.currentTimeMillis() : 0;
916 isNioExec = isNioExecutableFile(exeTestFile);
917 if(
null != isNioExec ) {
918 res = isNioExec.booleanValue() ? 0 : -1;
920 if(
null == isNioExec || 0 <= res ) {
928 pr = Runtime.getRuntime().exec( getExeTestCommandArgs( exeTestFile.getCanonicalPath() ),
null,
null );
929 if( DEBUG_EXE && !DEBUG_EXE_NOSTREAM ) {
930 new StreamMonitor(
new InputStream[] { pr.getInputStream(), pr.getErrorStream() }, System.err,
"Exe-Tst: ");
933 exitValue = pr.exitValue();
934 if( 0 == exitValue ) {
939 }
catch (
final SecurityException se) {
941 }
catch (
final Throwable t) {
942 t2 = debug ? System.currentTimeMillis() : 0;
945 System.err.println(
"IOUtil.testDirExec: <"+exeTestFile.getAbsolutePath()+
">: Caught "+t.getClass().getSimpleName()+
": "+t.getMessage());
955 }
catch (
final Throwable t) {
962 t2 = debug ? System.currentTimeMillis() : 0;
965 final boolean ok = 0 <= res;
966 if( !DEBUG_EXE && !existingExe ) {
967 exeTestFile.delete();
970 final long t3 = System.currentTimeMillis();
971 System.err.println(
"IOUtil.testDirExec(): test-exe <"+exeTestFile.getAbsolutePath()+
">, existingFile "+existingExe+
", isNioExec "+isNioExec+
", returned "+exitValue);
972 System.err.println(
"IOUtil.testDirExec(): abs-path <"+dir.getAbsolutePath()+
">: res "+res+
" -> "+ok);
973 System.err.println(
"IOUtil.testDirExec(): total "+(t3-t0)+
"ms, create "+(t1-t0)+
"ms, fill "+(t2-t1)+
"ms, execute "+(t3-t2)+
"ms");
978 private static File testDirImpl(
final File dir,
final boolean create,
final boolean executable,
final String dbgMsg)
979 throws SecurityException
982 if (create && !dir.exists()) {
988 res =
testFile(dir,
true,
true) ? dir :
null;
991 System.err.println(
"IOUtil.testDirImpl("+dbgMsg+
"): <"+dir.getAbsolutePath()+
">, create "+create+
", exec "+executable+
": "+(
null != res));
1010 public static File
testDir(
final File dir,
final boolean create,
final boolean executable)
1011 throws SecurityException
1013 return testDirImpl(dir, create, executable,
"testDir");
1016 private static boolean isStringSet(
final String s) {
return null != s && 0 < s.length(); }
1042 private static File getSubTempDir(
final File tmpRoot,
final String tmpSubDirPrefix,
final boolean executable,
final String dbgMsg)
1043 throws SecurityException
1045 File tmpBaseDir =
null;
1046 if(
null != testDirImpl(tmpRoot,
true , executable, dbgMsg)) {
1047 for(
int i = 0;
null == tmpBaseDir && i<=9999; i++) {
1048 final String tmpDirSuffix = String.format((Locale)
null,
"_%04d", i);
1049 tmpBaseDir = testDirImpl(
new File(tmpRoot, tmpSubDirPrefix+tmpDirSuffix),
true , executable, dbgMsg);
1055 private static File getFile(
final String fname) {
1056 if( isStringSet(fname) ) {
1057 return new File(fname);
1090 throws SecurityException, IOException
1093 synchronized(
IOUtil.class) {
1098 if(
null != ctxTempDir) {
1099 tempRootNoexec = getSubTempDir(ctxTempDir,
tmpSubDir,
false ,
"Android.ctxTemp");
1100 tempRootExec = tempRootNoexec;
1101 return tempRootExec;
1107 System.err.println(
"IOUtil.getTempRoot(): tempX1 <"+java_io_tmpdir+
">, used "+(
null!=java_io_tmpdir));
1110 final File user_tmpdir;
1112 String __user_tmpdir = System.getenv(
"TMPDIR");
1113 if( !isStringSet(__user_tmpdir) ) {
1114 __user_tmpdir = System.getenv(
"TEMP");
1116 final File _user_tmpdir = getFile(__user_tmpdir);
1117 if(
null != _user_tmpdir && !_user_tmpdir.equals(java_io_tmpdir) ) {
1118 user_tmpdir = _user_tmpdir;
1123 System.err.println(
"IOUtil.getTempRoot(): tempX3 <"+_user_tmpdir+
">, used "+(
null!=user_tmpdir));
1129 System.err.println(
"IOUtil.getTempRoot(): tempX4 <"+user_home+
">, used "+(
null!=user_home));
1132 final File xdg_cache_home;
1134 String __xdg_cache_home;
1135 if( getOSHasFreeDesktopXDG() ) {
1136 __xdg_cache_home = System.getenv(XDG_CACHE_HOME_envkey);
1137 if( !isStringSet(__xdg_cache_home) &&
null != user_home ) {
1138 __xdg_cache_home = user_home.getAbsolutePath() + File.separator +
".cache" ;
1141 __xdg_cache_home =
null;
1143 final File _xdg_cache_home = getFile(__xdg_cache_home);
1144 if(
null != _xdg_cache_home && !_xdg_cache_home.equals(java_io_tmpdir) ) {
1145 xdg_cache_home = _xdg_cache_home;
1147 xdg_cache_home =
null;
1150 System.err.println(
"IOUtil.getTempRoot(): tempX2 <"+_xdg_cache_home+
">, used "+(
null!=xdg_cache_home));
1155 if(
null == tempRootExec &&
null != java_io_tmpdir ) {
1159 tempRootExec = getSubTempDir(java_io_tmpdir,
tmpSubDir,
false ,
"tempX1");
1161 tempRootExec = getSubTempDir(java_io_tmpdir,
tmpSubDir,
true ,
"tempX1");
1166 if(
null == tempRootExec &&
null != xdg_cache_home ) {
1167 tempRootExec = getSubTempDir(xdg_cache_home,
tmpSubDir,
true ,
"tempX2");
1171 if(
null == tempRootExec &&
null != user_tmpdir ) {
1172 tempRootExec = getSubTempDir(user_tmpdir,
tmpSubDir,
true ,
"tempX3");
1176 if(
null == tempRootExec &&
null != user_home ) {
1177 tempRootExec = getSubTempDir(user_home,
"." +
tmpSubDir,
true ,
"tempX4");
1180 if(
null != tempRootExec ) {
1181 tempRootNoexec = tempRootExec;
1184 if(
null == tempRootNoexec &&
null != java_io_tmpdir ) {
1185 tempRootNoexec = getSubTempDir(java_io_tmpdir,
tmpSubDir,
false ,
"temp01");
1189 if(
null == tempRootNoexec &&
null != xdg_cache_home ) {
1190 tempRootNoexec = getSubTempDir(xdg_cache_home,
tmpSubDir,
false ,
"temp02");
1194 if(
null == tempRootNoexec &&
null != user_tmpdir ) {
1195 tempRootNoexec = getSubTempDir(user_tmpdir,
tmpSubDir,
false ,
"temp03");
1199 if(
null == tempRootNoexec &&
null != user_home ) {
1200 tempRootNoexec = getSubTempDir(user_home,
"." +
tmpSubDir,
false ,
"temp04");
1205 final String tempRootExecAbsPath =
null != tempRootExec ? tempRootExec.getAbsolutePath() :
null;
1206 final String tempRootNoexecAbsPath =
null != tempRootNoexec ? tempRootNoexec.getAbsolutePath() :
null;
1207 System.err.println(
"IOUtil.getTempRoot(): temp dirs: exec: "+tempRootExecAbsPath+
", noexec: "+tempRootNoexecAbsPath);
1212 final File r = executable ? tempRootExec : tempRootNoexec ;
1214 final String exe_s = executable ?
"executable " :
"";
1215 throw new IOException(
"Could not determine a temporary "+exe_s+
"directory");
1217 final FilePermission fp =
new FilePermission(r.getAbsolutePath(),
"read,write,delete");
1221 private static File tempRootExec =
null;
1222 private static File tempRootNoexec =
null;
1223 private static volatile boolean tempRootSet =
false;
1242 public static File
createTempFile(
final String prefix,
final String suffix,
final boolean executable)
1243 throws IllegalArgumentException, IOException, SecurityException
1245 return File.createTempFile( prefix, suffix,
getTempDir(executable) );
1248 public static void close(
final Closeable stream,
final boolean throwRuntimeException)
throws RuntimeException {
1249 if(
null != stream) {
1252 }
catch (
final IOException e) {
1253 if(throwRuntimeException) {
1254 throw new RuntimeException(e);
1256 System.err.println(
"Caught Exception: ");
1257 e.printStackTrace();
1271 public static IOException
close(
final Closeable stream,
final IOException[] saveOneIfFree,
final PrintStream dumpExcess) {
1274 }
catch(
final IOException e) {
1275 if(
null == saveOneIfFree[0] ) {
1276 saveOneIfFree[0] = e;
1278 if(
null != dumpExcess ) {
1279 dumpExcess.println(
"Caught "+e.getClass().getSimpleName()+
": "+e.getMessage());
1280 e.printStackTrace(dumpExcess);
1295 public static ArrayList<String>
filesOf(
final List<String> paths,
final List<Pattern> excludes,
final List<Pattern> includes) {
1296 final ArrayList<String> files =
new ArrayList<String>(paths.size()*32);
1297 final ArrayList<String> todo =
new ArrayList<String>(paths);
1298 while(todo.size() > 0) {
1299 final String p = todo.remove(0);
1300 if(
null != excludes && excludes.size() > 0) {
1301 boolean exclude =
false;
1302 for(
int i=0; !exclude && i<excludes.size(); i++) {
1303 exclude = excludes.get(i).matcher(p).matches();
1306 System.err.println(
"IOUtil.filesOf(): excluding <"+p+
"> (exclude["+i+
"]: "+excludes.get(i)+
")");
1314 final File f =
new File(p);
1317 System.err.println(
"IOUtil.filesOf(): not existing: "+f);
1320 }
else if( f.isDirectory() ) {
1321 final String[] subs = f.list();
1322 if(
null == subs ) {
1324 System.err.println(
"IOUtil.filesOf(): null list of directory: "+f);
1326 }
else if( 0 == subs.length ) {
1328 System.err.println(
"IOUtil.filesOf(): empty list of directory: "+f);
1332 final String pp = p.endsWith(
"/") ? p : p+
"/";
1333 for(
int i=0; i<subs.length; i++) {
1334 todo.add(j++, pp+subs[i]);
1338 if(
null != includes && includes.size() > 0) {
1339 boolean include =
false;
1340 for(
int i=0; !include && i<includes.size(); i++) {
1341 include = includes.get(i).matcher(p).matches();
1344 System.err.println(
"IOUtil.filesOf(): including <"+p+
"> (including["+i+
"]: "+includes.get(i)+
")");
Utility methods allowing easy java.nio.Buffer manipulations.
static ByteBuffer newDirectByteBuffer(final int size)
Allocates a new direct ByteBuffer with the specified number of elements.
Helper compound associating a class instance and resource paths to be resolved at a later time.
final ClassLoader classLoader
Optional ClassLoader used to resolve(int) resourcePaths.
final int resourceCount()
Returns the number of resources, i.e.
URLConnection resolve(final int uriIndex)
Resolving one of the resourcePaths indexed by uriIndex using classLoader, contextCL through IOUtil#ge...
ClassResources(final String[] resourcePaths, final ClassLoader classLoader, final Class<?> relContext)
final String[] resourcePaths
Resource paths, see resolve(int).
final Class<?> contextCL
Optional class instance used to resolve(int) relative resourcePaths.
StreamMonitor(final InputStream[] streams, final PrintStream ostream, final String prefix)
static URL getClassURL(final String clazzBinName, final ClassLoader cl)
static String getFileSuffix(final File file)
Returns the lowercase suffix of the given file name (the text after the last '.
static String getParentOf(final String path)
static final boolean DEBUG
static int copyStream2Stream(final int bufferSize, final InputStream in, final OutputStream out, final int totalNumBytes)
Copy the specified input stream to the specified output stream.
static IOException close(final Closeable stream, final IOException[] saveOneIfFree, final PrintStream dumpExcess)
Helper to simplify closing Closeables.
static final String tmpSubDir
Subdirectory within platform's temporary root directory where all JogAmp related temp files are being...
static int copyStream2Stream(final InputStream in, final OutputStream out, final int totalNumBytes)
Copy the specified input stream to the specified output stream.
static boolean testFile(final File file, final boolean shallBeDir, final boolean shallBeWritable)
Test whether file exists and matches the given requirements.
static String getDirname(String fname)
Returns unified '/' dirname including the last '/'.
static URLConnection openURL(final URL url)
Returns the connected URLConnection, or null if not url is not available.
static File testDir(final File dir, final boolean create, final boolean executable)
Returns the directory dir, which is processed and tested as described below.
static int copyURLConn2File(final URLConnection conn, final File outFile)
Copy the specified URL resource to the specified output file.
static String getRelativeOf(final File baseLocation, final String relativeFile)
Generates a path for the 'relativeFile' relative to the 'baseLocation'.
static boolean testDirExec(final File dir)
Returns true if the given dir @endiliteral.
static ByteBuffer copyStream2ByteBuffer(InputStream stream, int initialCapacity)
Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.
static File createTempFile(final String prefix, final String suffix, final boolean executable)
Utilizing File#createTempFile(String, String, File) using getTempDir(boolean) as the directory parame...
static String slashify(final String path, final boolean startWithSlash, final boolean endWithSlash)
static URLConnection openURL(final URL url, final String dbgmsg)
Returns the connected URLConnection, or null if not url is not available.
static ArrayList< String > filesOf(final List< String > paths, final List< Pattern > excludes, final List< Pattern > includes)
Retrieve the list of all filenames traversing through given paths.
static String getClassFileName(final String clazzBinName)
static FileOutputStream getFileOutputStream(final File file, final boolean allowOverwrite)
static String getBasename(String fname)
Returns the basename of the given fname w/o directory part.
static String getFileSuffix(final String filename)
Returns the lowercase suffix of the given file name (the text after the last '.
static URLConnection getResource(final String resourcePath, final ClassLoader cl)
Locating a resource using the ClassLoader's facilities and org.jau.net.AssetURLContext.
static int copyStream2File(final InputStream in, final File outFile, int totalNumBytes)
Copy the specified input stream to the specified output file.
static String cleanPathString(String path)
static File getTempDir(final boolean executable)
Returns a platform independent writable directory for temporary files consisting of the platform's te...
static byte[] copyStream2ByteArray(InputStream stream)
Copy the specified input stream to a byte array, which is being returned.
static URLConnection getResource(final String resourcePath, final ClassLoader classLoader, final Class<?> relContext)
Locating a resource using getResource(String, ClassLoader):
static void close(final Closeable stream, final boolean throwRuntimeException)
static final Pattern patternSpaceEnc
static ByteBuffer copyStream2ByteBuffer(final InputStream stream)
Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned.
static StringBuilder appendCharStream(final StringBuilder sb, final Reader r)
static void dumpThrowable(final String additionalDescr, final Throwable t)
Dumps a Throwable to System.err in a decorating message including the current thread name,...
java.lang.Thread specialization implementing InterruptSource to track java.lang.Thread#interrupt() ca...
Convenient Method access class.
Utility methods to simplify reflection access.
static final Class<?> getClass(final String clazzName, final boolean initializeClazz, final ClassLoader cl)
Loads and returns the class or null.
static final void checkPermission(final Permission perm)
Throws an SecurityException if an installed SecurityManager does not permit the requested Permission.
static< T > T doPrivileged(final PrivilegedAction< T > o)
Call wrapper for java.security.AccessController#doPrivileged(PrivilegedAction).
static File getTempRoot()
Helper routines for logging and debugging.
static final boolean debug(final String subcomponent)
Machine data description for alignment and size onle, see com.jogamp.gluegen.
int pageAlignedSize(final int size)
Helper routines for accessing properties.
static final String getProperty(final String propertyKey, final boolean jnlpAlias)
Query the property with the name propertyKey.
static final boolean getBooleanProperty(final String property, final boolean jnlpAlias)
static final boolean isPropertyDefined(final String property, final boolean jnlpAlias)
Interface exposing java.lang.Thread#interrupt() source, intended for java.lang.Thread specializations...