Package com.stata.sfi
Class SFIToolkit
java.lang.Object
com.stata.sfi.SFIToolkit
This class provides a set of core tools for interacting with Stata.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
callGC()
Call the Java garbage collector. Calling this method should generally be avoided.static void
Display an object in the Stata Results window.static void
Display an object in the Stata Results window.static void
display
(Object o, DisplayMode mode) Display an object in the Stata Results window.static void
display
(Object o, DisplayMode mode, boolean asis) Display an object in the Stata Results window.static void
Display a string in the Stata Results window.static void
Display a string in the Stata Results window.static void
display
(String s, DisplayMode mode) Display a string in the Stata Results window.static void
display
(String s, DisplayMode mode, boolean asis) Display a string in the Stata Results window.static void
Send a line separator to the output.static void
Display an object in the Stata Results window and automatically add a line separator at the end.static void
Display an object in the Stata Results window and automatically add a line separator at the end.static void
displayln
(Object o, DisplayMode mode) Display an object in the Stata Results window and automatically add a line separator at the end.static void
displayln
(Object o, DisplayMode mode, boolean asis) Display an object in the Stata Results window and automatically add a line separator at the end.static void
Display a string in the Stata Results window and automatically add a line separator at the end.static void
displayln
(String s, DisplayMode mode) Display a string in the Stata Results window and automatically add a line separator at the end.static void
displayln
(String s, DisplayMode mode, boolean asis) Display a string in the Stata Results window and automatically add a line separator at the end.static void
Display an object in the Stata Results window as an error.static void
Display an object in the Stata Results window as an error.static void
Display a string in the Stata Results window as an error.static void
Display a string in the Stata Results window as an error.static boolean
errorDebug
(String s) Display a string in the Stata Results window as an error if set debug on is enabled.static boolean
errorDebug
(String s, boolean asis) Display a string in the Stata Results window as an error if set debug on is enabled.static boolean
Display the stack trace as an error if set debug on is enabled.static void
Display an object in the Stata Results window as an error and automatically add a line separator at the end.static void
Display a string in the Stata Results window as an error and automatically add a line separator at the end.static int
errorMsg
(int rc) Display the standard Stata error message associated with return code rc in the Stata Results window.static int
executeCommand
(String command, boolean echo) Execute a Stata command.static String
formatValue
(double val, String format) Format a value using a Stata format.static String
Get the User-Agent that Stata uses for web requests.static double
Get the version number of the calling program.static String
Get a valid Stata temporary filename.static String
Get a valid Stata temporary name.static String
Get the current Stata working directory.static boolean
Check if aString
is a valid Stata name.static boolean
Check if aString
is a valid Stata variable name.static void
Apply Stata's proxy settings to Java.static int
pollnow()
Request that Stata poll its GUI immediately.static int
pollstd()
Request that Stata poll its GUI at the standard interval.static String
processTildePath
(String path) Stata utility to convert a path beginning with a tilde to a user's home directory.static File
resolvePath
(String path) Resolve a path to aFile
; the path may be relative to Stata's current working directory, begin with a tilde, or be an absolute path.static void
setRC
(int rc) Set the Stata return code when used with Java integration (that is, java[:] blocks).static String
static String
-
Field Details
-
RC_BREAK
public static final int RC_BREAK- See Also:
-
RC_GENERAL_ERROR
public static final int RC_GENERAL_ERROR- See Also:
-
RC_GENERAL_EXCEPTION
public static final int RC_GENERAL_EXCEPTION- See Also:
-
RC_SYNTAX_ERROR
public static final int RC_SYNTAX_ERROR- See Also:
-
-
Method Details
-
callGC
Call the Java garbage collector. Calling this method should generally be avoided. -
display
Display an object in the Stata Results window. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
o
- The object to display.
-
display
Display an object in the Stata Results window.- Parameters:
o
- The object to display.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
display
Display an object in the Stata Results window.- Parameters:
o
- The object to display.mode
- TheDisplayMode
.
-
display
Display an object in the Stata Results window.- Parameters:
o
- The object to display.mode
- TheDisplayMode
.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
display
Display a string in the Stata Results window. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
s
- The string to display.
-
display
Display a string in the Stata Results window.- Parameters:
s
- The string to display.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
display
Display a string in the Stata Results window.- Parameters:
s
- The string to display.mode
- TheDisplayMode
.
-
display
Display a string in the Stata Results window.- Parameters:
s
- The string to display.mode
- TheDisplayMode
.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
displayln
Send a line separator to the output. -
displayln
Display an object in the Stata Results window and automatically add a line separator at the end. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
o
- The object to display.
-
displayln
Display an object in the Stata Results window and automatically add a line separator at the end.- Parameters:
o
- The object to display.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
displayln
Display an object in the Stata Results window and automatically add a line separator at the end. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
o
- The object to display.mode
- TheDisplayMode
.
-
displayln
Display an object in the Stata Results window and automatically add a line separator at the end.- Parameters:
o
- The object to display.mode
- TheDisplayMode
.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
displayln
Display a string in the Stata Results window and automatically add a line separator at the end. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
s
- The string to display.
-
displayln
Display a string in the Stata Results window and automatically add a line separator at the end.- Parameters:
s
- The string to display.mode
- TheDisplayMode
.
-
displayln
Display a string in the Stata Results window and automatically add a line separator at the end.- Parameters:
s
- The string to display.mode
- TheDisplayMode
.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
error
Display an object in the Stata Results window as an error. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
o
- The object to display.
-
error
Display an object in the Stata Results window as an error.- Parameters:
o
- The object to display.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
error
Display a string in the Stata Results window as an error. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
s
- The string to display.
-
error
Display a string in the Stata Results window as an error.- Parameters:
s
- The string to display.asis
- When true, the string is printed without using the Stata SMCL interpreter.
-
errorDebug
Display a string in the Stata Results window as an error if set debug on is enabled. The string will not be run through the Stata SMCL interpreter.- Parameters:
s
- The string to display.- Returns:
- True if set debug on is enabled.
-
errorDebug
Display a string in the Stata Results window as an error if set debug on is enabled.- Parameters:
s
- The string to display.asis
- When true, the string is printed without using the Stata SMCL interpreter.- Returns:
- True if set debug on is enabled.
-
errorDebug
Display the stack trace as an error if set debug on is enabled.- Parameters:
t
- The throwable containing the stack trace to display.- Returns:
- True if set debug on is enabled.
-
errorln
Display an object in the Stata Results window as an error and automatically add a line separator at the end. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
o
- The object to display.
-
errorln
Display a string in the Stata Results window as an error and automatically add a line separator at the end. Before the string is printed, it is run through the Stata SMCL interpreter.- Parameters:
s
- The string to display.
-
errorMsg
Display the standard Stata error message associated with return code rc in the Stata Results window.- Parameters:
rc
- The return code for the error.- Returns:
- The return code for the error.
-
executeCommand
Execute a Stata command. This feature is not supported for use with Java integration (that is, java[:] blocks).- Parameters:
command
- The command to execute.echo
- Echo the command.- Returns:
- Return code from Stata; 0 if successful.
-
formatValue
Format a value using a Stata format. -
getAgentString
Get the User-Agent that Stata uses for web requests. This can be useful for setting the request property for aURLConnection
.
For example,URLConnection conn = url.openConnection(); conn.setRequestProperty("User-Agent", SFIToolkit.getAgentString());
- Returns:
- The agent string.
-
getCallerVersion
Get the version number of the calling program. This function can be used to implement Stata version control.- Returns:
- The caller's version number.
-
getTempFile
Get a valid Stata temporary filename.- Returns:
- The filename, including its path.
-
getTempName
Get a valid Stata temporary name.- Returns:
- The temporary name.
-
getWorkingDir
Get the current Stata working directory.- Returns:
- The path of the current working directory.
-
isValidName
Check if aString
is a valid Stata name.- Parameters:
s
- Name to test.- Returns:
- True if the
String
represents a valid Stata name.
-
isValidVariableName
Check if aString
is a valid Stata variable name.- Parameters:
s
- Name to test.- Returns:
- True if the
String
represents a valid Stata variable name.
-
loadStataProxySettings
public static void loadStataProxySettings()Apply Stata's proxy settings to Java. Call this prior to making a web request where you want proxy settings to be applied. This method only needs to be called once. -
pollnow
Request that Stata poll its GUI immediately. Use this method inside a time-consuming task so that the Stata interface is responsive to user inputs. Generally,pollstd
should be used instead. This method must be called from the main thread. If called from a worker thread, this method does nothing and returns 0.- Returns:
- A 0 unless the Break key has been pressed.
-
pollstd
Request that Stata poll its GUI at the standard interval. Use this method inside a time-consuming task so that the Stata interface is responsive to user inputs. This method must be called from the main thread. If called from a worker thread, this method does nothing and returns 0.- Returns:
- A 0 unless the Break key has been pressed.
-
processTildePath
Stata utility to convert a path beginning with a tilde to a user's home directory. If the path does not begin with a tilde, then the path will not be modified.- Parameters:
path
- Path to process.- Returns:
- The processed path.
-
resolvePath
Resolve a path to aFile
; the path may be relative to Stata's current working directory, begin with a tilde, or be an absolute path.- Parameters:
path
- Path to process.- Returns:
- A
File
. - Throws:
InvalidPathException
- If an error occurs an InvalidPathException is thrown.
-
setRC
Set the Stata return code when used with Java integration (that is, java[:] blocks). If this method is called within a plugin invoked with javacall, the return code will be overwritten when javacall exits.- Parameters:
rc
- The return code to set.
-
stackTraceToString
- Parameters:
e
- Exception.- Returns:
- The
String
representation of the stack trace.
-
stackTraceToString
- Parameters:
t
- Throwable.- Returns:
- The
String
representation of the stack trace.
-