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
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcallGC()Call the Java garbage collector. Calling this method should generally be avoided.static voidDisplay an object in the Stata Results window.static voidDisplay an object in the Stata Results window.static voiddisplay(Object o, DisplayMode mode) Display an object in the Stata Results window.static voiddisplay(Object o, DisplayMode mode, boolean asis) Display an object in the Stata Results window.static voidDisplay a string in the Stata Results window.static voidDisplay a string in the Stata Results window.static voiddisplay(String s, DisplayMode mode) Display a string in the Stata Results window.static voiddisplay(String s, DisplayMode mode, boolean asis) Display a string in the Stata Results window.static voidSend a line separator to the output.static voidDisplay an object in the Stata Results window and automatically add a line separator at the end.static voidDisplay an object in the Stata Results window and automatically add a line separator at the end.static voiddisplayln(Object o, DisplayMode mode) Display an object in the Stata Results window and automatically add a line separator at the end.static voiddisplayln(Object o, DisplayMode mode, boolean asis) Display an object in the Stata Results window and automatically add a line separator at the end.static voidDisplay a string in the Stata Results window and automatically add a line separator at the end.static voiddisplayln(String s, DisplayMode mode) Display a string in the Stata Results window and automatically add a line separator at the end.static voiddisplayln(String s, DisplayMode mode, boolean asis) Display a string in the Stata Results window and automatically add a line separator at the end.static voidDisplay an object in the Stata Results window as an error.static voidDisplay an object in the Stata Results window as an error.static voidDisplay a string in the Stata Results window as an error.static voidDisplay a string in the Stata Results window as an error.static booleanerrorDebug(String s) Display a string in the Stata Results window as an error if set debug on is enabled.static booleanerrorDebug(String s, boolean asis) Display a string in the Stata Results window as an error if set debug on is enabled.static booleanDisplay the stack trace as an error if set debug on is enabled.static voidDisplay an object in the Stata Results window as an error and automatically add a line separator at the end.static voidDisplay a string in the Stata Results window as an error and automatically add a line separator at the end.static interrorMsg(int rc) Display the standard Stata error message associated with return code rc in the Stata Results window.static intexecuteCommand(String command, boolean echo) Execute a Stata command.static StringformatValue(double val, String format) Format a value using a Stata format.static StringGet the User-Agent that Stata uses for web requests.static doubleGet the version number of the calling program.static StringGet a valid Stata temporary filename.static StringGet a valid Stata temporary name.static StringGet the current Stata working directory.static booleanCheck if aStringis a valid Stata name.static booleanCheck if aStringis a valid Stata variable name.static voidApply Stata's proxy settings to Java.static intpollnow()Request that Stata poll its GUI immediately.static intpollstd()Request that Stata poll its GUI at the standard interval.static StringprocessTildePath(String path) Stata utility to convert a path beginning with a tilde to a user's home directory.static FileresolvePath(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 voidsetRC(int rc) Set the Stata return code when used with Java integration (that is, java[:] blocks).static Stringstatic 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 aStringis a valid Stata name.- Parameters:
s- Name to test.- Returns:
- True if the
Stringrepresents a valid Stata name.
-
isValidVariableName
Check if aStringis a valid Stata variable name.- Parameters:
s- Name to test.- Returns:
- True if the
Stringrepresents 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,pollstdshould 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
Stringrepresentation of the stack trace.
-
stackTraceToString
- Parameters:
t- Throwable.- Returns:
- The
Stringrepresentation of the stack trace.
-