public class OsUtils extends Object
Modifier and Type | Field and Description |
---|---|
static char[] |
fileSeparators
All known file-separator characters.
|
static String |
ORA_EXTENSION
Oracle initialization files extension.
|
static String |
OS_AIX
The name of the AIX operating system: "AIX".
|
static String |
OS_SOLARIS
The name of the Solaris operating system: "Solaris".
|
static String |
OS_SUNOS
The name of the SunOS operating system: "SunOS".
|
static String |
OS_WINDOWS_2000
The name of the Windows 2000 operating system: "Windows 2000".
|
static String |
OS_WINDOWS_95
The name of the Windows 95 operating system: "Windows 95".
|
static String |
OS_WINDOWS_98
The name of the Windows 98 operating system: "Windows 98".
|
static String |
OS_WINDOWS_NT
The name of the Windows NT operating system: "Windows NT".
|
static String |
OS_WINDOWS_XP
The name of the Windows XP operating system: "Windows XP".
|
Constructor and Description |
---|
OsUtils()
Creates a new OsUtils.
|
Modifier and Type | Method and Description |
---|---|
void |
appendFile(String outfile,
String infile)
Appends
infile to outfile . |
boolean |
backupFile(String filename)
Backup a file: copy it to a new file with a numbered 3-character
extension (between 0 and 999).
|
static boolean |
chkTmpPermission()
Checks the permission of the system-defaulted temp folder, specified
by the system property java.io.tmpdir by creating a temp file using
the java API File.createTempFile.
|
static void |
copyFile(String source,
String dest)
Copies a file.
|
static void |
copyStream(InputStream source,
OutputStream dest)
Copies a stream.
|
static void |
copyStream(Reader source,
Writer dest)
Copies a character-based stream.
|
static boolean |
deleteFile(String filename)
Deletes a file or an empty directory.
|
static String |
getFilenameWithCorrectFileSeparators(String filename)
Converts any known file-separator characters in the given String
to this operating system's file-separator character.
|
static String |
getFilenameWithCorrectFileSeparators(String filename,
char separator)
Converts any known file-separator characters in the given String
to the given file-separator character.
|
String |
getLocalHostName()
Returns this machine's DNS hostname.
|
int |
getTimeZoneOffset()
Returns the number of milliseconds to add to GMT to convert to this
machine's timezone, correcting for daylight savings time.
|
static boolean |
isOsAix()
Returns true if the operating system is AIX.
|
static boolean |
isOsSolaris28()
Returns true if the operating system is Solaris 2.8 which also
includes SunOS 5.8 on which Solaris 2.8 is built
Checks the System property "os.name" and "os.version",
returns true if it is equal to:
Solaris or SunOS 2.8 or 5.8 respectively.
|
static boolean |
isOsWindowsFamily()
Returns true if the operating system is within the "Windows family".
|
static void |
moveFile(String source,
String dest)
Moves a file.
|
static void |
runPgm(String[] cmdarray)
Executes a program external to the Java VM.
|
static void |
runPgm(String[] cmdarray,
String inputFile)
Executes a program external to the Java VM, passing an InputStream to
the program from the file named
inputFile . |
static Process |
runPgmAsync(String[] cmdarray)
Asynchronously executes a Process external to the Java VM.
|
static Process |
runPgmAsync(String[] cmdarray,
String inputFile)
Asynchronously executes a Process external to the Java VM, passing an
InputStream to the program from the file named
inputFile . |
static String |
squeezeOut(String from,
char toss)
Removes all occurances of a character from a String.
|
public static final String OS_WINDOWS_NT
public static final String OS_WINDOWS_95
public static final String OS_WINDOWS_98
public static final String OS_WINDOWS_2000
public static final String OS_WINDOWS_XP
public static final String OS_SOLARIS
public static final String OS_SUNOS
public static final String OS_AIX
public static final char[] fileSeparators
public static final String ORA_EXTENSION
public static boolean isOsWindowsFamily()
public static boolean isOsSolaris28()
public static boolean isOsAix()
public void appendFile(String outfile, String infile) throws IOException
infile
to outfile
.outfile
- the name of the file to append to.infile
- the name of the file which will be appended.IOException
public boolean backupFile(String filename)
filename
- the name of the file to backup.public static boolean deleteFile(String filename)
filename
- the name of the file to delete.public static void runPgm(String[] cmdarray) throws IOException
cmdarray
- the name of the program to execute, with arguments.IOException
- if an error occurs when executing the Process.IllegalArgumentException
- if cmdarray
has no elements.NullPointerException
- if cmdarray
is null.public static void runPgm(String[] cmdarray, String inputFile) throws IOException
inputFile
.
cmdarray
- the name of the program to execute, with arguments.inputFile
- the name of the file to use as an InputStream.IOException
- if an error occurs when executing the Process.IllegalArgumentException
- if cmdarray
has no elements.NullPointerException
- if cmdarray
is null.public static Process runPgmAsync(String[] cmdarray) throws IOException
cmdarray
- the name of the program to execute, with arguments.IOException
- if an error occurs when executing the Process.IllegalArgumentException
- if cmdarray
has no elements.NullPointerException
- if cmdarray
is null.public static Process runPgmAsync(String[] cmdarray, String inputFile) throws IOException
inputFile
.cmdarray
- the name of the program to execute, with arguments.inputFile
- the name of the file to use as an InputStream.IOException
- if an error occurs when executing the Process.IllegalArgumentException
- if cmdarray
has no elements.NullPointerException
- if cmdarray
is null.public static void moveFile(String source, String dest) throws FileNotFoundException, IOException
source
- the name of the file to move.dest
- where to move the file to.FileNotFoundException
- if the source file cannot be found.IOException
- if an error occurs during copying.CommonException
- if some other error occurs.public static void copyFile(String source, String dest) throws FileNotFoundException, IOException
source
- the name of the file to copy.dest
- the name of the copied file.FileNotFoundException
- if the source file cannot be found.IOException
- if an error occurs during copying.public static void copyStream(InputStream source, OutputStream dest) throws IOException
source
- the source stream.dest
- the destination stream.IOException
- if an error occurs during copying.public static void copyStream(Reader source, Writer dest) throws IOException
source
- the source Reader.dest
- the destination Writer.IOException
- if an error occurs during copying.public String getLocalHostName() throws UnknownHostException
UnknownHostException
- if this machine does not have
a hostname.public int getTimeZoneOffset()
public static String getFilenameWithCorrectFileSeparators(String filename)
"e:/myDir\dirA/dirB"
"e:" + fs + "myDir" + fs + "dirA" + fs + "dirB"
filename
- the filename String to convertpublic static String getFilenameWithCorrectFileSeparators(String filename, char separator)
"e:/myDir\dirA/dirB"
"e:" + fs + "myDir" + fs + "dirA" + fs + "dirB"
separator
.filename
- the filename String to convertseparator
- the file-separator character to insert in place of
every known file-separator character in the orginal
filename (i.e., specify ':' for Macintosh file strings).public static String squeezeOut(String from, char toss)
from
- the String from which to remove the character.toss
- the character to remove from the String.from
without the character toss
.public static boolean chkTmpPermission()
Copyright © 2023. All rights reserved.