public abstract class Platform
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Platform.StreamReader
Thread which reads the contents of a stream into a string buffer.
|
private static class |
Platform.UnixPlatform
Platform implementation for Un*x-like systems.
|
private static class |
Platform.WindowsPlatform
Platform implementation for Microsoft Windows-like systems.
|
Modifier and Type | Field and Description |
---|---|
private static Platform |
instance_ |
private static java.util.logging.Logger |
logger_ |
private java.lang.String |
name_ |
Modifier | Constructor and Description |
---|---|
protected |
Platform(java.lang.String name)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private static Platform |
createPlatform()
Constructs a Platform for the current system.
|
private static java.lang.String |
exec(java.lang.String[] args)
Attempts a with a given
list of arguments.
|
java.lang.String |
getEnv(java.lang.String varname)
Returns the value of an environment variable.
|
protected abstract java.lang.String[] |
getGetenvArgs(java.lang.String varname)
Returns an array of words to pass to
Runtime.exec(java.lang.String[]) in order
to read an environment variable name. |
abstract java.io.File |
getHomeDirectory()
Returns SAMP's definition of the "home" directory.
|
static Platform |
getPlatform()
Returns a
Platform instance for the current system. |
protected abstract java.lang.String[] |
getPrivateReadArgs(java.io.File file)
Returns an array of words to pass to
Runtime.exec(java.lang.String[]) in order
to set permissions on a given file so that it cannot be read by
anyone other than its owner. |
void |
setPrivateRead(java.io.File file)
Sets file permissions on a given file so that it cannot be read by
anyone other than its owner.
|
private static boolean |
setPrivateReadReflect(java.io.File file)
Attempt to use the
File.setReadable() method to set
permissions on a file so that it cannot be read by anyone other
than its owner. |
private static Platform instance_
private final java.lang.String name_
private static final java.util.logging.Logger logger_
protected Platform(java.lang.String name)
name
- platform namepublic abstract java.io.File getHomeDirectory()
public java.lang.String getEnv(java.lang.String varname)
varname
- name of environment variablepublic void setPrivateRead(java.io.File file) throws java.io.IOException
file
- file whose permissions are to be alteredjava.io.IOException
- if permissions cannot be changedprotected abstract java.lang.String[] getGetenvArgs(java.lang.String varname)
Runtime.exec(java.lang.String[])
in order
to read an environment variable name.
If null is returned, no way is known to do this with a system command.varname
- environment variable name to readprotected abstract java.lang.String[] getPrivateReadArgs(java.io.File file) throws java.io.IOException
Runtime.exec(java.lang.String[])
in order
to set permissions on a given file so that it cannot be read by
anyone other than its owner.
If null is returned, no way is known to do this with a system command.file
- file to alterjava.io.IOException
private static boolean setPrivateReadReflect(java.io.File file) throws java.io.IOException
File.setReadable()
method to set
permissions on a file so that it cannot be read by anyone other
than its owner.file
- file to alterjava.io.IOException
- if there was some I/O failureprivate static java.lang.String exec(java.lang.String[] args) throws java.io.IOException
Note: do not use this for cases in which the
output from stdout or stderr might be more than a few characters -
blocking or deadlock is possible (see Process
).
args
- array of words to pass to exec
java.io.IOException
- with text from standard error if there is an errorpublic static Platform getPlatform()
Platform
instance for the current system.private static Platform createPlatform()