|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jawk.jrt.JRT
public class JRT
The Jawk runtime coordinator. The JRT services interpreted and compiled Jawk scripts, mainly for IO and other non-CPU bound tasks. The goal is to house service functions into a Java-compiled class rather than to hand-craft service functions in bytecode, or cut-paste compiled JVM code into the compiled AWK script. Also, since these functions are non-CPU bound, the need for inlining is reduced.
Variable access is achieved through the VariableManager interface. The constructor requires a VariableManager instance (which, in this case, is the compiled Jawk class itself).
Main services include:
All static and non-static service methods should be package-private to the resultant AWK script class rather than public. However, the resultant script class is not in the org.jawk.jrt package by default, and the user may reassign the resultant script class to another package. Therefore, all accessed methods are public.
VariableManager
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_RS_REGEX
The default regular expression for RS. |
java.lang.String |
input_line
|
java.util.Map<java.lang.String,java.io.PrintStream> |
output_files
|
PartitioningReader |
pr
|
Constructor Summary | |
---|---|
JRT(VariableManager vm)
Create a JRT with a VariableManager |
Method Summary | |
---|---|
void |
applyRS(java.lang.Object rs_obj)
|
static void |
assignEnvironmentVariables(AssocArray aa)
Called by AVM/compiled modules to assign local environment variables to an associative array (in this case, to ENVIRON). |
void |
assignInitialVariables(java.util.Map<java.lang.String,java.lang.Object> initial_var_map)
Assign all -v variables. |
static boolean |
compare2(java.lang.Object o1,
java.lang.Object o2,
int mode)
Compares two objects. |
static java.lang.Object |
dec(java.lang.Object o)
Return an object which is numerically equivalent to one minus a given object. |
static java.lang.Object |
inc(java.lang.Object o)
Return an object which is numerically equivalent to one plus a given object. |
java.lang.Integer |
jrtClose(java.lang.String filename)
Attempt to close an open stream, whether it is an input file, output file, input process, or output process. |
void |
jrtCloseAll()
|
boolean |
jrtConsumeCommandInput(java.lang.String cmd)
|
java.lang.Integer |
jrtConsumeCommandInputForGetline(java.lang.String cmd_string)
Retrieve the next line of output from a command, executing the command if necessary and store it to $0. |
boolean |
jrtConsumeFileInput(java.lang.String filename)
|
java.lang.Integer |
jrtConsumeFileInputForGetline(java.lang.String filename)
|
boolean |
jrtConsumeInput(boolean for_getline)
Attempt to consume one line of input, either from stdin or from filenames passed in to ARGC/ARGV via the command-line. |
java.lang.Object |
jrtGetInputField(int fieldnum)
|
java.lang.Object |
jrtGetInputField(java.lang.Object fieldnum_obj)
Retrieve the contents of a particular input field. |
java.lang.String |
jrtGetInputString()
Retrieve $0. |
java.io.PrintStream |
jrtGetPrintStream(java.lang.String filename,
boolean append)
Retrieve the PrintStream which writes to a particular file, creating the PrintStream if necessary. |
void |
jrtParseFields()
Splits $0 into $1, $2, etc. |
java.lang.String |
jrtSetInputField(java.lang.Object value_obj,
int field_num)
Stores value_obj into an input field. |
java.io.PrintStream |
jrtSpawnForOutput(java.lang.String cmd)
Retrieve the PrintStream which shuttles data to stdin for a process, executing the process if necessary. |
static java.lang.Integer |
jrtSystem(java.lang.String cmd)
Executes the command specified by cmd and waits for termination, returning an Integer object containing the return code. |
static java.util.Random |
newRandom(int seed)
|
static void |
printfFunction(java.lang.Object[] arr,
java.lang.String fmt_arg)
Applies a format string to a set of parameters and prints the result to stdout. |
static void |
printfFunction(java.io.PrintStream ps,
java.lang.Object[] arr,
java.lang.String fmt_arg)
Applies a format string to a set of parameters and prints the result to a PrintStream. |
static void |
printfFunctionNoCatch(java.lang.Object[] arr,
java.lang.String fmt_arg)
|
static void |
printfFunctionNoCatch(java.io.PrintStream ps,
java.lang.Object[] arr,
java.lang.String fmt_arg)
|
static java.lang.Integer |
replaceAll(java.lang.Object orig_value_obj,
java.lang.Object repl_obj,
java.lang.Object ere_obj,
java.lang.StringBuffer sb,
java.lang.String convfmt)
|
static java.lang.Integer |
replaceFirst(java.lang.Object orig_value_obj,
java.lang.Object repl_obj,
java.lang.Object ere_obj,
java.lang.StringBuffer sb,
java.lang.String convfmt)
|
static int |
split(java.lang.Object fs,
java.lang.Object array,
java.lang.Object string,
java.lang.String convfmt)
Splits the string into parts separated the regular expression fs. |
static int |
split(java.lang.Object array,
java.lang.Object string,
java.lang.String convfmt)
Splits the string into parts separated by one or more spaces; blank first and last fields are eliminated. |
static java.lang.String |
sprintfFunction(java.lang.Object[] arr,
java.lang.String fmt_arg)
Applies a format string to a set of parameters and returns the formatted result. |
static java.lang.String |
sprintfFunctionNoCatch(java.lang.Object[] arr,
java.lang.String fmt_arg)
|
static java.lang.String |
substr(java.lang.Object size_obj,
java.lang.Object startpos_obj,
java.lang.String str)
|
static java.lang.String |
substr(java.lang.Object startpos_obj,
java.lang.String str)
|
static int |
timeSeed()
|
static java.lang.String |
toAwkString(java.lang.Object o,
java.lang.String convfmt)
Convert Strings, Integers, and Doubles to Strings based on the CONVFMT variable contents. |
static java.lang.String |
toAwkStringForOutput(java.lang.Object o,
java.lang.String ofmt)
Convert a String, Integer, or Double to String based on the OFMT variable contents. |
boolean |
toBoolean(java.lang.Object o)
Converts an Integer, Double, String, Pattern, or PatternPair to a boolean. |
static double |
toDouble(java.lang.Object o)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_RS_REGEX
public PartitioningReader pr
public java.lang.String input_line
public java.util.Map<java.lang.String,java.io.PrintStream> output_files
Constructor Detail |
---|
public JRT(VariableManager vm)
vm
- The VariableManager to use with this JRT.Method Detail |
---|
public final void assignInitialVariables(java.util.Map<java.lang.String,java.lang.Object> initial_var_map)
initial_var_map
- A map containing all initial variable
names and their values.public static final void assignEnvironmentVariables(AssocArray aa)
aa
- The associatve array to populate with
environment variables. The module asserts that
the associative array is empty prior to population.public static final java.lang.String toAwkString(java.lang.Object o, java.lang.String convfmt)
o
- Object to convert.convfmt
- The contents of the CONVFMT variable.
public static final java.lang.String toAwkStringForOutput(java.lang.Object o, java.lang.String ofmt)
o
- Object to convert.ofmt
- The contents of the OFMT variable.
public static final double toDouble(java.lang.Object o)
public static final boolean compare2(java.lang.Object o1, java.lang.Object o2, int mode)
o1
- The 1st object.o2
- the 2nd object.mode
- public static java.lang.Object inc(java.lang.Object o)
o
- The object to increase.
public static java.lang.Object dec(java.lang.Object o)
o
- The object to increase.
public final boolean toBoolean(java.lang.Object o)
o
- The object to convert to a boolean.
PatternPair
public static final int split(java.lang.Object array, java.lang.Object string, java.lang.String convfmt)
array
- The array to populate.string
- The string to split.convfmt
- Contents of the CONVFMT variable.
public static final int split(java.lang.Object fs, java.lang.Object array, java.lang.Object string, java.lang.String convfmt)
If fs is blank, it behaves similar to the 2-arg version of AWK's split function.
fs
- Field separator regular expression.array
- The array to populate.string
- The string to split.convfmt
- Contents of the CONVFMT variable.
public boolean jrtConsumeInput(boolean for_getline) throws java.io.IOException
for_getline
- true if call is for getline, false otherwise.
java.io.IOException
- upon an IO error.public void jrtParseFields()
public java.lang.Object jrtGetInputField(java.lang.Object fieldnum_obj)
fieldnum_obj
- Object refering to the field number.
public java.lang.Object jrtGetInputField(int fieldnum)
public java.lang.String jrtSetInputField(java.lang.Object value_obj, int field_num)
value_obj
- The RHS of the assignment.field_num
- Object refering to the field number.
public java.lang.Integer jrtConsumeFileInputForGetline(java.lang.String filename)
public java.lang.Integer jrtConsumeCommandInputForGetline(java.lang.String cmd_string)
cmd_string
- The command to execute.
public java.lang.String jrtGetInputString()
public final java.io.PrintStream jrtGetPrintStream(java.lang.String filename, boolean append)
filename
- The file which to write the contents of the PrintStream.append
- true to append to the file, false to overwrite the file.public boolean jrtConsumeFileInput(java.lang.String filename) throws java.io.IOException
java.io.IOException
public boolean jrtConsumeCommandInput(java.lang.String cmd) throws java.io.IOException
java.io.IOException
public java.io.PrintStream jrtSpawnForOutput(java.lang.String cmd)
cmd
- The command to execute.
public java.lang.Integer jrtClose(java.lang.String filename)
The specification did not describe AWK behavior when attempting to close streams/processes with the same file/command name. In this case, all open streams with this name are closed.
filename
- The filename/command process to close.
public void jrtCloseAll()
public static java.lang.Integer jrtSystem(java.lang.String cmd)
cmd
- The command to execute.
public static java.lang.String sprintfFunction(java.lang.Object[] arr, java.lang.String fmt_arg)
arr
- Arguments to format.fmt_arg
- The format string to apply.
sprintfFunctionNoCatch(Object[],String)
public static void printfFunction(java.lang.Object[] arr, java.lang.String fmt_arg)
String.format() is used to perform the formatting. Thus, an IllegalFormatException can be thrown. If so, a blank string ("") is printed.System.out.print(sprintfFunction(arr, fmt_arg));
arr
- Arguments to format.fmt_arg
- The format string to apply.printfFunctionNoCatch(Object[],String)
public static void printfFunction(java.io.PrintStream ps, java.lang.Object[] arr, java.lang.String fmt_arg)
String.format() is used to perform the formatting. Thus, an IllegalFormatException can be thrown. If so, a blank string ("") is printed.ps.print(sprintfFunction(arr, fmt_arg));
ps
- The PrintStream to use for printing.arr
- Arguments to format.fmt_arg
- The format string to apply.printfFunctionNoCatch(PrintStream,Object[],String)
public static java.lang.String sprintfFunctionNoCatch(java.lang.Object[] arr, java.lang.String fmt_arg) throws java.util.IllegalFormatException
java.util.IllegalFormatException
public static void printfFunctionNoCatch(java.lang.Object[] arr, java.lang.String fmt_arg)
public static void printfFunctionNoCatch(java.io.PrintStream ps, java.lang.Object[] arr, java.lang.String fmt_arg)
public static java.lang.Integer replaceFirst(java.lang.Object orig_value_obj, java.lang.Object repl_obj, java.lang.Object ere_obj, java.lang.StringBuffer sb, java.lang.String convfmt)
public static java.lang.Integer replaceAll(java.lang.Object orig_value_obj, java.lang.Object repl_obj, java.lang.Object ere_obj, java.lang.StringBuffer sb, java.lang.String convfmt)
public static java.lang.String substr(java.lang.Object startpos_obj, java.lang.String str)
public static java.lang.String substr(java.lang.Object size_obj, java.lang.Object startpos_obj, java.lang.String str)
public static final int timeSeed()
public static java.util.Random newRandom(int seed)
public void applyRS(java.lang.Object rs_obj)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |