|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.sciss.io.IOUtil
public class IOUtil
This is a helper class containing utility static functions for common file operations.
Field Summary | |
---|---|
static java.lang.String |
KEY_TEMPDIR
Value: String representing the pathname of the temporary files directory. |
Method Summary | |
---|---|
static java.lang.String |
abbreviate(java.lang.String fileName,
int maxLen)
Abbreviates a path name by replacing sub directories by an ellipsis character. |
static void |
createEmptyDirectory(java.io.File f)
Creates a new empty directory. |
static void |
createEmptyFile(java.io.File f)
Creates an empty file. |
static java.io.File |
createTempFile()
Creates a new temporary file, using the preferred temp file folder ( KEY_TEMPDIR ). |
static java.io.File |
createTempFile(java.lang.String prefix,
java.lang.String suffix)
Create a new temporary file with specified prefix and suffix. |
static void |
deleteAll(java.io.File f)
Deletes a file or directory. |
static java.lang.String |
getResourceString(java.lang.String key)
|
static java.util.prefs.Preferences |
getUserPrefs()
|
static double |
getVersion()
|
static java.io.IOException |
map(java.lang.Exception e)
Input/output methods sometimes contain methods from other java API that throw exceptions which are not subclasses of IOException . |
static java.io.File |
nonExistentFileVariant(java.io.File template,
int insertPos,
java.lang.String prefix,
java.lang.String suffix)
Iteratres a filename template as long as filenames generated by the template already exist. |
static java.io.File |
setFileSuffix(java.io.File f,
java.lang.String ext)
Sets the extension (suffix) of a file name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String KEY_TEMPDIR
Method Detail |
---|
public static final java.util.prefs.Preferences getUserPrefs()
public static final double getVersion()
public static final java.lang.String getResourceString(java.lang.String key)
public static java.io.IOException map(java.lang.Exception e)
IOException
. The present a more
consistent frontend to the caller of these
methods, any exceptions can be simply mapped
to IOException
by creating a new IOException
with the same message text as the original
exception.
For example, in PrefsUtil
's toXML
method,
BackingStoreException
s and DOMException
s are
caught and rethrown:
try { ... } catch( DOMException e1 ) { throw IOUtil.map( e1 ); }
e
- the original exception whose message is queries
and copied to the returned exception.
IOException
with the message text
and exception class name copied from the given original
exception.public static java.lang.String abbreviate(java.lang.String fileName, int maxLen)
MenuFactory
to shorten the pathnames attached to
the Open-Recent menu.
fileName
- the pathName to abbreviatemaxLen
- maximum length of the
Abbreviation. Beware: this
method appends sub directories
until maxLen is exceeded, therefore
the returned String can well exceed
maxLen!
public static void createEmptyDirectory(java.io.File f) throws java.io.IOException
f
- pathname denoting the folder to create.
this method will attempt to create nonexisting
parent folders if required.
java.io.IOException
- is the directory cannot be created
or emptied.deleteAll( File )
,
File.mkdirs()
public static void createEmptyFile(java.io.File f) throws java.io.IOException
f
already exists, it will
be erased.
f
- the file to be erased
java.io.IOException
- if an error occurs such as the file
being protected or indicating an invalid pathpublic static java.io.File createTempFile() throws java.io.IOException
KEY_TEMPDIR
). The file will
automatically deleted upon
application exit.
java.io.IOException
- if this method fails to create the fileFile.createTempFile( String, String, File )
,
File.deleteOnExit()
,
KEY_TEMPDIR
public static java.io.File createTempFile(java.lang.String prefix, java.lang.String suffix) throws java.io.IOException
prefix
- string with which to filename
shall begin, minimum three letters but
as short as possible. might be truncated.suffix
- string with which to filename
shall end (including the period if used as a file type suffix).
might be truncated, but if it begins with a period, the
following three letters are guaranteed to be preserved.
java.io.IOException
- if this method fails to create the fileFile.createTempFile( String, String, File )
,
File.deleteOnExit()
,
KEY_TEMPDIR
public static void deleteAll(java.io.File f) throws java.io.IOException
f
- the path (file or folder) to delete
java.io.IOException
- if the deletion failsFile.delete()
public static java.io.File setFileSuffix(java.io.File f, java.lang.String ext)
f
- the file whose suffix to change.
can be null
in which
case null
is returnedext
- the new suffix, e.g. ".aif", ".xml" etc.
the leading period may be omitted.
if ext
is null
,
the suffix is removed.
public static java.io.File nonExistentFileVariant(java.io.File template, int insertPos, java.lang.String prefix, java.lang.String suffix)
Example: with template = new File( "/Users/schoko/myFile.aif" )
,
insertPos = -1
and prefix = " "
(white space),
the method will first check if file "/Users/schoko/myFile.aif"
exists, if not that file will be returned. Next, it will check for the file
"/Users/schoko/myFile 1.aif", then for "/Users/schoko/myFile 2.aif"
etc.
template
- template pathinsertPos
- the index in the name portion of the template at which variants are to be inserted;
if insertPos
is -1
, the position of the period
of the filetype suffix will be used (and if not found, the end of the template).prefix
- a string to paste before the inserted variant, can be null
suffix
- a string to paste after the inserted variant, can be null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |