Package jnr.ffi
Class Platform
- java.lang.Object
-
- jnr.ffi.Platform
-
- Direct Known Subclasses:
Platform.Supported,Platform.Unsupported
public abstract class Platform extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPlatform.CPUThe supported CPU architectures.private static classPlatform.DarwinAPlatformsubclass representing the MacOS system.private static classPlatform.Default(package private) static classPlatform.IbmI(package private) static classPlatform.LinuxAPlatformsubclass representing the Linux operating system.static classPlatform.OSThe common names of supported operating systems.private static classPlatform.SingletonHolderprivate static classPlatform.Supportedprivate static classPlatform.Unsupportedprivate static classPlatform.WindowsAPlatformsubclass representing the Windows system.
-
Field Summary
Fields Modifier and Type Field Description private intaddressSizeprivate Platform.CPUcpuprotected java.util.regex.PatternlibPatternprivate static java.util.LocaleLOCALEprivate intlongSizeprivate Platform.OSos
-
Constructor Summary
Constructors Modifier Constructor Description privatePlatform(Platform.OS os)Platform(Platform.OS os, Platform.CPU cpu, int addressSize, int longSize, java.lang.String libPattern)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intaddressSize()Deprecated.UseRuntime.addressSize()instead.private static intcalculateAddressSize(Platform.CPU cpu)private static Platform.CPUdetermineCPU()private static Platform.OSdetermineOS()Determines the operating system jffi is running onprivate static PlatformdeterminePlatform()private static PlatformdeterminePlatform(Platform.OS os)Determines thePlatformthat best describes theOSprivate static booleanequalsIgnoreCase(java.lang.String s1, java.lang.String s2)Platform.CPUgetCPU()Gets the current processor architecture the JVM is running on.java.lang.StringgetName()Gets the name of thisPlatform.static PlatformgetNativePlatform()Gets the nativePlatformPlatform.OSgetOS()Gets the current Operating System.java.lang.StringgetOSName()static PlatformgetPlatform()Deprecated.java.lang.StringgetStandardCLibraryName()Returns the platform specific standard C library namejava.lang.StringgetVersion()Gets the version of this platform as specified by the system property "os.version"intgetVersionMajor()Gets the number representing the major version of this platform This uses the first number fromgetVersion()intgetVersionMinor()Gets the number representing the minor version of this platform This uses the second number fromgetVersion()private java.util.List<java.lang.String>getVersionNumbers()booleanis32Bit()booleanis64Bit()booleanisBigEndian()Returns true if the current platform is big endianbooleanisBSD()booleanisLittleEndian()Returns true if the current platform is little endianbooleanisUnix()java.util.List<java.lang.String>libraryLocations(java.lang.String libName, java.util.List<java.lang.String> additionalPaths)Returns a list of absolute paths to the found locations of a library with the base namelibName, if the returned list is empty then the library could not be found and will fail to be loaded as a result.java.lang.StringlocateLibrary(java.lang.String libName, java.util.List<java.lang.String> libraryPath)Searches through a list of directories for a native library.java.lang.StringlocateLibrary(java.lang.String libName, java.util.List<java.lang.String> libraryPaths, java.util.Map<LibraryOption,java.lang.Object> options)Searches through a list of directories for a native library.intlongSize()Deprecated.UseRuntime.longSize()instead.java.lang.StringmapLibraryName(java.lang.String libName)Maps from a generic library name (e.g.private static booleanstartsWithIgnoreCase(java.lang.String s1, java.lang.String s2)
-
-
-
Field Detail
-
LOCALE
private static final java.util.Locale LOCALE
-
os
private final Platform.OS os
-
cpu
private final Platform.CPU cpu
-
addressSize
private final int addressSize
-
longSize
private final int longSize
-
libPattern
protected final java.util.regex.Pattern libPattern
-
-
Constructor Detail
-
Platform
public Platform(Platform.OS os, Platform.CPU cpu, int addressSize, int longSize, java.lang.String libPattern)
-
Platform
private Platform(Platform.OS os)
-
-
Method Detail
-
determineOS
private static Platform.OS determineOS()
Determines the operating system jffi is running on- Returns:
- An member of the
OSenum.
-
determinePlatform
private static Platform determinePlatform(Platform.OS os)
Determines thePlatformthat best describes theOS- Parameters:
os- The operating system.- Returns:
- An instance of
Platform
-
determinePlatform
private static Platform determinePlatform()
-
determineCPU
private static Platform.CPU determineCPU()
-
calculateAddressSize
private static int calculateAddressSize(Platform.CPU cpu)
-
getNativePlatform
public static Platform getNativePlatform()
Gets the nativePlatform- Returns:
- The current platform.
-
getPlatform
@Deprecated public static Platform getPlatform()
Deprecated.
-
getOS
public final Platform.OS getOS()
Gets the current Operating System.- Returns:
- A
OSvalue representing the current Operating System.
-
getCPU
public final Platform.CPU getCPU()
Gets the current processor architecture the JVM is running on.- Returns:
- A
CPUvalue representing the current processor architecture.
-
isBSD
public final boolean isBSD()
-
isUnix
public final boolean isUnix()
-
longSize
public final int longSize()
Deprecated.UseRuntime.longSize()instead.Gets the size of a C 'long' on the native platform.- Returns:
- the size of a long in bits
-
addressSize
public final int addressSize()
Deprecated.UseRuntime.addressSize()instead.Gets the size of a C address/pointer on the native platform.- Returns:
- the size of a pointer in bits
-
is32Bit
public final boolean is32Bit()
- Returns:
- true if this platform is 32 bit, else false
Note: do not use this to determine long size, instead use
Runtime.longSize()
-
is64Bit
public final boolean is64Bit()
- Returns:
- true if this platform is 64 bit, else false
Note: do not use this to determine long size, instead use
Runtime.longSize()
-
isLittleEndian
public final boolean isLittleEndian()
Returns true if the current platform is little endian- Returns:
- true if little endian, false otherwise or if cannot determine
-
isBigEndian
public final boolean isBigEndian()
Returns true if the current platform is big endian- Returns:
- true if big endian, false otherwise or if cannot determine
-
getOSName
public final java.lang.String getOSName()
- Returns:
- the String representing the OS name from the System property
os.nameor null if none was found This is not the same asgetOS()which returns thePlatform.OS. For example: Mac OS X is thePlatform.OS.DARWINPlatform.OSbut returns "Mac OS X" from this method
-
getName
public java.lang.String getName()
Gets the name of thisPlatform.- Returns:
- The name of this platform.
-
getVersion
public java.lang.String getVersion()
Gets the version of this platform as specified by the system property "os.version"- Returns:
- the String representing the version of this platform, or null if none could be found
-
getVersionNumbers
private java.util.List<java.lang.String> getVersionNumbers()
- Returns:
- the list of version numbers found from
getVersion()or an empty list if none were found
-
getVersionMajor
public int getVersionMajor()
Gets the number representing the major version of this platform This uses the first number fromgetVersion()- Returns:
- the number representing the major version of this platform or -1 if none was found
-
getVersionMinor
public int getVersionMinor()
Gets the number representing the minor version of this platform This uses the second number fromgetVersion()- Returns:
- the number representing the minor version of this platform or -1 if none was found
-
getStandardCLibraryName
public java.lang.String getStandardCLibraryName()
Returns the platform specific standard C library name- Returns:
- The standard C library name
-
mapLibraryName
public java.lang.String mapLibraryName(java.lang.String libName)
Maps from a generic library name (e.g. "c") to the platform specific library name.- Parameters:
libName- The library name to map- Returns:
- The mapped library name.
-
locateLibrary
public java.lang.String locateLibrary(java.lang.String libName, java.util.List<java.lang.String> libraryPath)Searches through a list of directories for a native library.- Parameters:
libName- the base name (e.g. "c") of the library to locatelibraryPath- the list of directories to search- Returns:
- the path of the library
-
locateLibrary
public java.lang.String locateLibrary(java.lang.String libName, java.util.List<java.lang.String> libraryPaths, java.util.Map<LibraryOption,java.lang.Object> options)Searches through a list of directories for a native library.- Parameters:
libName- the base name (e.g. "c") of the library to locatelibraryPaths- the list of directories to searchoptions- map ofLibraryOptions to customize search behavior such asLibraryOption.PreferCustomPaths- Returns:
- the path of the library
-
libraryLocations
public java.util.List<java.lang.String> libraryLocations(java.lang.String libName, java.util.List<java.lang.String> additionalPaths)Returns a list of absolute paths to the found locations of a library with the base namelibName, if the returned list is empty then the library could not be found and will fail to be loaded as a result. Even if a library is found, this does not guarantee that it will successfully be loaded, it only guarantees that the reason for the failure was not that it was not found.- Parameters:
libName- the base name (e.g. "c") of the library to locateadditionalPaths- additional paths to search, these take precedence over default paths, (as is the behavior inLibraryLoader) pass null to only search in the default paths- Returns:
- the list of absolute paths where the library was found
-
startsWithIgnoreCase
private static boolean startsWithIgnoreCase(java.lang.String s1, java.lang.String s2)
-
equalsIgnoreCase
private static boolean equalsIgnoreCase(java.lang.String s1, java.lang.String s2)
-
-