当前位置: 首页>>代码示例>>Java>>正文


Java Platform.isLinux方法代码示例

本文整理汇总了Java中com.sun.jna.Platform.isLinux方法的典型用法代码示例。如果您正苦于以下问题:Java Platform.isLinux方法的具体用法?Java Platform.isLinux怎么用?Java Platform.isLinux使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jna.Platform的用法示例。


在下文中一共展示了Platform.isLinux方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getImplInstance

import com.sun.jna.Platform; //导入方法依赖的package包/类
private static final NativeCalls getImplInstance() {
  if (Platform.isLinux()) {
    return new LinuxNativeCalls();
  }
  if (Platform.isWindows()) {
    return new WinNativeCalls();
  }
  if (Platform.isSolaris()) {
    return new SolarisNativeCalls();
  }
  if (Platform.isMac()) {
    return new MacOSXNativeCalls();
  }
  if (Platform.isFreeBSD()) {
    return new FreeBSDNativeCalls();
  }
  return new POSIXNativeCalls();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:NativeCallsJNAImpl.java

示例2: getPlatformFolder

import com.sun.jna.Platform; //导入方法依赖的package包/类
private static String getPlatformFolder() {
    String result;

    if (Platform.isMac()) {
        result = "macosx";
    } else if (Platform.isWindows()) {
        result = "win";
    } else if (Platform.isLinux()) {
        result = "linux";
    } else if (Platform.isFreeBSD()) {
        result = "freebsd";
    } else if (Platform.isOpenBSD()) {
        result = "openbsd";
    } else {
        throw new IllegalStateException("Platform " + Platform.getOSType() + " is not supported");
    }

    return result;
}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:20,代码来源:PtyUtil.java

示例3: getUnixUID

import com.sun.jna.Platform; //导入方法依赖的package包/类
/**
 * Gets the user ID on Unix based systems. This should not change during a
 * session and the lookup is expensive, so we cache the result.
 *
 * @return The Unix user ID
 * @throws IOException
 */
public static int getUnixUID() throws IOException {
	if (
		Platform.isAIX() || Platform.isFreeBSD() || Platform.isGNU() || Platform.iskFreeBSD() ||
		Platform.isLinux() || Platform.isMac() || Platform.isNetBSD() || Platform.isOpenBSD() ||
		Platform.isSolaris()
	) {
		synchronized (unixUIDLock) {
			if (unixUID < 0) {
				String response;
			    Process id;
				id = Runtime.getRuntime().exec("id -u");
			    try (BufferedReader reader = new BufferedReader(new InputStreamReader(id.getInputStream(), Charset.defaultCharset()))) {
			    	response = reader.readLine();
			    }
			    try {
			    	unixUID = Integer.parseInt(response);
			    } catch (NumberFormatException e) {
			    	throw new UnsupportedOperationException("Unexpected response from OS: " + response, e);
			    }
			}
			return unixUID;
		}
	}
	throw new UnsupportedOperationException("getUnixUID can only be called on Unix based OS'es");
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:33,代码来源:FileUtil.java

示例4: byName

import com.sun.jna.Platform; //导入方法依赖的package包/类
public static Process byName(String name) {
	if (Platform.isWindows()) {
		Tlhelp32.PROCESSENTRY32.ByReference entry = new Tlhelp32.PROCESSENTRY32.ByReference();
		Pointer snapshot = Kernel32.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL.intValue(), 0);
		try {
			while (Kernel32.Process32Next(snapshot, entry)) {
				String processName = Native.toString(entry.szExeFile);
				if (name.equals(processName)) {
					return byId(entry.th32ProcessID.intValue());
				}
			}
		} finally {
			Kernel32.CloseHandle(snapshot);
		}
	} else if (Platform.isMac() || Platform.isLinux()) {
		return byId(Utils.exec("bash", "-c", "ps -A | grep -m1 \"" + name + "\" | awk '{print $1}'"));
	} else {
		throw new UnsupportedOperationException("Unknown operating system! (" + System.getProperty("os.name") + ")");
	}
	throw new IllegalStateException("Process '" + name + "' was not found. Are you sure its running?");
}
 
开发者ID:Jonatino,项目名称:Java-Memory-Manipulation,代码行数:22,代码来源:Processes.java

示例5: byId

import com.sun.jna.Platform; //导入方法依赖的package包/类
public static Process byId(int id) {
	if ((Platform.isMac() || Platform.isLinux()) && !isSudo()) {
		throw new RuntimeException("You need to run as root/sudo for unix/osx based environments.");
	}
	
	if (Platform.isWindows()) {
		return new Win32Process(id, Kernel32.OpenProcess(0x438, true, id));
	} else if (Platform.isLinux()) {
		return new UnixProcess(id);
	} else if (Platform.isMac()) {
		IntByReference out = new IntByReference();
		if (mac.task_for_pid(mac.mach_task_self(), id, out) != 0) {
			throw new IllegalStateException("Failed to find mach task port for process, ensure you are running as sudo.");
		}
		return new MacProcess(id, out.getValue());
	}
	throw new IllegalStateException("Process " + id + " was not found. Are you sure its running?");
}
 
开发者ID:Jonatino,项目名称:Java-Memory-Manipulation,代码行数:19,代码来源:Processes.java

示例6: getNativeHandle

import com.sun.jna.Platform; //导入方法依赖的package包/类
/**
 * Helper function to get the proper handle for a given SWT Composite.
 *
 * @param composite the SWT Composite for what i like to get the handle. 
 * The type can't be Control since only Composite has embeddedHandle and
 * the Composite's style must be embedded.  
 * @return the handle of the Composite or 0 if the handle is not available.
 */
public static long getNativeHandle(Composite composite) {
    if (composite != null /*&& ((composite.getStyle() | SWT.EMBEDDED) != 0)*/)
     try {
         Class<? extends Composite> compositeClass = composite.getClass();
         Field handleField = Platform.isLinux() ? compositeClass.getField("embeddedHandle") : compositeClass.getField("handle");
         Class<?> t = handleField.getType();
         if (t.equals(long.class))
             return handleField.getLong(composite);
         else if (t.equals(int.class))
             return handleField.getInt(composite);
     } catch (Exception e) {
         throw new GstException("Cannot set window ID, in XOverlay interface, composite is null or not SWT.EMBEDDED");
     }
    return 0L;
}
 
开发者ID:gstreamer-java,项目名称:gstreamer1.x-java,代码行数:24,代码来源:SWTOverlay.java

示例7: getPlatformFolder

import com.sun.jna.Platform; //导入方法依赖的package包/类
private static String getPlatformFolder() {
  String result;

  if (Platform.isMac()) {
    result = "macosx";
  } else if (Platform.isWindows()) {
    result = "win";
  } else if (Platform.isLinux()) {
    result = "linux";
  } else if (Platform.isFreeBSD()) {
    result = "freebsd";
  } else if (Platform.isOpenBSD()) {
    result = "openbsd";
  } else {
    throw new IllegalStateException("Platform " + Platform.getOSType() + " is not supported");
  }

  return result;
}
 
开发者ID:traff,项目名称:pty4j,代码行数:20,代码来源:PtyUtil.java

示例8: getOpener

import com.sun.jna.Platform; //导入方法依赖的package包/类
private Opener getOpener()
{
	if( Platform.isWindows() )
	{
		final Permissions permissions = new Permissions();
		permissions.add(new AllPermission());
		final AccessControlContext context = new AccessControlContext(new ProtectionDomain[]{new ProtectionDomain(
			null, permissions)});
		return AccessController.doPrivileged(new PrivilegedAction<Opener>()
		{
			@Override
			public Opener run()
			{
				return new WindowsOpener();
			}
		}, context);
	}

	if( Platform.isLinux() )
	{
		return new LinuxOpener();
	}

	if( Platform.isMac() )
	{
		return new MacOpener();
	}

	throw new UnsupportedOperationException("This platform is not supported");
}
 
开发者ID:equella,项目名称:Equella,代码行数:31,代码来源:InPlaceEditAppletLauncher.java

示例9: mapSharedLibraryName

import com.sun.jna.Platform; //导入方法依赖的package包/类
static String mapSharedLibraryName(String libName) {
    if (Platform.isMac()) {
        if (libName.startsWith("lib")
            && (libName.endsWith(".dylib")
                || libName.endsWith(".jnilib"))) {
            return libName;
        }
        String name = System.mapLibraryName(libName);
        // On MacOSX, System.mapLibraryName() returns the .jnilib extension
        // (the suffix for JNI libraries); ordinarily shared libraries have
        // a .dylib suffix
        if (name.endsWith(".jnilib")) {
            return name.substring(0, name.lastIndexOf(".jnilib")) + ".dylib";
        }
        return name;
    }
    else if (Platform.isLinux() || Platform.isFreeBSD()) {
        if (isVersionedName(libName) || libName.endsWith(".so")) {
            // A specific version was requested - use as is for search
            return libName;
        }
    }
    else if (Platform.isAIX()) {	// can be libx.a, libx.a(shr.o), libx.so
        if (libName.startsWith("lib")) {
            return libName;
        }
    }
    else if (Platform.isWindows()) {
        if (libName.endsWith(".drv") || libName.endsWith(".dll")) {
            return libName;
        }
    }

    return System.mapLibraryName(libName);
}
 
开发者ID:xtuhcy,项目名称:webkit4j,代码行数:36,代码来源:InstallLibs.java

示例10: getNativeLibraryName

import com.sun.jna.Platform; //导入方法依赖的package包/类
private static String getNativeLibraryName() {
    String result;

    if (Platform.isMac()) {
        result = "libpty.dylib";
    } else if (Platform.isWindows()) {
        result = "winpty.dll";
    } else if (Platform.isLinux() || Platform.isFreeBSD() || Platform.isOpenBSD()) {
        result = "libpty.so";
    } else {
        throw new IllegalStateException("Platform " + Platform.getOSType() + " is not supported");
    }

    return result;
}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:16,代码来源:PtyUtil.java

示例11: main

import com.sun.jna.Platform; //导入方法依赖的package包/类
public static void main(String[] args) {
	try {
		//check platform
		if (!Platform.isLinux()) {
			throw new IllegalStateException("Not a linux platform");
		}
		if (!Platform.is64Bit()) {
			throw new IllegalStateException("Not a 64bit platform");
		}
		//bump max open files limit
		int procMax = Integer.parseInt(Files.readAllLines(new File("/proc/sys/fs/nr_open").toPath()).get(0));
		ResourceLimit rlimit = new ResourceLimit();
		rlimit.rlim_cur = procMax;
		rlimit.rlim_max = procMax;
		CLibrary.setrlimit(CLibrary.RLIMIT_NOFILE, rlimit);
		//bump max mmap count
		BufferedWriter maxMapCountStream = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("/proc/sys/vm/max_map_count"))));
		maxMapCountStream.write(String.valueOf(Integer.MAX_VALUE));
		maxMapCountStream.close();
		//infinite sleep thread, doens't allow program to close if no folders configured
		new InfiniteSleeperThread().start();
		//start watching directories
		DirectoryList list = new DirectoryList();
		list.load("dirlist");
		for (File directory : list.getList()) {
			new DirectoryWatchService(directory).start();
		}
		for (String arg : args) {
			new DirectoryWatchService(new File(arg)).start();
		}
	} catch (Throwable t) {
		ExceptionShutdown.shutdown("Exception while initializing", t);
	}
}
 
