Class PsUtil
- java.lang.Object
-
- jv.object.PsUtil
-
public final class PsUtil extends java.lang.ObjectUtility to locate and query classes and superclasses, open files, bit manipulations.- Author:
- Konrad Polthier
- Version:
- 20.07.02, 1.20 revised (kp) New method getFilePathAndBaseName() implemented.
21.05.01, 1.10 revised (kp) Support for zip files revised.
21.11.98, 1.00 created (kp)
-
-
Constructor Summary
Constructors Constructor and Description PsUtil()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static java.lang.StringassureFileSeparator(java.lang.String dir, boolean bDir)Assure that path name contains and, in case of directories, ends with current file separator.static intclearBits(int flag, int bit)java.lang.StringgetClassName(java.lang.Object obj)Get simple class name without leading package.static java.lang.StringgetFileBaseName(java.lang.String fullFileName)Extract file name without extension and without path information.static java.lang.StringgetFileExtension(java.lang.String fullFileName)Extract base file name and search for characters behind the last '.'.static java.lang.StringgetFileName(java.lang.String fullFileName)Extract file name including extension without path information.static java.lang.StringgetFilePath(java.lang.String fullFileName)Extract full path excluding anything behind the last file separator.static java.lang.StringgetFilePathAndBaseName(java.lang.String fullFileName)Extract full path and file base name excluding file extensions.static java.lang.StringgetSimpleClassName(java.lang.Object obj)Get full qualified class name.static booleanhasAllBits(int flag, int bit)static booleanhasBits(int flag, int bit)static booleanhasSomeBits(int flag, int bit)static booleanisAbsolutePath(java.lang.String dir)Check if directory is a relative or absolute path.static java.lang.ObjectnewInstance(java.lang.Class baseClass, java.lang.String nameSuffix)Find a class and create an instance.static java.lang.ObjectnewInstance(java.lang.String className)Find a class given by name and create an instance.static java.io.DataInputStreamopen_as_DataInputStream(java.lang.String fileName)Open a file either on the local file system or as URL for reading.static java.io.BufferedReaderopen(java.lang.String fileName)Open a file either on the local file system or as URL for reading.static java.io.DataInputStreamopenFile_as_DataInputStream(java.lang.String aFileName)Open a file on the local file system for reading within an application.static java.io.BufferedReaderopenFile(java.lang.String aFileName)Open a file on the local file system for reading within an application.static java.io.DataInputStreamopenURL_as_DataInputStream(java.lang.String aURL)Opens a URL for reading within an applet.static java.io.BufferedReaderopenURL(java.lang.String aURL)Opens a URL for reading within an applet.static intsetBits(int flag, int bit)static java.io.PrintWriterwriteFile(java.lang.String aFileName)Open a file on the local file system for writing from an application.
-
-
-
Method Detail
-
newInstance
public static java.lang.Object newInstance(java.lang.Class baseClass, java.lang.String nameSuffix)Find a class and create an instance. Name of searched class starts with name of baseClass, or one of its super classes, and finishes with string given by nameSuffix.- Parameters:
baseClass- base classnameSuffix- post fix of class- Returns:
- an instance if class is found, else null.
-
newInstance
public static java.lang.Object newInstance(java.lang.String className)
Find a class given by name and create an instance.- Parameters:
className- Name of class- Returns:
- an instance if class is found, else null
-
open
public static java.io.BufferedReader open(java.lang.String fileName)
Open a file either on the local file system or as URL for reading. This version works both within an application and in applets.- Parameters:
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";- Returns:
- an InputStream if open was successfull, other wise
null. - See Also:
openFile(java.lang.String),openURL(java.lang.String)- Author:
- Konrad Polthier
- Version:
- 23.02.14, 1.30 revised (kp) Check for with codebase/instbase too in application mode.
12.02.05, 1.20 revised (kp) Check for https connection too.
06.08.99, 1.10 revised (kp) Return value changed from DataInputStream to to BufferedReader according to Java 1.1 deprecation of readline().
21.09.98, 1.00 created (kp)
-
openFile
public static java.io.BufferedReader openFile(java.lang.String aFileName)
Open a file on the local file system for reading within an application. This version only works within an application and does not work in applets. In applets, usePsUtil.openURL(String).File may be compressed using gz. It should also work with zip but mysteriously does not currently.
- Parameters:
aFileName- String of full file name including directory path, e.g. aFileName = PsConfig.getCodeBase()+"c:/JavaView/src/models/primitive/Octahedron.byu";- Returns:
- a BufferedReader if open was successfull, other wise
null. - See Also:
openURL(java.lang.String)- Author:
- Konrad Polthier
- Version:
- 27.07.03, 1.40 revised (kp) Adding zip.getNextEntry() again which was accidentally removed on 17.11.02.
21.05.01, 1.20 revised (kp) Support for zip files revised.
06.08.99, 1.10 revised (kp) Return value changed from DataInputStream to to BufferedReader according to Java 1.1 deprecation of readline().
00.00.97, 1.00 created (kp)
-
openURL
public static java.io.BufferedReader openURL(java.lang.String aURL)
Opens a URL for reading within an applet. The URL can be generated within an appletgetCodeBase()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.
- Parameters:
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";- Returns:
- a BufferedReader if open was successfull, other wise
null. - See Also:
openFile(java.lang.String)- Author:
- Konrad Polthier
- Version:
- 27.07.03, 1.40 revised (kp) Adding zip.getNextEntry() again which was accidentally removed on 17.11.02.
21.05.01, 1.20 revised (kp) Support for zip files revised.
06.08.99, 1.10 revised (kp) Return value changed from DataInputStream to to BufferedReader according to Java 1.1 deprecation of readline().
00.00.97, 1.00 created (kp)
-
open_as_DataInputStream
public static java.io.DataInputStream open_as_DataInputStream(java.lang.String fileName)
Open a file either on the local file system or as URL for reading. This version works both within an application and in applets.- Parameters:
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";- Returns:
- an InputStream if open was successfull, other wise
null. - See Also:
openFile(java.lang.String),openURL(java.lang.String)- Author:
- Konrad Polthier
- Version:
- 12.02.05, 1.20 revised (kp) Check for https connection too.
06.08.99, 1.10 revised (kp) Return value changed from DataInputStream to to BufferedReader according to Java 1.1 deprecation of readline().
21.09.98, 1.00 created (kp)
-
openFile_as_DataInputStream
public static java.io.DataInputStream openFile_as_DataInputStream(java.lang.String aFileName)
Open a file on the local file system for reading within an application. This version only works within an application and does not work in applets. In applets, usePsUtil.openURL(String).File may be compressed using gz. It should also work with zip but mysteriously does not currently.
- Parameters:
aFileName- String of full file name including directory path, e.g. aFileName = PsConfig.getCodeBase()+"c:/JavaView/src/models/primitive/Octahedron.byu";- Returns:
- a BufferedReader if open was successfull, other wise
null. - See Also:
openURL(java.lang.String)- Author:
- Konrad Polthier
- Version:
- 27.07.03, 1.40 revised (kp) Adding zip.getNextEntry() again which was accidentally removed on 17.11.02.
21.05.01, 1.20 revised (kp) Support for zip files revised.
06.08.99, 1.10 revised (kp) Return value changed from DataInputStream to to BufferedReader according to Java 1.1 deprecation of readline().
00.00.97, 1.00 created (kp)
-
openURL_as_DataInputStream
public static java.io.DataInputStream openURL_as_DataInputStream(java.lang.String aURL)
Opens a URL for reading within an applet. The URL can be generated within an appletgetCodeBase()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.
- Parameters:
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";- Returns:
- a BufferedReader if open was successfull, other wise
null. - See Also:
openFile(java.lang.String)- Author:
- Konrad Polthier
- Version:
- 27.07.03, 1.40 revised (kp) Adding zip.getNextEntry() again which was accidentally removed on 17.11.02.
21.05.01, 1.20 revised (kp) Support for zip files revised.
06.08.99, 1.10 revised (kp) Return value changed from DataInputStream to to BufferedReader according to Java 1.1 deprecation of readline().
00.00.97, 1.00 created (kp)
-
writeFile
public static java.io.PrintWriter writeFile(java.lang.String aFileName)
Open a file on the local file system for writing from an application. This version only works within an application and does not work in applets.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.
- Parameters:
aFileName- String of full file name including directory path, e.g. aFileName = "c:/JavaView/src/models/primitive/Octahedron.byu";- Returns:
- PrintWriter if open was successfull, other wise
null. - Author:
- Konrad Polthier
- Version:
- 20.05.05, 1.30 revised (kp) GZIPOutputStream added.
01.09.03, 1.20 revised (kp) Path information removed from zip entry.
18.08.03, 1.10 revised (kp) Implement Zip output when filename ends with ".zip".
07.02.00, 1.00 created (kp)
-
getFileName
public static java.lang.String getFileName(java.lang.String fullFileName)
Extract file name including extension without path information. Anything behind the last occurrence of '/' or '\' is considered the file name.- Version:
- 24.07.02, 1.50 revised (kp) Look for both kind of separators simultaneously.
-
getFileBaseName
public static java.lang.String getFileBaseName(java.lang.String fullFileName)
Extract file name without extension and without path information. Anything behind the last occurrence of '/' or '\' is considered the file name from which anything including the last '.' is removed as extension.Note, a trailing number section such as *.0017 is considered as part of the file basename, and therefore not removed from the file basename.
- Version:
- 06.10.06, 1.20 revised (kp) Bug removed when no dot in base filename.
08.08.04, 1.10 revised (kp) Trailing number section belongs to base name.
-
getFileExtension
public static java.lang.String getFileExtension(java.lang.String fullFileName)
Extract base file name and search for characters behind the last '.'. Anything behind the last occurrence of '/' or '\' is considered the base name.Note, a trailing number section such as *.0017 is considered as part of the file basename and not returned as filename extension.
- Version:
- 08.08.04, 1.10 revised (kp) Number section before extension belongs to base name.
19.07.02, 1.50 revised (kp) If dot is missing then return empty string.
-
getFilePath
public static java.lang.String getFilePath(java.lang.String fullFileName)
Extract full path excluding anything behind the last file separator. Anything before and including the last occurrence of '/' or '\' is considered as path information.If string contains no separator then string is consist of a fileName only, and an empty string is returned as path.
- Version:
- 11.09.04, 1.60 revised (kp) If string contains no separator then return empty string.
24.07.02, 1.50 revised (kp) Look for both kind of separators simultaneously.
14.12.00, 1.10 revised (kp) Missing slash appended to end of string.
-
getFilePathAndBaseName
public static java.lang.String getFilePathAndBaseName(java.lang.String fullFileName)
Extract full path and file base name excluding file extensions.Note, a trailing number section such as *.0017 is considered as part of the file basename, and therefore not removed from the path+basename.
- Version:
- 08.08.04, 1.10 revised (kp) Number section before extension belongs to base name.
19.07.02, 1.00 created (kp)
-
assureFileSeparator
public 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. Parameter bDir determines if the path name is a directory which must end with a file separator.- Parameters:
dir- directory or file name with path informationbDir- indicate if string is a directory or file- Returns:
- modified directory name
- Since:
- JavaView 3.09.003
- Version:
- 20.02.07, 1.10 revised (kp) Reduce internal conversions of character to string.
15.02.04, 1.00 created (kp)
-
isAbsolutePath
public static boolean isAbsolutePath(java.lang.String dir)
Check if directory is a relative or absolute path.- Returns:
trueif directory is an absolute path or url.- Since:
- JavaView 3.09.003
- Version:
- 12.02.05, 1.20 revised (kp) Check for https connection too.
15.02.04, 1.00 created (kp)
-
getSimpleClassName
public static java.lang.String getSimpleClassName(java.lang.Object obj)
Get full qualified class name.- Since:
- JavaView 5.03.001
- Version:
- 01.04.2020, 1.00 created (kp)
-
getClassName
public java.lang.String getClassName(java.lang.Object obj)
Get simple class name without leading package.- Since:
- JavaView 5.03.001
- Version:
- 01.04.2020, 1.00 created (kp)
-
hasAllBits
public static boolean hasAllBits(int flag, int bit)
-
hasSomeBits
public static boolean hasSomeBits(int flag, int bit)
-
hasBits
public static boolean hasBits(int flag, int bit)
-
setBits
public static int setBits(int flag, int bit)
-
clearBits
public static int clearBits(int flag, int bit)
-
-
"