public class ZUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
JZOS_MERGE_SYSOUT_PROPERTY
Property name used by batch launcher to cause stderr/stdout to be merged
to DD:SYSOUT
|
static int |
LOG_DEBUG
Debug level logging @see
setLoggingLevel(int) |
static int |
LOG_ERR
Error level logging @see
setLoggingLevel(int) |
static int |
LOG_INFO
Informational level logging @see
setLoggingLevel(int) |
static int |
LOG_NOTICE
Notice level logging @see
setLoggingLevel(int) |
static int |
LOG_TRACE
Trace level logging @see
setLoggingLevel(int) |
static int |
LOG_WARN
Warning level logging @see
setLoggingLevel(int) |
static int |
SMF_HEADER_PREFIX_LEN
The length of an SMF header prefix
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
environ()
Get an array of strings that represent the environment variables of the current
process.
|
static java.lang.String |
formatStackTrace(java.lang.Throwable t)
Print the stacktrace related to the supplied Throwable and
return it as a String.
|
static java.lang.String |
getCodePageCurrentLocale()
Native method to retrieve the default locale codepage name used by the toolkit
native library.
|
static long |
getCpuTimeMicros()
Gets the amount of CPU time consumed, expressed in microseconds,
for the current thread.
|
static java.lang.String |
getCurrentJobId()
Get the current MVS jobid, blanks trimmed
|
static java.lang.String |
getCurrentJobname()
Get the current MVS jobname, blanks trimmed
|
static java.lang.String |
getCurrentProcStepname()
Get the current MVS proc stepname, blanks trimmed.
|
static java.lang.String |
getCurrentStepname()
Get the current MVS stepname, blanks trimmed.
|
static long |
getCurrentTimeMicros()
Gets the current time, expressed in microseconds since
00:00:00 Coordinated Universal Time (UTC), January 1, 1970
|
static java.lang.String |
getCurrentTsoPrefix()
Gets the TSO prefix, if running under TSO.
|
static java.lang.String |
getCurrentUser()
Get the current MVS userid.
|
static java.lang.String |
getDefaultPlatformEncoding()
Get the default platform encoding for this instance of the JVM.
|
static java.lang.String |
getEnv(java.lang.String varName)
Get the value of the Environment variable.
|
static java.util.Properties |
getEnvironment()
Return a Properties object containing the current process environment variables.
|
static java.lang.String |
getJavaVersionInfo()
Get a multi-line string that contains information about the version
of Java that is currently running.
|
static java.lang.String |
getJzosDllVersion()
Return a string representing the version of the JZOS shared library.
|
static java.lang.String |
getJzosJarVersion()
Load the build_version.properties class resource and return
a string representing the version of the JZOS Java archive.
|
static int |
getLoggingLevel()
Answer the current logging level for the Toolkit native code.
|
static int |
getPid()
Get the process id of the current process.
|
static int |
getPPid()
Get the parent process id of the current process.
|
static byte[] |
getTodClock()
A JNI wrapper for the z/architecture STORE CLOCK (STCK) instruction
Refer to
SA22-7832 z/Architecture Principles of Operationsfor more information. |
static void |
getTodClock(byte[] buffer)
A JNI wrapper for the z/architecture STORE CLOCK (STCK) instruction
Refer to
SA22-7832 z/Architecture Principles of Operationsfor more information. |
static byte[] |
getTodClockExtended()
A JNI wrapper for the z/architecture STORE CLOCK EXTENDED (STCKE) instruction
Refer to
SA22-7832 z/Architecture Principles of Operationsfor more information. |
static void |
getTodClockExtended(byte[] buffer)
A JNI wrapper for the z/architecture STORE CLOCK EXTENDED (STCKE) instruction
Refer to
SA22-7832 z/Architecture Principles of Operationsfor more information. |
static void |
logDiagnostic(int level,
java.lang.String msg)
Send a message to the JZOS toolkit's log, which goes to the Language Environment
messages file, which is usually stderr or DD SYSOUT.
|
static java.io.PrintStream |
newEncodedPrintStream(java.io.OutputStream os,
boolean autoFlush)
Construct a PrintStream which is configured to transcode from the current Java
file encoding to the current default platform encoding.
|
static java.io.PrintStream |
newEncodedPrintStream(java.io.OutputStream os,
boolean autoFlush,
java.lang.String encoding)
Construct a PrintStream which is configured to transcode from the current Java
file encoding to the given encoding
|
static java.io.PrintStream |
newEncodedPrintStream(java.io.OutputStream os,
boolean autoFlush,
java.lang.String encoding,
boolean enable)
Construct a PrintStream which which can be used to transcode characters and bytes from the current Java
file encoding to the given encoding
|
static void |
peekOSMemory(long address,
byte[] bytes)
Peek bytes from OS memory.
|
static void |
peekOSMemory(long address,
byte[] bytes,
int offset,
int len)
Peek bytes from OS memory.
|
static long |
peekOSMemory(long address,
int len)
Peek (read) a long from OS memory.
|
static void |
redirectStandardStreams()
A convenience method to redirect the standard streams using the
default character encoding.
|
static boolean |
redirectStandardStreams(java.lang.String requestedEncoding,
boolean enableTranscoding)
A static method which redirects the standard streams as follows:
System.out is redirected to DD:STDOUT (required)
System.err is redirected to DD:STDERR (required)
System.in is redirected from DD:STDIN (optional)
This method is invoked by the JZOSVM launcher to redirect the standard Java
streams to MVS DDs.
|
static void |
setDefaultPlatformEncoding(java.lang.String encoding)
Set the default output encoding for this instance of the JVM.
|
static void |
setEnv(java.lang.String varName,
java.lang.String varValue)
Set an Environment variable.
|
static void |
setLoggingLevel(int level)
Sets the logging level for the Toolkit native code.
|
static void |
smfRecord(int type,
int subtype,
byte[] record)
Write a System Management Facility (SMF) record.
|
static java.lang.String |
substituteSystemSymbols(java.lang.String pattern)
Substitute text for MVS system symbols.
|
static java.lang.String |
substituteSystemSymbols(java.lang.String pattern,
boolean warn)
Substitute text for MVS system symbols.
|
static void |
touch() |
public static final int LOG_ERR
setLoggingLevel(int)
public static final int LOG_WARN
setLoggingLevel(int)
public static final int LOG_NOTICE
setLoggingLevel(int)
public static final int LOG_INFO
setLoggingLevel(int)
public static final int LOG_DEBUG
setLoggingLevel(int)
public static final int LOG_TRACE
setLoggingLevel(int)
public static final int SMF_HEADER_PREFIX_LEN
public static final java.lang.String JZOS_MERGE_SYSOUT_PROPERTY
public static java.lang.String getDefaultPlatformEncoding()
public static void setDefaultPlatformEncoding(java.lang.String encoding) throws java.io.UnsupportedEncodingException
encoding
- the charset encoding to use as a defaultjava.io.UnsupportedEncodingException
- if the encoding is not supportedpublic static java.lang.String[] environ()
This method reads and returns the values held in the C-library 'environ' global.
public static java.util.Properties getEnvironment()
public static java.lang.String getEnv(java.lang.String varName)
This method calls the getenv() C-library routine.
varName
- the name of the environment variablepublic static void setEnv(java.lang.String varName, java.lang.String varValue) throws ErrnoException
This method calls the setenv() C-library routine.
varName
- the name of the environment variablevarValue
- the value of the environment variableErrnoException
- if the native call fails.public static java.lang.String getCurrentJobname()
public static java.lang.String getCurrentTsoPrefix()
public static java.lang.String getCurrentStepname()
public static java.lang.String getCurrentProcStepname()
public static java.lang.String getCurrentJobId()
public static long getCurrentTimeMicros()
This function uses the gettimeofday() C library function, which returns two 32-bit numbers containing the seconds since 1/1/1970, and the fractional microseconds.
public static long getCpuTimeMicros() throws RcException
This function calls the TIMEUSED ECT=COND system macro.
an
- (unchecked) RcException if call fails (not expected)RcException
public static java.lang.String getCurrentUser() throws RcException
This is a convenience method that simply delegates to PlatformThread.getUserName()
RcException
public static java.lang.String getJavaVersionInfo()
public static java.lang.String getJzosJarVersion()
public static java.lang.String getJzosDllVersion()
public static long peekOSMemory(long address, int len) throws RcException
address
- the address of the OS memory to start peeking from.len
- the number of bytes to read into the returned long, must be <= 8RcException
- if there is an error accessing the memory location.java.lang.IllegalArgumentException
- if len > 8 or len <=0java.lang.SecurityException
- if a a SecurityManager is active and the user doesn't have access to JzosPermission("peekOSMemory")public static void peekOSMemory(long address, byte[] bytes) throws RcException
address
- the address of the OS memory to start peeking from.bytes
- the location to store the bytes peeked, for bytes.lengthRcException
- if there is an error accessing the memory location.java.lang.SecurityException
- if a a SecurityManager is active and the user doesn't have access to JzosPermission("peekOSMemory")public static void peekOSMemory(long address, byte[] bytes, int offset, int len) throws RcException
address
- the address of the OS memory to start peeking from.bytes
- the location to store the bytes peekedoffset
- the 0-based offset into bytes where to store the first byte peekedlen
- the number of bytes to copy from memoryjava.lang.IllegalArgumentException
- if offset and len are incompatible with bytesRcException
- if there is an error accessing the memory location.java.lang.SecurityException
- if a a SecurityManager is active and the user doesn't have access to JzosPermission("peekOSMemory")public static void logDiagnostic(int level, java.lang.String msg)
level
- one of the LOG_XXX constants. If an invalid value is supplied,
the message is ignored.msg
- the message textpublic static void redirectStandardStreams() throws java.lang.Exception
JZOSVM calls this method on startup to cause System.out System.err and System.in to be directed to/from the job stream.
This facility may only be used to redirect standard streams once, and is not intended to be used from customer code.
java.lang.Exception
- if the streams could not be redirected.public static boolean redirectStandardStreams(java.lang.String requestedEncoding, boolean enableTranscoding) throws java.lang.Exception
This facility may only be used to redirect standard streams once, and is not intended to be used from customer code.
If the system property jzos.merge.sysout is set to true, System.out and System.err are redirected to DD:SYSOUT rather than DD:STDOUT and DD:STDERR respectively.
requestedEncoding
- the requested character encoding. If this encoding
is not supported, defaultPlatformEncoding is used.true
if the requestedEncoding was used,
false
if the default was used.java.lang.Exception
- if the streams could not be redirected.public static java.io.PrintStream newEncodedPrintStream(java.io.OutputStream os, boolean autoFlush) throws java.io.UnsupportedEncodingException
The current Java file encoding can be obtained from the "file.encoding" System property.
os
- the stream to base the PrintStream on.autoFlush
- whether or not to autoFlush.java.io.UnsupportedEncodingException
getDefaultPlatformEncoding()
public static java.io.PrintStream newEncodedPrintStream(java.io.OutputStream os, boolean autoFlush, java.lang.String encoding) throws java.io.UnsupportedEncodingException
The current Java file encoding can be obtained from the "file.encoding" System property.
os
- the stream to base the PrintStream on.autoFlush
- whether or not to autoFlushencoding
- the target charset encoding to usejava.io.UnsupportedEncodingException
TranscodingPrintStream
public static java.io.PrintStream newEncodedPrintStream(java.io.OutputStream os, boolean autoFlush, java.lang.String encoding, boolean enable) throws java.io.UnsupportedEncodingException
The current Java file encoding can be obtained from the "file.encoding" System property.
os
- the stream to base the PrintStream on.autoFlush
- whether or not to autoFlushencoding
- the charset encoding to useenable
- if false, transcoding is disabledjava.io.UnsupportedEncodingException
TranscodingPrintStream
public static int getLoggingLevel()
setLoggingLevel(int)
public static void setLoggingLevel(int level)
In order of decreasing severity, the logging levels are:
Alternatively, a system property can be used to set the toolkit logging level. This property has the form: -Djzos.logging={E|W|N|I|D|T}
level
- one of the LOG_XXX constants. If an invalid level is given
it is ignored, but a warning is logged.logDiagnostic(int, String)
public static java.lang.String getCodePageCurrentLocale()
public static int getPid()
This method calls the getpid() C-library routine.
public static int getPPid()
This method calls the getppid() C-library routine.
public static byte[] getTodClock()
SA22-7832 z/Architecture Principles of Operationsfor more information.
RcException
- if the STCK instruction returns a CC != 0 (should not happen)public static void getTodClock(byte[] buffer)
SA22-7832 z/Architecture Principles of Operationsfor more information.
buffer
- a byte array a least 8 bytes long to receive the TOD clock valueRcException
- if the STCK instruction returns a CC != 0 (should not happen)java.lang.IllegalArgumentException
- if the given buffer is not at least 8 bytes in lengthpublic static byte[] getTodClockExtended()
SA22-7832 z/Architecture Principles of Operationsfor more information.
RcException
- if the STCKE instruction returns a CC != 0 (should not happen)public static void getTodClockExtended(byte[] buffer)
SA22-7832 z/Architecture Principles of Operationsfor more information.
buffer
- a byte array a least 16 bytes long to receive the extended TOD clock valueRcException
- if the STCKE instruction returns a CC != 0 (should not happen)java.lang.IllegalArgumentException
- if the given buffer is not at least 16 bytes in lengthpublic static void smfRecord(int type, int subtype, byte[] record) throws ErrnoException
This method calls the __smf_record() C-library routine.
The first 24 bytes of the given record are reserved for the Standard SMF
Record Header with Subtypes
, as described in the manual: MVS Systems
Management Facilities (SMF)
.
Before writing the record, this API will overwrite the 24 byte SMF header area, filling in all header fields, including the current date/time and the system id (SID). If the SUBSYS starts with a blank or null(zero), then it is also filled in with either "JES2", "JES3", "TSO", or "STC" as appropriate. If the SUBSYS field starts with a character other than blank or null, then it is unchanged.
Note: The "TZ" environment variable must be properly set to the
correct timezone in order for the date/time in the SMF header to
reflect the current local time.
ErrnoException
- on failure.
Refer to __smf_record() api documentation for specific errno reason code constants,
which are provided as constants in the ErrnoException class.public static java.lang.String substituteSystemSymbols(java.lang.String pattern, boolean warn) throws RcException
This method calls the ASASYMBM Assembler service. For more information, see
MVS Programming: Assembler Services Reference, Volume 1
(SA22-7606).
User symbol tables are not supported by this API.
pattern
- a string containing MVS system symbol(s) to be substituted. MVS system
symbols have the form &SYMBOL.
, or &SYMBOL(n:m).
(if a substring
of the resulting text is requested). In this case, n
is the start index of
the resulting text and m
is the number of characters to substitute. For
more information on how symbol substrings are specified, see the MVS Initialization and Tuning Reference(SA22-7592)
warn
- if true will force ASASYMBM to check for symbol substitution warnings.
See the notes under RcException for details. If false, symbol substitution warnings
are ignored.RcException
- if an error occurs with one of the following return codes:
public static java.lang.String substituteSystemSymbols(java.lang.String pattern) throws RcException
substituteSystemSymbols(String, boolean)
with warn=false.
RcException
public static void touch()
public static java.lang.String formatStackTrace(java.lang.Throwable t)