public final class OsHelper extends Object
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static void |
allocSpaceForFile(FileDescriptor fd,
long offset,
long length) |
Allocates disk space for a file.
|
static void |
changeFileName(String oldPath,
String newPath) |
Changes the file name.
|
static void |
changeFilePermission(String path,
int mode) |
Changes the file permission.
|
static boolean |
checkFilePermission(String path,
int mode) |
Checks whether the user can access the specified file.
|
static void |
closeFile(FileDescriptor fd) |
Closes the file referred to by the specified file descriptor.
|
static FileDescriptor |
copyFileDescriptor(FileDescriptor fileDescriptor) |
Copies a file descriptor.
|
static FileDescriptor |
copyFileDescriptor(FileDescriptor oldFd,
int newFd) |
Copies the specified file descriptor.
|
static FileStat |
getFileStatus(FileDescriptor fd) |
Obtains the file status.
|
static FileStat |
getFileStatus(String path) |
Obtains file status information.
|
static FileStat |
getLinkFileStatus(String path) |
Obtains the file status.
|
static long |
getSystemConfig(int name) |
Obtains the system configuration at runtime.
|
static int |
getUID() |
Obtains the user ID of the calling process.
|
static int |
readFile(FileDescriptor fd,
byte[] bytes,
int byteOffset,
int byteCount) |
Reads a specified number of bytes from the specified file and saves the bytes to the specified byte array.
|
static int |
readFile(FileDescriptor fd,
ByteBuffer buffer) |
Reads data from the specified file and saves the data to the specified byte buffer.
|
static String |
readSymbolicLink(String path) |
Obtains the target file path to which the symbolic link points.
|
static void |
removeFileExtendedAttribute(String path,
String name) |
Removes the specified extended attribute of the specified file.
|
static void |
setEnvironmentVar(String name,
String value,
boolean overwrite) |
Replaces or adds the specified environment variable.
|
static void |
setFileExtendedAttribute(String path,
String name,
byte[] value,
int flag) |
Sets the specified extended attribute of the specified file, directory, or symbolic link.
|
static long |
setFileOperationPos(FileDescriptor fd,
long offset,
int whence) |
Sets the offset of the read or write position in the specified file based on
offset and whence. |
static int |
setProcessOption(int option,
long arg2,
long arg3,
long arg4,
long arg5) |
Sets the specified option for the calling process.
|
static void |
symbolLink(String oldPath,
String newPath) |
Creates a symbolic link to the target file.
|
static void |
trimFile(long targetFileSize,
FileDescriptor fileDescriptor) |
Truncates a given file to the specified size.
|
public static String readSymbolicLink(String path) throws OsHelperErrnoException
path - Indicates the symbolic link.OsHelperErrnoException - Throws this exception if an error occurs during the execution.public static FileStat getFileStatus(String path) throws OsHelperErrnoException
path - Indicates the file path.FileStat object storing the file status information.OsHelperErrnoException - Throws this exception if an error occurs during the execution.public static FileStat getFileStatus(FileDescriptor fd) throws OsHelperErrnoException
getFileStatus(java.lang.String),
except that the file is specified by the file descriptor in this method.fd - Indicates the file descriptor.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static FileStat getLinkFileStatus(String path) throws OsHelperErrnoException
getFileStatus(java.lang.String), except that if the file path is a symbolic link,
this method returns information about the link rather than the file the link points to.path - Indicates the file path.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static void symbolLink(String oldPath, String newPath) throws OsHelperErrnoException
oldPath - Indicates the target file path.newPath - Indicates the symbolic link to the target file.OsHelperErrnoException - Throws this exception if an error occurs during the execution.public static long getSystemConfig(int name)
name - Indicates the name of the system configuration to obtain.public static void setFileExtendedAttribute(String path, String name, byte[] value, int flag) throws OsHelperErrnoException
path - Indicates the file path.name - Indicates the name of the extended attribute to set.value - Indicates the value of the extended attribute to set.flag - Specifies whether to create or update the extended attribute.
Value 0 indicates creating or updating the extended attribute;
value 1 indicates only creating the extended attribute(the creation fails
if the extended attribute already exists);
value 2 indicates only updating the extended attribute (the update fails
if the extended attribute does not exist).OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static void setEnvironmentVar(String name, String value, boolean overwrite) throws OsHelperErrnoException
name - Indicates the name of the environment variable.value - Indicates the value of the environment variable.overwrite - Specifies whether to overwrite the value of the existing environment variable.
This parameter takes effect only when the environment variable already exists.
If this parameter is set to 0, the value of the existing environment variable will not be overwritten;
otherwise, the value of the existing environment variable will be overwritten.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static void removeFileExtendedAttribute(String path, String name) throws OsHelperErrnoException
path - Indicates the file path.name - Indicates the name of the extended attribute.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static void changeFileName(String oldPath, String newPath) throws OsHelperErrnoException
oldPath - Indicates the current file name.newPath - Indicates the new file name.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static int readFile(FileDescriptor fd, ByteBuffer buffer) throws InterruptedIOException, OsHelperErrnoException
fd - Indicates the file descriptor.buffer - Indicates the byte buffer to which the data is saved.InterruptedIOException - Throws this exception if I/O transfer is terminated.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static int readFile(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount) throws InterruptedIOException, OsHelperErrnoException
fd - Indicates the file descriptor.bytes - Indicates the byte array to which the data is saved.byteOffset - Indicates the position to start saving data.byteCount - Indicates the number of bytes to read.InterruptedIOException - Throws this exception if I/O transfer is terminated.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static int setProcessOption(int option,
long arg2,
long arg3,
long arg4,
long arg5)
throws OsHelperErrnoException
option - Indicates the option to set.arg2 - Indicates an argument of the option.arg3 - Indicates an argument of the option.arg4 - Indicates an argument of the option.arg5 - Indicates an argument of the option.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static void allocSpaceForFile(FileDescriptor fd, long offset, long length) throws OsHelperErrnoException
fd - Indicates the file descriptor.offset - Indicates the offset from the start position for allocating disk space.length - Indicates the disk space to allocate, in bytes.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static long setFileOperationPos(FileDescriptor fd, long offset, int whence) throws OsHelperErrnoException
offset and whence.fd - Indicates the file descriptor.offset - Indicates the offset.whence - Indicates whence. The value can be SEEK_SET (the result offset is
the value of offset), SEEK_CUR (the result offset is the current position plus
the value of offset), or SEEK_END (the result offset is the file size plus
the value of offset).-1 otherwise.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static int getUID()
public static FileDescriptor copyFileDescriptor(FileDescriptor oldFd, int newFd) throws OsHelperErrnoException
oldFd - Indicates the file descriptor to copy.newFd - Indicates the new file descriptor.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static void closeFile(FileDescriptor fd) throws OsHelperErrnoException
fd - Indicates the file descriptor.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static void changeFilePermission(String path, int mode) throws OsHelperErrnoException
path - Indicates the file path.mode - Indicates the permission to set, for example, OsHelperConstants#S_IROTH.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static boolean checkFilePermission(String path, int mode) throws OsHelperErrnoException
path - Indicates the file path.mode - Indicates the permission to check, for example, OsHelperConstants#F_OK.true if the user can access the specified file; returns false otherwise.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static void trimFile(long targetFileSize,
FileDescriptor fileDescriptor)
throws OsHelperErrnoException
targetFileSize - Indicates the target file size.fileDescriptor - Indicates the descriptor of the file to truncate.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.public static FileDescriptor copyFileDescriptor(FileDescriptor fileDescriptor) throws OsHelperErrnoException
fileDescriptor - Indicates the file descriptor to copy.OsHelperErrnoException - Throws this exception if an error occurs during the execution.
It contains the specific error message.