com.ibm.jzos
Class ZUtil

java.lang.Object
  extended by com.ibm.jzos.ZUtil

public class ZUtil
extends java.lang.Object

This class provides a static interface to various z/OS native library calls, other than I/O.


Field Summary
static int LOG_DEBUG
           
static int LOG_ERR
           
static int LOG_INFO
           
static int LOG_NOTICE
           
static int LOG_TRACE
           
static int LOG_WARN
           
static int SMF_HEADER_PREFIX_LEN
           
 
Method Summary
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 procstepname, 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 getPid()
          Get the process id of the current process.
static int getPPid()
          Get the parent process id of the current process.
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 constructed with the defaultOutputEncoding.
static java.io.PrintStream newEncodedPrintStream(java.io.OutputStream os, boolean autoFlush, java.lang.String encoding)
          Return a PrintStream constructed from the supplied OutputStream and the encoding.
static java.io.PrintStream newEncodedPrintStream(java.io.OutputStream os, boolean autoFlush, java.lang.String encoding, boolean enable)
          Return a PrintStream constructed from the supplied OutputStream and the 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_ERR

public static final int LOG_ERR
See Also:
Constant Field Values

LOG_WARN

public static final int LOG_WARN
See Also:
Constant Field Values

LOG_NOTICE

public static final int LOG_NOTICE
See Also:
Constant Field Values

LOG_INFO

public static final int LOG_INFO
See Also:
Constant Field Values

LOG_DEBUG

public static final int LOG_DEBUG
See Also:
Constant Field Values

LOG_TRACE

public static final int LOG_TRACE
See Also:
Constant Field Values

SMF_HEADER_PREFIX_LEN

public static final int SMF_HEADER_PREFIX_LEN
See Also:
Constant Field Values
Method Detail

getDefaultPlatformEncoding

public static java.lang.String getDefaultPlatformEncoding()
Get the default platform encoding for this instance of the JVM. The encoding is generally some variant of EBCDIC. This property is set by the JZOS launcher to match the default locale encoding for the process.

Returns:
the default output encoding

setDefaultPlatformEncoding

public static void setDefaultPlatformEncoding(java.lang.String encoding)
                                       throws java.io.UnsupportedEncodingException
Set the default output encoding for this instance of the JVM. The encoding is generally some variant of EBCDIC. This property is set by the JZOS launcher to match the default locale encoding for the process. This value should be changed with caution.

Parameters:
encoding - the charset encoding to use as a default
Throws:
java.io.UnsupportedEncodingException - if the encoding is not supported

environ

public static java.lang.String[] environ()
Get an array of strings that represent the environment variables of the current process.

This method reads and returns the values held in the C-library 'environ' global.

Returns:
an array of environment variable strings in name=value format

getEnvironment

public static java.util.Properties getEnvironment()
Return a Properties object containing the current process environment variables.


getEnv

public static java.lang.String getEnv(java.lang.String varName)
Get the value of the Environment variable.

This method calls the getenv() C-library routine.

Parameters:
varName - the name of the environment variable
Returns:
the value of the environment variable. Null if not found.

setEnv

public static void setEnv(java.lang.String varName,
                          java.lang.String varValue)
                   throws ErrnoException
Set an Environment variable.

This method calls the setenv() C-library routine.

Parameters:
varName - the name of the environment variable
varValue - the value of the environment variable
Throws:
ErrnoException - if the native call fails.

getCurrentJobname

public static java.lang.String getCurrentJobname()
Get the current MVS jobname, blanks trimmed

Returns:
the jobname

getCurrentTsoPrefix

public static java.lang.String getCurrentTsoPrefix()
Gets the TSO prefix, if running under TSO.

Returns:
the TSO prefix; null if not running under TSO; an empty string if under TSO with no prefix

getCurrentStepname

public static java.lang.String getCurrentStepname()
Get the current MVS stepname, blanks trimmed. This is the "jobstep name" if running under a proc.

Returns:
the procstepname

getCurrentProcStepname

public static java.lang.String getCurrentProcStepname()
Get the current MVS procstepname, blanks trimmed. This is an empty string if not running in a proc.

Returns:
the procstepname

getCurrentJobId

public static java.lang.String getCurrentJobId()
Get the current MVS jobid, blanks trimmed

Returns:
the jobid (job number)

getCurrentTimeMicros

public static long getCurrentTimeMicros()
Gets the current time, expressed in microseconds since 00:00:00 Coordinated Universal Time (UTC), January 1, 1970

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.

Returns:
a (64-bit) Java long containing the number of microseconds since UTC January 1, 1970. As with gettimeofday(), this returns -1 if the number of seconds has overflowed a 32-bit integer (in 2038)

getCpuTimeMicros

public static long getCpuTimeMicros()
                             throws RcException
Gets the amount of CPU time consumed, expressed in microseconds, for the current thread.

This function calls the clock() C-Library function.

Returns:
a Java long containing the number of microseconds of CPU time consumed by the current thread
Throws:
an - (unchecked) RcException if call fails (not expected)
RcException

getCurrentUser

public static java.lang.String getCurrentUser()
                                       throws RcException
Get the current MVS userid.

This is a convenience method that simply delegates to PlatformThread.getUserName()

Returns:
the current MVS userid
Throws:
RcException
See Also:


getJavaVersionInfo