开发者ID:Shevchik,项目名称:DirectoryCacher,代码行数:35,代码来源:DirectoryCacher.java

示例12: getInstance

import com.sun.jna.Platform; //导入方法依赖的package包/类
public static MemoryMap getInstance() {
    if (Platform.isWindows()) {
        return new MemoryMapWindows(MemoryMappedByteBufFactory.INSTANCE);
    } else if (Platform.isLinux()) {
        return new MemoryMapLinux(MemoryMappedByteBufFactory.INSTANCE);
    } else {
        throw new UnsatisfiedLinkError("OS is not supported!");
    }
}
 
开发者ID:Nithanim,项目名称:mmf4j,代码行数:10,代码来源:MemoryMapFactory.java

示例13: create

import com.sun.jna.Platform; //导入方法依赖的package包/类
static ScreenAccessor create(boolean isNative) {
    if (isNative) {
        if (Platform.isWindows()) {
            return new WindowsScreenAccessor();
        }
        if (Platform.isLinux()) {
            return new LinuxScreenAccessor();
        }
    }
    return new AwtRobotScreenAccessor();
}
 
开发者ID:pavelfatin,项目名称:typometer,代码行数:12,代码来源:ScreenAccessor.java

示例14: hasSameHost

import com.sun.jna.Platform; //导入方法依赖的package包/类
/**
 * Check if server and client are on same host (not using containers).
 * @return true if server and client are really on same host
 */
