|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ptolemy.util.FileUtilities
public class FileUtilities
A collection of utilities for manipulating files These utilities do not depend on any other ptolemy.* packages.
Green (cxh) |
Green (cxh) |
Field Summary | |
---|---|
private static java.lang.String |
_CLASSPATH_VALUE
Tag value used by this class and registered as a parser constant for the identifier "CLASSPATH" to indicate searching in the classpath. |
static java.io.BufferedReader |
STD_IN
Standard in as a reader, which will be non-null only after a call to openForReading("System.in"). |
static java.io.PrintWriter |
STD_OUT
Standard out as a writer, which will be non-null only after a call to openForWriting("System.out"). |
Constructor Summary | |
---|---|
private |
FileUtilities()
Instances of this class cannot be created. |
Method Summary | |
---|---|
private static void |
_binaryCopyStream(java.io.InputStream inputStream,
java.io.File destinationFile)
Copy files safely. |
private static byte[] |
_binaryReadStream(java.io.InputStream inputStream)
Read a stream safely. |
private static java.net.URL |
_searchClassPath(java.lang.String name,
java.lang.ClassLoader classLoader)
Search the classpath. |
private static java.lang.String |
_trimClassPath(java.lang.String name)
Remove the value of _CLASSPATH_VALUE or "$CLASSPATH". |
static boolean |
binaryCopyURLToFile(java.net.URL sourceURL,
java.io.File destinationFile)
Copy sourceURL to destinationFile without doing any byte conversion. |
static byte[] |
binaryReadURLToByteArray(java.net.URL sourceURL)
Read a sourceURL without doing any byte conversion. |
static void |
extractJarFile(java.lang.String jarFileName,
java.lang.String directoryName)
Extract a jar file into a directory. |
static void |
main(java.lang.String[] args)
Extract the contents of a jar file. |
static java.io.File |
nameToFile(java.lang.String name,
java.net.URI base)
Given a file name or URL, construct a java.io.File object that refers to the file name or URL. |
static java.net.URL |
nameToURL(java.lang.String name,
java.net.URI baseDirectory,
java.lang.ClassLoader classLoader)
Given a file or URL name, return as a URL. |
static java.io.BufferedReader |
openForReading(java.lang.String name,
java.net.URI base,
java.lang.ClassLoader classLoader)
Open the specified file for reading. |
static java.io.Writer |
openForWriting(java.lang.String name,
java.net.URI base,
boolean append)
Open the specified file for writing or appending. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.io.BufferedReader STD_IN
public static java.io.PrintWriter STD_OUT
private static java.lang.String _CLASSPATH_VALUE
Constructor Detail |
---|
private FileUtilities()
Method Detail |
---|
public static boolean binaryCopyURLToFile(java.net.URL sourceURL, java.io.File destinationFile) throws java.io.IOException
sourceURL
- The source URLdestinationFile
- The destination File.
java.io.IOException
- If the source file does not exist.public static byte[] binaryReadURLToByteArray(java.net.URL sourceURL) throws java.io.IOException
sourceURL
- The source URL
java.io.IOException
- If the source URL does not exist.public static void extractJarFile(java.lang.String jarFileName, java.lang.String directoryName) throws java.io.IOException
jar -xf
command.
jarFileName
- The name of the jar file to extractdirectoryName
- The name of the directory. If this argument
is null, then the files are extracted in the current directory.
java.io.IOException
- If the jar file cannot be opened, or
if there are problems extracting the contents of the jar filepublic static void main(java.lang.String[] args)
args
- An array of arguments. The first argument
names the jar file to be extracted. The first argument
is required. The second argument names the directory in
which to extract the files from the jar file. The second
argument is optional.public static java.io.File nameToFile(java.lang.String name, java.net.URI base)
If the name begins with "xxxxxxCLASSPATHxxxxxx" or "$CLASSPATH" then search for the file relative to the classpath.
Note that "xxxxxxCLASSPATHxxxxxx" is the value of the globally defined constant $CLASSPATH available in the Ptolemy II expression language.
If the name begins with $CLASSPATH or "xxxxxxCLASSPATHxxxxxx" but that name cannot be found in the classpath, the value of the ptolemy.ptII.dir property is substituted in.
The file need not exist for this method to succeed. Thus, this method can be used to determine whether a file with a given name exists, prior to calling openForWriting(), for example.
This method is similar to
nameToURL(String, URI, ClassLoader)
except that in this method, the file or URL must be readable.
Usually, this method is use for write a file and
nameToURL(String, URI, ClassLoader)
is used for reading.
name
- The file name or URL.base
- The base for relative URLs.
nameToURL(String, URI, ClassLoader)
public static java.net.URL nameToURL(java.lang.String name, java.net.URI baseDirectory, java.lang.ClassLoader classLoader) throws java.io.IOException
Note that "xxxxxxCLASSPATHxxxxxx" is the value of the globally defined constant $CLASSPATH available in the Ptolemy II expression language. II expression language.
If no file is found, then throw an exception.
This method is similar to nameToFile(String, URI)
except that in this method, the file or URL must be readable.
Usually, this method is use for reading a file and
is used for writing nameToFile(String, URI)
.
name
- The name of a file or URL.baseDirectory
- The base directory for relative file names,
or null to specify none.classLoader
- The class loader to use to locate system
resources, or null to use the system class loader that was used
to load this class.
java.io.IOException
- If the file cannot be read, or
if the file cannot be represented as a URL (e.g. System.in), or
the name specification cannot be parsed.nameToFile(String, URI)
public static java.io.BufferedReader openForReading(java.lang.String name, java.net.URI base, java.lang.ClassLoader classLoader) throws java.io.IOException
nameToURL(String, URI, ClassLoader)
If the file name is not absolute, the it is assumed to be relative to
the specified base URI.
name
- File name.base
- The base URI for relative references.classLoader
- The class loader to use to locate system
resources, or null to use the system class loader that was used
to load this class.
java.io.IOException
- If the file cannot be opened.nameToURL(String, URI, ClassLoader)
public static java.io.Writer openForWriting(java.lang.String name, java.net.URI base, boolean append) throws java.io.IOException
nameToFile(String, URI)
and create a file writer. If the
file does not exist, then create it. If the file name is not
absolute, the it is assumed to be relative to the specified
base directory. If permitted, this method will return a
Writer that will simply overwrite the contents of the file. It
is up to the user of this method to check whether this is OK
(by first calling nameToFile(String, URI)
and calling
exists() on the returned value).
name
- File name.base
- The base URI for relative references.append
- If true, then append to the file rather than
overwriting.
java.io.IOException
- If the file cannot be opened
or created.private static void _binaryCopyStream(java.io.InputStream inputStream, java.io.File destinationFile) throws java.io.IOException
inputStream
- The input stream.destinationFile
- The destination File.
java.io.IOException
- If the input stream cannot be created
or read, or * if there is a problem writing to the destination
file.private static byte[] _binaryReadStream(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- The input stream.
java.io.IOException
- If the input stream cannot be read.private static java.net.URL _searchClassPath(java.lang.String name, java.lang.ClassLoader classLoader) throws java.io.IOException
name
- The name to be searchedclassLoader
- The class loader to use to locate system
resources, or null to use the system class loader that was used
to load this class.
java.io.IOException
private static java.lang.String _trimClassPath(java.lang.String name)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |