public final class OS extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
SAFE_PAGE_SIZE |
static Exception |
TIME_LIMIT |
static String |
TMP |
static String |
USER_HOME |
| Modifier and Type | Method and Description |
|---|---|
static int |
defaultOsPageSize()
Returns default OS page size.
|
static @NotNull String |
findDir(@NotNull String suffix)
Finds a directory with the specified suffix in the class path.
|
static @NotNull File |
findFile(String... path)
Search a list of directories to find a path which is the last element.
|
static String |
getHostName()
Returns the host name of the current machine.
|
static String |
getIPAddress()
Returns the IP address of the current machine.
|
static long |
getPidMax() |
static int |
getProcessId()
Returns the process ID of the current running process.
|
static String |
getTarget()
Returns the target of the operating system.
|
static String |
getTmp()
Returns the temporary directory path.
|
static String |
getUserDir() |
static String |
getUserName()
Returns the username of the current user.
|
static boolean |
is64Bit() |
static boolean |
isLinux()
Returns if this JVM runs on the Linux operating system.
|
static boolean |
isMacOSX()
Returns if this JVM runs on the MacOS operating system.
|
static boolean |
isSparseFileSupported()
Checks if the operating system supports sparse files
|
static boolean |
isWindows()
Returns if this JVM runs on the Windows operating system.
|
static long |
map(@NotNull FileChannel fileChannel,
FileChannel.MapMode mode,
long start,
long size) |
static long |
map(@NotNull FileChannel fileChannel,
FileChannel.MapMode mode,
long start,
long size,
int pageSize)
Map a region of a file into memory.
|
static long |
mapAlign(long offset)
Aligns the specified offset for a memory-mapped file based on the operating system's page size.
|
static long |
mapAlign(long offset,
int pageAlignment)
Aligns the specified offset for a memory-mapped file to the nearest higher multiple of the given pageAlignment.
|
static long |
mapAlignment()
Returns the alignment of offsets in file, from which memory mapping could start, based on OS.
|
static @NotNull Memory |
memory() |
static long |
memoryMapped()
Returns the number of bytes that is memory mapped.
|
static long |
pageAlign(long size)
Align the size to page boundary
|
static long |
pageAlign(long size,
int pageSize)
Align the size to page boundary
|
static int |
pageSize() |
static int |
read0(FileDescriptor fd,
long address,
int len) |
static long |
spaceUsed(@NotNull String filename)
Get the space actually used by a file.
|
static void |
unmap(long address,
long size) |
static void |
unmap(long address,
long size,
int pageSize)
Unmap a region of memory.
|
static String |
userDir()
Returns the current working directory of the user.
|
static int |
write0(FileDescriptor fd,
long address,
int len) |
public static final String USER_HOME
public static final Exception TIME_LIMIT
public static final int SAFE_PAGE_SIZE
public static final String TMP
public static boolean isSparseFileSupported()
@NotNull public static @NotNull String findDir(@NotNull @NotNull String suffix) throws FileNotFoundException
suffix - the suffix of the directoryFileNotFoundException - if no directory with the specified suffix is found@NotNull public static @NotNull File findFile(@NotNull String... path)
path - of directories to use if found, the last path is always appended.public static String getHostName()
public static String getIPAddress()
public static String getUserName()
public static String getTarget()
public static String getTmp()
public static String getUserDir()
@NotNull public static @NotNull Memory memory()
public static long pageAlign(long size,
int pageSize)
size - the size to alignpageSize - the size of pagespageSize()public static long pageAlign(long size)
size - the size to alignpageSize()public static int pageSize()
pageAlign(long)public static int defaultOsPageSize()
public static long mapAlign(long offset)
For example, if the operating system's page size is 4096 bytes and an offset of 6000 is specified, this method would return 8192, as 8192 is the next multiple of 4096 greater than 6000.
offset - the offset to be aligned. It must be non-negative.IllegalArgumentException - if offset is negative.mapAlignment()public static long mapAlign(long offset,
int pageAlignment)
For example, if the provided alignment is 2M bytes and an offset of 2.5M is specified, this method would return 4M, as 4M is the next multiple of 2M greater than 2.5M.
offset - the offset to be aligned. It must be non-negative.pageAlignment - the alignment size, in bytes. This should typically be the operating system's page size or a multiple thereof.IllegalArgumentException - if offset is negative or pageAlignment is non-positive.public static long mapAlignment()
mapAlign(long)public static boolean is64Bit()
public static int getProcessId()
Note: Getting the process ID may be slow if the reserve DNS is not set up correctly.
public static boolean isWindows()
public static boolean isMacOSX()
public static boolean isLinux()
public static long getPidMax()
public static long map(@NotNull
@NotNull FileChannel fileChannel,
FileChannel.MapMode mode,
long start,
long size,
int pageSize)
throws IOException,
IllegalArgumentException
fileChannel - to mapmode - of accessstart - offset within a filesize - of region to map.IOException - if the mapping failsIllegalArgumentException - if the arguments are not validpublic static long map(@NotNull
@NotNull FileChannel fileChannel,
FileChannel.MapMode mode,
long start,
long size)
throws IOException,
IllegalArgumentException
IOExceptionIllegalArgumentExceptionpublic static void unmap(long address,
long size,
int pageSize)
throws IOException
address - of the start of the mapping.size - of the region mapped.IOException - if the unmap fails.public static void unmap(long address,
long size)
throws IOException
IOExceptionpublic static long memoryMapped()
public static long spaceUsed(@NotNull
@NotNull String filename)
filename - to get the actual size ofpublic static String userDir()
public static int read0(FileDescriptor fd, long address, int len) throws IOException
IOExceptionpublic static int write0(FileDescriptor fd, long address, int len) throws IOException
IOExceptionCopyright © 2024. All rights reserved.