public boolean hasSameHost() {
    try {
        Statement st = sharedConnection.createStatement();
        ResultSet rs = st.executeQuery("select @@version_compile_os");
        if (rs.next()) {
            if ((rs.getString(1).contains("linux") && Platform.isWindows())
                    || (rs.getString(1).contains("win") && Platform.isLinux())) return false;
        }
    } catch (SQLException sqle) {
        //eat
    }
    return true;
}
 
开发者ID:MariaDB,项目名称:mariadb-connector-j,代码行数:18,代码来源:BaseTest.java

示例15: cleanupNativeFolder

import com.sun.jna.Platform; //导入方法依赖的package包/类
/**
 * cleanup the native folder
 * 
 * only the specified folders should survive
 * 
 * Windows: windows-x86 windows-x64 Linux: linux-x86 linux-x64 Mac OSX: mac-x86 mac-x64
 */
private static void cleanupNativeFolder() {
  // no cleanup in GIT
  if (ReleaseInfo.isGitBuild()) {
    return;
  }

  try {
    File[] nativeFiles = new File("native").listFiles();
    if (nativeFiles == null) {
      return;
    }

    for (File file : nativeFiles) {
      if (!file.isDirectory()) {
        continue;
      }

      if (Platform.isWindows() && !"windows-x86".equals(file.getName()) && !"windows-x64".equals(file.getName())) {
        FileUtils.deleteQuietly(file);
      }
      else if (Platform.isLinux() && !"linux-x86".equals(file.getName()) && !"linux-x64".equals(file.getName())) {
        FileUtils.deleteQuietly(file);
      }
      else if (Platform.isMac() && !"mac-x86".equals(file.getName()) && !"mac-x64".equals(file.getName())) {
        FileUtils.deleteQuietly(file);
      }
    }
  }
  catch (Exception e) {
    LOGGER.warn("failed to cleanup native folder: " + e.getMessage());
  }
}
 
开发者ID:tinyMediaManager,项目名称:tinyMediaManager,代码行数:40,代码来源:UpgradeTasks.java


注:本文中的com.sun.jna.Platform.isLinux方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。