public final class PsUtil
extends java.lang.Object
Constructor and Description |
---|
PsUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
assureFileSeparator(java.lang.String dir,
boolean bDir)
Assure that path name contains and, in case of directories, ends with current file separator.
|
static int |
clearBits(int flag,
int bit) |
static java.lang.String |
getFileBaseName(java.lang.String fullFileName)
Extract file name without extension and without path information.
|
static java.lang.String |
getFileExtension(java.lang.String fullFileName)
Extract base file name and search for characters behind the last '.'.
|
static java.lang.String |
getFileName(java.lang.String fullFileName)
Extract file name including extension without path information.
|
static java.lang.String |
getFilePath(java.lang.String fullFileName)
Extract full path excluding anything behind the last file separator.
|
static java.lang.String |
getFilePathAndBaseName(java.lang.String fullFileName)
Extract full path and file base name excluding file extensions.
|
static boolean |
hasAllBits(int flag,
int bit) |
static boolean |
hasBits(int flag,
int bit) |
static boolean |
hasSomeBits(int flag,
int bit) |
static boolean |
isAbsolutePath(java.lang.String dir)
Check if directory is a relative or absolute path.
|
static java.lang.Object |
newInstance(java.lang.Class baseClass,
java.lang.String nameSuffix)
Find a class and create an instance.
|
static java.lang.Object |
newInstance(java.lang.String className)
Find a class given by name and create an instance.
|
static java.io.BufferedReader |
open(java.lang.String fileName)
Open a file either on the local file system or in the internet for reading within an application.
|
static java.io.BufferedReader |
openFile(java.lang.String aFileName)
Open a file on the local file system for reading within an application.
|
static java.io.BufferedReader |
openURL(java.lang.String aURL)
Opens a URL for reading within an applet.
|
static int |
setBits(int flag,
int bit) |
static java.io.PrintWriter |
writeFile(java.lang.String aFileName)
Open a file on the local file system for writing from an application.
|
public static java.lang.Object newInstance(java.lang.Class baseClass, java.lang.String nameSuffix)
baseClass
- base classnameSuffix
- post fix of classpublic static java.lang.Object newInstance(java.lang.String className)
className
- Name of classpublic static java.io.BufferedReader open(java.lang.String fileName)
fileName
- If application, string of full file name of a geometry file in BYU file format, e.g.
aFileName = "c:/JavaView/src/models/primitive/Octahedron.byu";
or, if applet, a full qualified URL such as
aFileName = "file:/c:/JavaView/src/models/primitive/Octahedron.byu";
aFileName = "http://www.javaview.de/models/primitive/Octahedron.byu";null
.openFile(java.lang.String)
,
openURL(java.lang.String)
public static java.io.BufferedReader openFile(java.lang.String aFileName)
PsUtil.openURL(String)
.
File may be compressed using gz. It should also work with zip but mysteriously does not currently.
aFileName
- String of full file name including directory path, e.g.
aFileName = PsConfig.getCodeBase()+"c:/JavaView/src/models/primitive/Octahedron.byu";null
.openURL(java.lang.String)
public static java.io.PrintWriter writeFile(java.lang.String aFileName)
If filename ends with ".zip" then writer into ZipOutputStream is opened. The zip file contains a single file whose name is the same as the parameter aFileName without the suffix ".zip".
Filename suffix ".gz" will returned a writer based on a GZIPOutputStream.
aFileName
- String of full file name including directory path, e.g.
aFileName = "c:/JavaView/src/models/primitive/Octahedron.byu";null
.public static java.io.BufferedReader openURL(java.lang.String aURL)
getCodeBase()
and the local
position of the file, e.g.
String obj = getCodeBase().toExternalForm(); String fileName = new StringBuffer().append(obj).append("models/byu/brezelMid.byu").toString();If applet runs in a browser the file must be below the code base, otherwise a SecurityException be thrown.
File may be compressed using gz. It should also work with zip but mysteriously does not currently.
aURL
- String of full URL of a geometry file in BYU file format, e.g.
aFileName = "file:/c:/JavaView/src/models/primitive/Octahedron.byu";
aFileName = "http://www-sfb288.math.tu-berlin.de/vgp/models/primitive/Octahedron.byu";null
.openFile(java.lang.String)
public static java.lang.String getFileName(java.lang.String fullFileName)
public static java.lang.String getFileBaseName(java.lang.String fullFileName)
Note, a trailing number section such as *.0017 is considered as part of the file basename, and therefore not removed from the file basename.
public static java.lang.String getFileExtension(java.lang.String fullFileName)
Note, a trailing number section such as *.0017 is considered as part of the file basename and not returned as filename extension.
public static java.lang.String getFilePath(java.lang.String fullFileName)
If string contains no separator then string is consist of a fileName only, and an empty string is returned as path.
public static java.lang.String getFilePathAndBaseName(java.lang.String fullFileName)
Note, a trailing number section such as *.0017 is considered as part of the file basename, and therefore not removed from the path+basename.
public static java.lang.String assureFileSeparator(java.lang.String dir, boolean bDir)
dir
- directory or file name with path informationbDir
- indicate if string is a directory or filepublic static boolean isAbsolutePath(java.lang.String dir)
true
if directory is an absolute path or url.public static boolean hasAllBits(int flag, int bit)
public static boolean hasSomeBits(int flag, int bit)
public static boolean hasBits(int flag, int bit)
public static int setBits(int flag, int bit)
public static int clearBits(int flag, int bit)
"