public final class Unix
extends java.lang.Object
Check with isOperational()
if this class is operational and only call the other
methods if Unix.isOperational() == true
.
Modifier and Type | Class and Description |
---|---|
static class |
Unix.Group
A class representing the Unix
group struct. |
static class |
Unix.Password
A class representing the Unix
passwd struct. |
static class |
Unix.Stat
A class representing the Unix
stat structure. |
Modifier and Type | Field and Description |
---|---|
static short |
S_IRGRP
read by group
|
static short |
S_IROTH
read by others
|
static short |
S_IRUSR
read by owner
|
static short |
S_ISGID
set group ID on execution
|
static short |
S_ISUID
set user ID on execution
|
static short |
S_ISVTX
sticky bit
|
static short |
S_IWGRP
write by group
|
static short |
S_IWOTH
write by others
|
static short |
S_IWUSR
write by owner
|
static short |
S_IXGRP
execute/search by group
|
static short |
S_IXOTH
execute/search by others
|
static short |
S_IXUSR
execute/search by owner
|
Constructor and Description |
---|
Unix() |
Modifier and Type | Method and Description |
---|---|
static boolean |
canDetectProcesses()
Returns
true , if process detection is available on this system. |
static void |
createHardLink(java.lang.String fileName,
java.lang.String linkName)
Creates a hard link linkName that points to fileName.
|
static void |
createSymbolicLink(java.lang.String fileName,
java.lang.String linkName)
Creates a symbolic link linkName that points to fileName.
|
static int |
getEgid()
Returns the effective gid that determines the permissions of this process.
|
static java.lang.String |
getErrorString(int errnum)
Returns the error string for the given errnum.
|
static int |
getEuid()
Returns the effective uid that determines the permissions of this process.
|
static Unix.Stat |
getFileInfo(java.lang.String fileName)
Returns the information about fileName.
|
static int |
getGid()
Returns the gid of the user that started this process.
|
static int |
getGidForGroupName(java.lang.String groupName)
Returns the gid of the groupName, or
-1 , if no group with this name
exists. |
static long |
getInode(java.lang.String fileName)
Returns the inode for the fileName.
|
static java.lang.String |
getLastError()
Returns the last error that occurred in this class.
|
static Unix.Stat |
getLinkInfo(java.lang.String linkName)
Returns the information about linkName.
|
static Unix.Stat |
getLinkInfo(java.lang.String linkName,
boolean readSymbolicLinkTarget)
Returns the information about linkName.
|
static int |
getNumberOfHardLinks(java.lang.String fileName)
Returns the number of hard links for the fileName.
|
static int |
getPid()
Returns the process identifier of the current process.
|
static int |
getUid()
Returns the uid of the user that started this process.
|
static int |
getUidForUserName(java.lang.String userName)
Returns the uid of the userName, or
-1 , if no user with this name
exists. |
static boolean |
isOperational()
Returns
true , if the native library has been loaded successfully and the link
utilities are operational, false otherwise. |
static boolean |
isProcessRunning(int pid)
Returns
true , if the process with pid is currently running and
false , if it is not running or if process detection is not available (
canDetectProcesses() == false ). |
static boolean |
isSymbolicLink(java.lang.String fileName)
Returns
true if fileName is a symbolic link and false
otherwise. |
static void |
setAccessMode(java.lang.String fileName,
short mode)
Sets the access mode of filename to the specified mode value.
|
static void |
setOwner(java.lang.String fileName,
int uid,
int gid)
Sets the owner of filename to the specified uid and gid
values.
|
static Unix.Stat |
tryGetFileInfo(java.lang.String fileName)
Returns the information about fileName, or
NullPointerException , if the
information could not be obtained, e.g. |
static Unix.Group |
tryGetGroupByGid(int gid)
Returns the
Unix.Group for the given gid, or null , if no group
with that gid exists. |
static Unix.Group |
tryGetGroupByName(java.lang.String groupName)
Returns the
Unix.Group for the given groupName, or null , if no
group with that name exists. |
static java.lang.String |
tryGetGroupNameForGid(int gid)
Returns the name of the group identified by gid, or
null , if no group
with that gid exists. |
static Unix.Stat |
tryGetLinkInfo(java.lang.String linkName)
Returns the information about linkName, or
NullPointerException , if the
information could not be obtained, e.g. |
static Unix.Stat |
tryGetLinkInfo(java.lang.String linkName,
boolean readSymbolicLinkTarget)
Returns the information about linkName, or
null if the information
can not be obtained, e.g. |
static Unix.Password |
tryGetUserByName(java.lang.String userName)
Returns the
Unix.Password for the given userName, or null , if no
user with that name exists. |
static Unix.Password |
tryGetUserByUid(int uid)
Returns the
Unix.Password for the given userName, or null , if no
user with that name exists. |
static java.lang.String |
tryGetUserNameForUid(int uid)
Returns the name of the user identified by uid.
|
static java.lang.String |
tryReadSymbolicLink(java.lang.String linkName)
Returns the value of the symbolik link linkName, or
null , if
linkName is not a symbolic link. |
public static final short S_ISUID
public static final short S_ISGID
public static final short S_ISVTX
public static final short S_IRUSR
public static final short S_IWUSR
public static final short S_IXUSR
public static final short S_IRGRP
public static final short S_IWGRP
public static final short S_IXGRP
public static final short S_IROTH
public static final short S_IWOTH
public static final short S_IXOTH
public static final boolean isOperational()
true
, if the native library has been loaded successfully and the link
utilities are operational, false
otherwise.public static boolean canDetectProcesses()
true
, if process detection is available on this system.public static java.lang.String getLastError()
tryGetLinkInfo(String)
or tryGetFileInfo(String)
returned
null
.public static int getPid()
public static boolean isProcessRunning(int pid)
true
, if the process with pid is currently running and
false
, if it is not running or if process detection is not available (
canDetectProcesses()
== false
).public static final int getUid()
public static final int getEuid()
public static final int getGid()
public static final int getEgid()
public static final void createHardLink(java.lang.String fileName, java.lang.String linkName) throws IOExceptionUnchecked
IOExceptionUnchecked
- If the underlying system call fails, e.g. because
linkName already exists or fileName does not exist.public static final void createSymbolicLink(java.lang.String fileName, java.lang.String linkName) throws IOExceptionUnchecked
IOExceptionUnchecked
- If the underlying system call fails, e.g. because
linkName already exists.public static final long getInode(java.lang.String fileName) throws IOExceptionUnchecked
IOExceptionUnchecked
- If the information could not be obtained, e.g. because the link
does not exist.public static final int getNumberOfHardLinks(java.lang.String fileName) throws IOExceptionUnchecked
IOExceptionUnchecked
- If the information could not be obtained, e.g. because the link
does not exist.public static final boolean isSymbolicLink(java.lang.String fileName) throws IOExceptionUnchecked
true
if fileName is a symbolic link and false
otherwise.IOExceptionUnchecked
- If the information could not be obtained, e.g. because the link
does not exist.public static final java.lang.String tryReadSymbolicLink(java.lang.String linkName) throws IOExceptionUnchecked
null
, if
linkName is not a symbolic link.IOExceptionUnchecked
- If the information could not be obtained, e.g. because the link
does not exist.public static final Unix.Stat getFileInfo(java.lang.String fileName) throws IOExceptionUnchecked
IOExceptionUnchecked
- If the information could not be obtained, e.g. because the file
does not exist.public static final Unix.Stat tryGetFileInfo(java.lang.String fileName) throws IOExceptionUnchecked
NullPointerException
, if the
information could not be obtained, e.g. because the file does not exist (call
getLastError()
to find out what went wrong).IOExceptionUnchecked
public static final Unix.Stat getLinkInfo(java.lang.String linkName) throws IOExceptionUnchecked
IOExceptionUnchecked
- If the information could not be obtained, e.g. because the link
does not exist.public static final Unix.Stat getLinkInfo(java.lang.String linkName, boolean readSymbolicLinkTarget) throws IOExceptionUnchecked
readSymbolicLinkTarget == true
, then the symbolic link target is read when
linkName is a symbolic link.IOExceptionUnchecked
- If the information could not be obtained, e.g. because the link
does not exist.public static final Unix.Stat tryGetLinkInfo(java.lang.String linkName) throws IOExceptionUnchecked
NullPointerException
, if the
information could not be obtained, e.g. because the link does not exist (call
getLastError()
to find out what went wrong).IOExceptionUnchecked
public static final Unix.Stat tryGetLinkInfo(java.lang.String linkName, boolean readSymbolicLinkTarget) throws IOExceptionUnchecked
null
if the information
can not be obtained, e.g. because the link does not exist (call getLastError()
to
find out what went wrong). If readSymbolicLinkTarget == true
, then the symbolic
link target is read when linkName is a symbolic link.IOExceptionUnchecked
public static final void setAccessMode(java.lang.String fileName, short mode) throws IOExceptionUnchecked
IOExceptionUnchecked
public static final void setOwner(java.lang.String fileName, int uid, int gid) throws IOExceptionUnchecked
IOExceptionUnchecked
public static final java.lang.String tryGetUserNameForUid(int uid)
public static final int getUidForUserName(java.lang.String userName)
-1
, if no user with this name
exists.public static final Unix.Password tryGetUserByName(java.lang.String userName)
Unix.Password
for the given userName, or null
, if no
user with that name exists.public static final Unix.Password tryGetUserByUid(int uid)
Unix.Password
for the given userName, or null
, if no
user with that name exists.public static final java.lang.String tryGetGroupNameForGid(int gid)
null
, if no group
with that gid exists.public static final int getGidForGroupName(java.lang.String groupName)
-1
, if no group with this name
exists.public static final Unix.Group tryGetGroupByName(java.lang.String groupName)
Unix.Group
for the given groupName, or null
, if no
group with that name exists.public static final Unix.Group tryGetGroupByGid(int gid)
Unix.Group
for the given gid, or null
, if no group
with that gid exists.public static final java.lang.String getErrorString(int errnum)