jaulib v1.1.2-115-g39e35fd
Jau Support Library (C++, Java, ..)
Classes | Static Public Member Functions | Static Public Attributes | List of all members
org.jau.io.IOUtil Class Reference
Collaboration diagram for org.jau.io.IOUtil:

Classes

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

Static Public Member Functions

static int copyURLConn2File (final URLConnection conn, final File outFile) throws IOException
 Copy the specified URL resource to the specified output file. More...
 
static int copyStream2File (final InputStream in, final File outFile, int totalNumBytes) throws IOException
 Copy the specified input stream to the specified output file. More...
 
static int copyStream2Stream (final InputStream in, final OutputStream out, final int totalNumBytes) throws IOException
 Copy the specified input stream to the specified output stream. More...
 
static int copyStream2Stream (final int bufferSize, final InputStream in, final OutputStream out, final int totalNumBytes) throws IOException
 Copy the specified input stream to the specified output stream. More...
 
static StringBuilder appendCharStream (final StringBuilder sb, final Reader r) throws IOException
 
static byte[] copyStream2ByteArray (InputStream stream) throws IOException
 Copy the specified input stream to a byte array, which is being returned. More...
 
static ByteBuffer copyStream2ByteBuffer (final InputStream stream) throws IOException
 Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned. More...
 
static ByteBuffer copyStream2ByteBuffer (InputStream stream, int initialCapacity) throws IOException
 Copy the specified input stream to a NIO ByteBuffer w/ native byte order, which is being returned. More...
 
static String slashify (final String path, final boolean startWithSlash, final boolean endWithSlash) throws URISyntaxException
 