public static java.lang.String getJavaVersionInfo()
Get a multi-line string that contains information about the version of Java that is currently running. This method is called by the JZOSVM launcher to display the Java version information on the //SYSOUT DD

Returns:
a String in the general form specified by sun.misc.Version.print()

getJzosJarVersion

public static java.lang.String getJzosJarVersion()
Load the build_version.properties class resource and return a string representing the version of the JZOS Java archive.


getJzosDllVersion

public static java.lang.String getJzosDllVersion()
Return a string representing the version of the JZOS shared library.


peekOSMemory

public static long peekOSMemory(long address,
                                int len)
                         throws RcException
Peek (read) a long from OS memory.

Parameters:
address - the address of the OS memory to start peeking from.
len - the number of bytes to read into the returned long, must be <= 8
Throws:
RcException - if there is an error accessing the memory location.
java.lang.IllegalArgumentException - if len > 8
java.lang.SecurityException - if a a SecurityManager is active and the user doesn't have access to JzosPermission("peekOSMemory")

peekOSMemory

public static void peekOSMemory(long address,
                                byte[] bytes)
                         throws RcException
Peek bytes from OS memory.

Parameters:
address - the address of the OS memory to start peeking from.
bytes - the location to store the bytes peeked, for bytes.length
Throws:
RcException - 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")

peekOSMemory

public static void peekOSMemory(long address,
                                byte[] bytes,
                                int offset,
                                int len)
                         throws RcException
Peek bytes from OS memory.

Parameters:
address - the address of the OS memory to start peeking from.
bytes - the location to store the bytes peeked
offset - the 0-based offset into bytes where to store the first byte peeked
len - the number of bytes to copy from memory
Throws:
java.lang.IllegalArgumentException - if offset and len are incompatible with bytes
RcException - 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")

logDiagnostic

public 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.

Parameters:
level - one of the LOG_XXX constants defined above
msg - the message text

redirectStandardStreams

public static void redirectStandardStreams()
                                    throws java.lang.Exception
A convenience method to redirect the standard streams using the default character encoding.

JZOSVM calls this method on startup to cause System.out System.err and System.in to be directed to/from the job stream.

Throws:
java.lang.Exception - if the streams could not be redirected.

redirectStandardStreams

public static boolean redirectStandardStreams(java.lang.String requestedEncoding,
                                              boolean enableTranscoding)
                                       throws java.lang.Exception
A static method which redirects the standard streams as follows:

newEncodedPrintStream

public static java.io.PrintStream newEncodedPrintStream(java.io.OutputStream os,
                                                        boolean autoFlush)
                                                 throws java.io.UnsupportedEncodingException
Construct a PrintStream constructed with the defaultOutputEncoding.

Parameters:
os - the stream to base the PrintStream on.
autoFlush - whether or not to autoFlush.
Returns:
the printStream
Throws:
java.io.UnsupportedEncodingException

newEncodedPrintStream

public static java.io.PrintStream newEncodedPrintStream(java.io.OutputStream os,
                                                        boolean autoFlush,
                                                        java.lang.String encoding)
                                                 throws java.io.UnsupportedEncodingException
Return a PrintStream constructed from the supplied OutputStream and the encoding. We actually answer an instance of a subclass that also translates bytes sent throught its OutputStream interface.

Parameters:
os - the stream to base the PrintStream on.
autoFlush - whether or not to autoFlush
encoding - the charset encoding to use
Returns:
the printStream
Throws:
java.io.UnsupportedEncodingException
See Also:
TranscodingPrintStream

newEncodedPrintStream

public static java.io.PrintStream newEncodedPrintStream(java.io.OutputStream os,
                                                        boolean autoFlush,
                                                        java.lang.String encoding,
                                                        boolean enable)
                                                 throws java.io.UnsupportedEncodingException
Return a PrintStream constructed from the supplied OutputStream and the encoding. We actually answer an instance of a subclass that also translates bytes sent throught its OutputStream interface.

Parameters:
os - the stream to base the PrintStream on.
autoFlush - whether or not to autoFlush
encoding - the charset encoding to use
enable - whether or not to enable the transcoding
Returns:
the printStream
Throws:
java.io.UnsupportedEncodingException
See Also:
TranscodingPrintStream

setLoggingLevel

public static void setLoggingLevel(int level)
Sets the logging level for the Toolkit native code. This method can be used to enable debugging output from the toolkit native library.

Parameters:
level - one of the LOG_XXX constants defined above
See Also:
logDiagnostic(int, String)

getCodePageCurrentLocale

public static java.lang.String getCodePageCurrentLocale()
Native method to retrieve the default locale codepage name used by the toolkit native library. This is the default codepage for the z/OS process based on the LANG environment variable.


getPid

public static int getPid()
Get the process id of the current process.

This method calls the getpid() C-library routine.

Returns:
the process id.

getPPid

public static int getPPid()
Get the parent process id of the current process.

This method calls the getppid() C-library routine.

Returns:
the parent process id.

smfRecord

public static void smfRecord(int type,
                             int subtype,
                             byte[] record)
                      throws ErrnoException
Write a System Management Facility (SMF) record.

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.

Throws:
ErrnoException - on failure. Refer to __smf_record() api documentation for specific errno reason code constants, which are provided as constants in the ErrnoException class.

formatStackTrace

public static java.lang.String formatStackTrace(java.lang.Throwable t)
Print the stacktrace related to the supplied Throwable and return it as a String.