static String getFileSuffix (final File file)
 Returns the lowercase suffix of the given file name (the text after the last '. More...
 
static String getFileSuffix (final String filename)
 Returns the lowercase suffix of the given file name (the text after the last '. More...
 
static FileOutputStream getFileOutputStream (final File file, final boolean allowOverwrite) throws IOException
 
static String getClassFileName (final String clazzBinName)
 
static URL getClassURL (final String clazzBinName, final ClassLoader cl) throws IOException
 
static String getBasename (String fname) throws URISyntaxException
 Returns the basename of the given fname w/o directory part. More...
 
static String getDirname (String fname) throws URISyntaxException
 Returns unified '/' dirname including the last '/'. More...
 
static URLConnection getResource (final String resourcePath, final ClassLoader classLoader, final Class<?> relContext)
 Locating a resource using getResource(String, ClassLoader): More...
 
static URLConnection getResource (final String resourcePath, final ClassLoader cl)
 Locating a resource using the ClassLoader's facilities and org.jau.net.AssetURLContext. More...
 
static String getRelativeOf (final File baseLocation, final String relativeFile) throws URISyntaxException
 Generates a path for the 'relativeFile' relative to the 'baseLocation'. More...
 
static String getParentOf (final String path) throws URISyntaxException
 
static String cleanPathString (String path) throws URISyntaxException
 
static URLConnection openURL (final URL url)
 Returns the connected URLConnection, or null if not url is not available. More...
 
static URLConnection openURL (final URL url, final String dbgmsg)
 Returns the connected URLConnection, or null if not url is not available. More...
 
static boolean testFile (final File file, final boolean shallBeDir, final boolean shallBeWritable)
 Test whether file exists and matches the given requirements. More...
 
static boolean testDirExec (final File dir) throws SecurityException
 Returns true if the given dir @endiliteral.
More...
 
static File testDir (final File dir, final boolean create, final boolean executable) throws SecurityException
 Returns the directory dir, which is processed and tested as described below. More...
 
static File getTempDir (final boolean executable) throws SecurityException, IOException
 Returns a platform independent writable directory for temporary files consisting of the platform's temp-root + tmpSubDir, e.g. More...
 
static File createTempFile (final String prefix, final String suffix, final boolean executable) throws IllegalArgumentException, IOException, SecurityException
 Utilizing File#createTempFile(String, String, File) using getTempDir(boolean) as the directory parameter, ie. More...
 
static void close (final Closeable stream, final boolean throwRuntimeException) throws RuntimeException
 
static IOException close (final Closeable stream, final IOException[] saveOneIfFree, final PrintStream dumpExcess)
 Helper to simplify closing Closeables. More...
 
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. More...
 

Static Public Attributes

static final boolean DEBUG
 
static final String tmpSubDir = "jau"
 Subdirectory within platform's temporary root directory where all JogAmp related temp files are being stored: jau
More...
 
static final Pattern patternSpaceEnc = Pattern.compile("%20")
 

Detailed Description

Definition at line 61 of file IOUtil.java.

Member Function Documentation

◆ appendCharStream()

static StringBuilder org.jau.io.IOUtil.appendCharStream ( final StringBuilder  sb,
final Reader  r 
) throws IOException
static

Definition at line 219 of file IOUtil.java.

◆ cleanPathString()

static String org.jau.io.IOUtil.cleanPathString ( String  path) throws URISyntaxException
static
Parameters
pathassuming a slashified path, either denoting a file or directory, either relative or absolute.
Returns
clean path string where ./ and ../ is resolved, while keeping a starting ../ at the beginning of a relative path.
Exceptions
URISyntaxExceptionif path is empty or has no parent directory available while resolving ../

Definition at line 629 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close() [1/2]

static void org.jau.io.IOUtil.close ( final Closeable  stream,
final boolean  throwRuntimeException 
) throws RuntimeException
static

Definition at line 1248 of file IOUtil.java.

Here is the caller graph for this function:

◆ close() [2/2]

static IOException org.jau.io.IOUtil.close ( final Closeable  stream,
final IOException[]  saveOneIfFree,
final PrintStream  dumpExcess 
)
static

Helper to simplify closing Closeables.

Parameters
streamthe Closeable instance to close
saveOneIfFreecache for one IOException to store, if not already used (excess)
dumpExcessdump the excess IOException on this PrintStream
Returns
the excess IOException or null.

Definition at line 1271 of file IOUtil.java.

◆ copyStream2ByteArray()

static byte[] org.jau.io.IOUtil.copyStream2ByteArray ( InputStream  stream) throws IOException
static

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

Definition at line 231 of file IOUtil.java.

Here is the caller graph for this function:

◆ copyStream2ByteBuffer() [1/2]

static ByteBuffer org.jau.io.IOUtil.copyStream2ByteBuffer ( final InputStream  stream) throws IOException
static

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.

Parameters
streaminput stream, which will be wrapped into a BufferedInputStream, if not already done.

Definition at line 267 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyStream2ByteBuffer() [2/2]

static ByteBuffer org.jau.io.IOUtil.copyStream2ByteBuffer ( InputStream  stream,
int  initialCapacity 
) throws IOException
static

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.

Parameters
streaminput stream, which will be wrapped into a BufferedInputStream, if not already done.
initialCapacityinitial buffer capacity in bytes, if > available bytes

Definition at line 278 of file IOUtil.java.

Here is the call graph for this function:

◆ copyStream2File()

static int org.jau.io.IOUtil.copyStream2File ( final InputStream  in,
final File  outFile,
int  totalNumBytes 
) throws IOException
static

Copy the specified input stream to the specified output file.

The total number of bytes written is returned.

Parameters
inthe source
outFilethe destination
totalNumBytesinformal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
Returns
Exceptions
IOException

Definition at line 170 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyStream2Stream() [1/2]

static int org.jau.io.IOUtil.copyStream2Stream ( final InputStream  in,
final OutputStream  out,
final int  totalNumBytes 
) throws IOException
static

Copy the specified input stream to the specified output stream.

The total number of bytes written is returned.

Parameters
inthe source
outthe destination
totalNumBytesinformal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
Returns
Exceptions
IOException

Definition at line 190 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyStream2Stream() [2/2]

static int org.jau.io.IOUtil.copyStream2Stream ( final int  bufferSize,
final InputStream  in,
final OutputStream  out,
final int  totalNumBytes 
) throws IOException
static

Copy the specified input stream to the specified output stream.

The total number of bytes written is returned.

Parameters
bufferSizethe intermediate buffer size, should be MachineDataInfo#pageSizeInBytes() for best performance.
inthe source
outthe destination
totalNumBytesinformal number of expected bytes, maybe used for user feedback while processing. -1 if unknown
Returns
Exceptions
IOException

Definition at line 205 of file IOUtil.java.

◆ copyURLConn2File()

static int org.jau.io.IOUtil.copyURLConn2File ( final URLConnection  conn,
final File  outFile 
) throws IOException
static

Copy the specified URL resource to the specified output file.

The total number of bytes written is returned.

Parameters
connthe open URLConnection
outFilethe destination
Returns
Exceptions
IOException

Definition at line 147 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createTempFile()

static File org.jau.io.IOUtil.createTempFile ( final String  prefix,
final String  suffix,
final boolean  executable 
) throws IllegalArgumentException, IOException, SecurityException
static

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

location of the root temp folder.

See also
File::createTempFile(String, String)
File::createTempFile(String, String, File)
getTempDir(boolean)
Parameters
prefix
suffix
executabletrue if the temporary root folder needs to hold executable files, otherwise false.
Returns
Exceptions
IllegalArgumentException
IOExceptionif no temporary directory could be determined or temp file could not be created
SecurityException

Definition at line 1242 of file IOUtil.java.

Here is the call graph for this function:

◆ filesOf()

static ArrayList< String > org.jau.io.IOUtil.filesOf ( final List< String >  paths,
final List< Pattern >  excludes,
final List< Pattern >  includes 
)
static

Retrieve the list of all filenames traversing through given paths.

Parameters
pathslist of paths to traverse through, containing directories and files
excludesoptional list of exclude Pattern. All matching files or directories will be omitted. Maybe be null or empty.
includesoptional list of explicit include Pattern. If given, only matching files will be returned, otherwise all occurring.
Returns
list of unsorted filenames within given paths

Definition at line 1295 of file IOUtil.java.

Here is the caller graph for this function:

◆ getBasename()

static String org.jau.io.IOUtil.getBasename ( String  fname) throws URISyntaxException
static

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

Exceptions
URISyntaxExceptionif path is empty or has no parent directory available while resolving ../

Definition at line 420 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getClassFileName()

static String org.jau.io.IOUtil.getClassFileName ( final String  clazzBinName)
static

Definition at line 397 of file IOUtil.java.

Here is the caller graph for this function:

◆ getClassURL()

static URL org.jau.io.IOUtil.getClassURL ( final String  clazzBinName,
final ClassLoader  cl 
) throws IOException
static
Parameters
clazzBinNamecom.jogamp.common.util.cache.TempJarCache
clClassLoader to locate the JarFile
Returns
jar:file:/usr/local/projects/JOGL/gluegen/build-x86_64/gluegen-rt.jar!/com/jogamp/common/util/cache/TempJarCache.class
Exceptions
IOExceptionif the jar file could not been found by the ClassLoader

Definition at line 408 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDirname()

static String org.jau.io.IOUtil.getDirname ( String  fname) throws URISyntaxException
static

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

Exceptions
URISyntaxExceptionif path is empty or has no parent directory available while resolving ../

Definition at line 433 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFileOutputStream()

static FileOutputStream org.jau.io.IOUtil.getFileOutputStream ( final File  file,
final boolean  allowOverwrite 
) throws IOException
static

Definition at line 386 of file IOUtil.java.

◆ getFileSuffix() [1/2]

static String org.jau.io.IOUtil.getFileSuffix ( final File  file)
static

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 of the file
Returns
lowercase suffix of the file name
Exceptions
NullPointerExceptionif file is null

Definition at line 349 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFileSuffix() [2/2]

static String org.jau.io.IOUtil.getFileSuffix ( final String  filename)
static

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
filenamename of the file
Returns
lowercase suffix of the file name
Exceptions
NullPointerExceptionif filename is null

Definition at line 363 of file IOUtil.java.

◆ getParentOf()

static String org.jau.io.IOUtil.getParentOf ( final String  path) throws URISyntaxException
static
Parameters
pathassuming a slashified path, either denotes a file or directory, either relative or absolute.
Returns
parent of path
Exceptions
URISyntaxExceptionif path is empty or has no parent directory available

Definition at line 587 of file IOUtil.java.

Here is the caller graph for this function:

◆ getRelativeOf()

static String org.jau.io.IOUtil.getRelativeOf ( final File  baseLocation,
final String  relativeFile 
) throws URISyntaxException
static

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

Parameters
baseLocationdenotes a directory
relativeFiledenotes a relative file to the baseLocation
Exceptions
URISyntaxExceptionif path is empty or has no parent directory available while resolving ../

Definition at line 569 of file IOUtil.java.

Here is the call graph for this function:

◆ getResource() [1/2]

static URLConnection org.jau.io.IOUtil.getResource ( final String  resourcePath,
final ClassLoader  cl 
)
static

Locating a resource using the ClassLoader's facilities and org.jau.net.AssetURLContext.

Returns the resolved and connected URLConnection or null if not found.

Return null if org.jau.net.AssetURLContext is not available.

See also
ClassLoader::getResource(String)
ClassLoader::getSystemResource(String)
URL::URL(String)
File::File(String)

Definition at line 554 of file IOUtil.java.

◆ getResource() [2/2]

static URLConnection org.jau.io.IOUtil.getResource ( final String  resourcePath,
final ClassLoader  classLoader,
final Class<?>  relContext 
)
static

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.

Returns the resolved and open URLConnection or null if not found.

Parameters
resourcePaththe resource path to locate relative or absolute
classLoaderthe optional ClassLoader, recommended
relContextrelative context, i.e. position, of the resourcePath, to perform the relative lookup, if not null.
See also
getResource(String, ClassLoader)
ClassLoader::getResource(String)
ClassLoader::getSystemResource(String)

Definition at line 512 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTempDir()

static File org.jau.io.IOUtil.getTempDir ( final boolean  executable) throws SecurityException, IOException
static

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

/tmp/jau_0000/.

On standard Java the temp-root folder is specified by java.io.tempdir.

On Android the temp-root folder is 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.init(..). This allows using the temp folder w/o the need for sdcard access, which would be the java.io.tempdir location on Android!

In case temp-root is the users home folder, a dot is being prepended to tmpSubDir, i.e.: /home/user/.jau_0000/.

Parameters
executabletrue if the user intents to launch executables from the temporary directory, otherwise false.
Exceptions
IOExceptionif no temporary directory could be determined
SecurityExceptionif access to java.io.tmpdir is not allowed within the current security context
See also
PropertyAccess::getProperty(String, boolean)
Context::getDir(String, int)

Definition at line 1089 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openURL() [1/2]

static URLConnection org.jau.io.IOUtil.openURL ( final URL  url)
static

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

Definition at line 657 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openURL() [2/2]

static URLConnection org.jau.io.IOUtil.openURL ( final URL  url,
final String  dbgmsg 
)
static

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

Definition at line 664 of file IOUtil.java.

Here is the call graph for this function:

◆ slashify()

static String org.jau.io.IOUtil.slashify ( final String  path,
final boolean  startWithSlash,
final boolean  endWithSlash 
) throws URISyntaxException
static
Parameters
path
startWithSlash
endWithSlash
Returns
Exceptions
URISyntaxExceptionif path is empty or has no parent directory available while resolving ../

Definition at line 327 of file IOUtil.java.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testDir()

static File org.jau.io.IOUtil.testDir ( final File  dir,
final boolean  create,
final boolean  executable 
) throws SecurityException
static

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

  1. If create is true and the directory does not exist yet, it is created incl. all sub-directories.
  2. If dirName exists, but is not a directory, null is being returned.
  3. If the directory does not exist or is not writeable, null is being returned.
  4. If executable is true and files cannot be executed from the directory, null is being returned.
Parameters
dirthe directory to process
createtrue if the directory shall be created if not existing
executabletrue if the user intents to launch executables from the temporary directory, otherwise false.
Exceptions
SecurityExceptionif file creation and process execution is not allowed within the current security context

Definition at line 1010 of file IOUtil.java.

◆ testDirExec()

static boolean org.jau.io.IOUtil.testDirExec ( final File  dir) throws SecurityException
static

Returns true if the given dir @endiliteral.

  1. exists, and
  2. is a directory, and
  3. is writeable, and
  4. files can be executed from the directory
Exceptions
SecurityExceptionif file creation and process execution is not allowed within the current security context
Parameters
dir

Definition at line 863 of file IOUtil.java.

Here is the call graph for this function:

◆ testFile()

static boolean org.jau.io.IOUtil.testFile ( final File  file,
final boolean  shallBeDir,
final boolean  shallBeWritable 
)
static

Test whether file exists and matches the given requirements.

Parameters
file
shallBeDir
shallBeWritable
Returns

Definition at line 767 of file IOUtil.java.

Here is the caller graph for this function:

Member Data Documentation

◆ DEBUG

final boolean org.jau.io.IOUtil.DEBUG
static

Definition at line 62 of file IOUtil.java.

◆ patternSpaceEnc

final Pattern org.jau.io.IOUtil.patternSpaceEnc = Pattern.compile("%20")
static

Definition at line 652 of file IOUtil.java.

◆ tmpSubDir

final String org.jau.io.IOUtil.tmpSubDir = "jau"
static

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

Definition at line 128 of file IOUtil.java.


The documentation for this class was generated from the following file: