本文整理汇总了Java中org.apache.commons.lang3.SystemUtils类的典型用法代码示例。如果您正苦于以下问题:Java SystemUtils类的具体用法?Java SystemUtils怎么用?Java SystemUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SystemUtils类属于org.apache.commons.lang3包,在下文中一共展示了SystemUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setNodeHeight
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
/**
* Sets the node height used for drawing.
* <p>
* Also updates the font size used for drawing sequences within nodes.
*
* @param nodeHeight the node height
*/
public final void setNodeHeight(final double nodeHeight) {
this.nodeHeight = nodeHeight;
this.snpHeight = nodeHeight * SNP_HEIGHT_FACTOR;
final Text text = new Text("X");
text.setFont(new Font(DEFAULT_NODE_FONT, 1));
final double font1PHeight = text.getLayoutBounds().getHeight();
final String font;
if (SystemUtils.IS_OS_MAC) {
font = DEFAULT_MAC_NODE_FONT;
} else {
font = DEFAULT_NODE_FONT;
}
final double fontSize = DEFAULT_NODE_FONT_HEIGHT_SCALAR * nodeHeight / font1PHeight;
this.nodeFont = new Font(font, fontSize);
text.setFont(nodeFont);
this.charWidth = text.getLayoutBounds().getWidth();
this.charHeight = text.getLayoutBounds().getHeight();
}
示例2: doStart
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
private void doStart() {
try {
String[] command;
if (SystemUtils.IS_OS_WINDOWS) {
// for windows test
command = new String[] { "C:/Program Files/Java/jdk1.8.0_91/bin/java", "-version" };
} else {
// real use
Assert.notNull(file);
command = new String[] { this.command, argf, calculateFileName() };
}
process = new ProcessBuilder(command).redirectErrorStream(true).start();
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = input.readLine()) != null) {
content.add(String.format("%s : %s", name, line));
this.checkForEviction();
}
int exitVal = process.waitFor();
log.info("Exited with error code " + exitVal);
} catch (Exception e) {
log.error("Error", e);
throw new RuntimeException(e);
}
}
示例3: getLogger
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
/**
* Creates a static {@code Logger} instance.
*
* @return a static {@code Logger} with properties:
* <ul>
* <li>Name: {@code "DefaultDatabaseConfigurator"}.</li>
* <li>Output file pattern:
* {@code user.home/.kawansoft/log/AceQL.log}.</li>
* <li>Formatter: {@code SimpleFormatter}.</li>
* <li>Limit: 200Mb.</li>
* <li>Count (number of files to use): 2.</li>
* </ul>
*/
@Override
public Logger getLogger() throws IOException {
if (ACEQL_LOGGER != null) {
return ACEQL_LOGGER;
}
File logDir = new File(SystemUtils.USER_HOME + File.separator + ".kawansoft" + File.separator + "log");
logDir.mkdirs();
String pattern = logDir.toString() + File.separator + "AceQL.log";
ACEQL_LOGGER = Logger.getLogger(DefaultDatabaseConfigurator.class.getName());
Handler fh = new FileHandler(pattern, 200 * 1024 * 1024, 2, true);
fh.setFormatter(new SimpleFormatter());
ACEQL_LOGGER.addHandler(fh);
return ACEQL_LOGGER;
}
示例4: getProductFile
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
/**
*
* @return the product file that contains the product name
*/
private static File getProductFile() {
// Use absolute directory: client side and Tomcat side don'ts have same
// user.home value!
String exchangeDir = null;
if (SystemUtils.IS_OS_WINDOWS) {
exchangeDir = "c:\\temp\\";
} else {
if (FrameworkSystemUtil.isAndroid()) {
// exchangeDir = "/sdcard/";
exchangeDir = System.getProperty("java.io.tmpdir");
if (!exchangeDir.endsWith(System.getProperty("file.separator"))) {
exchangeDir += System.getProperty("file.separator");
}
} else {
exchangeDir = "/tmp/";
}
}
File productFile = new File(exchangeDir + "aceql-database-to-use.txt");
return productFile;
}
示例5: read
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
public static void read(File file, Consumer<File> handle) throws IOException {
Path temp;
if (SystemUtils.IS_OS_LINUX) {
temp = Files.createTempFile(SHARED_MEMORY, TEMP_PREFIX, null);
} else {
temp = Files.createTempFile(TEMP_PREFIX, null);
}
try (
InputStream is = new FileInputStream(file);
GZIPInputStream gis = new GZIPInputStream(is);
OutputStream os = Files.newOutputStream(temp);
) {
byte[] buffer = new byte[1024];
int length;
while ((length = gis.read(buffer, 0, 1024)) != -1) {
os.write(buffer, 0, length);
}
handle.accept(temp.toFile());
} finally {
Files.delete(temp);
}
}
示例6: deleteRecursively
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
/**
* Delete a file or directory and its contents recursively.
* Don't follow directories if they are symlinks.
*
* @param file Input file / dir to be deleted
* @throws IOException if deletion is unsuccessful
*/
public static void deleteRecursively(File file) throws IOException {
if (file == null) { return; }
// On Unix systems, use operating system command to run faster
// If that does not work out, fallback to the Java IO way
if (SystemUtils.IS_OS_UNIX) {
try {
deleteRecursivelyUsingUnixNative(file);
return;
} catch (IOException e) {
logger.warn("Attempt to delete using native Unix OS command failed for path = {}. " +
"Falling back to Java IO way", file.getAbsolutePath(), e);
}
}
deleteRecursivelyUsingJavaIO(file);
}
示例7: getModules
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
public List<CarnotzetModule> getModules() {
if (modules == null) {
modules = resolver.resolve(config.getTopLevelModuleId(), failOnDependencyCycle);
if (SystemUtils.IS_OS_LINUX || !getResourcesFolder().resolve("expanded-jars").toFile().exists()) {
resourceManager.extractResources(modules);
modules = computeServiceIds(modules);
resourceManager.resolveResources(modules);
}
log.debug("configuring modules");
modules = configureModules(modules);
if (config.getExtensions() != null) {
for (CarnotzetExtension feature : config.getExtensions()) {
log.debug("Extension [{}] enabled", feature.getClass().getSimpleName());
modules = feature.apply(this);
}
}
assertNoDuplicateArtifactId(modules);
modules = selectModulesForUniqueServiceId(modules);
}
return modules;
}
示例8: getSensor
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
public static Sensor getSensor() {
if (SystemUtils.IS_OS_WINDOWS) {
return new WindowsSensor();
} else if (SystemUtils.IS_OS_LINUX) {
return new LMSensor();
} else {
System.err.println(SystemUtils.OS_NAME + " is not a supported operating system.");
return new Sensor() {
@Override
public void poll() throws IOException {
temperatures.put("Fake 0", 0d);
temperatures.put("Fake 100", 100d);
}
};
}
}
示例9: solve
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
@Override
public Solution solve(final Board board, final Configuration configuration) throws SolutionException {
LOG.traceEntry("solve(board={}, configuration={})", board, configuration);
LOG.debug("Attempting serial solve for board:{}{}", SystemUtils.LINE_SEPARATOR, board);
for (final Move move : board.getAvailableMoves()) {
try {
final Solution solution = new SolutionSearch(configuration, move).search();
LOG.debug("Found solution:{}{}", SystemUtils.LINE_SEPARATOR, solution);
return LOG.traceExit(solution);
} catch (SolutionException e) {
// Ignore failed solution
}
}
LOG.debug("No solution found");
return LOG.traceExit(new Solution(configuration));
}
示例10: solve
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
public Solution solve(final Board board) throws BrickPopSolverException {
LOG.traceEntry("solve(board={})", board);
Objects.requireNonNull(board, "board");
LOG.info("Solving board: {}", board);
final SolutionService solutionService = configuration.getSolutionService();
final Instant start = Instant.now();
final Solution solution = solutionService.solve(board, configuration);
final Instant end = Instant.now();
if (solution.isEmpty()) {
throw new SolutionException("No solution could be found");
}
LOG.info("Found a solution in {} seconds:{}{}", () -> Duration.between(start, end).getSeconds(), () -> SystemUtils.LINE_SEPARATOR, () -> solution);
return LOG.traceExit(solution);
}
示例11: init
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
@PostConstruct
public void init() {
if (SystemUtils.IS_OS_LINUX) {
usersPath = environment.getProperty("image.path.linux.users");
formsPath = environment.getProperty("image.path.linux.forms");
} else if (SystemUtils.IS_OS_MAC) {
usersPath = environment.getProperty("image.path.mac.users");
formsPath = environment.getProperty("image.path.mac.forms");
} else if (SystemUtils.IS_OS_WINDOWS) {
usersPath = environment.getProperty("image.path.windows.users");
formsPath = environment.getProperty("image.path.windows.forms");
}
userContext = environment.getProperty("image.context.user");
formContext = environment.getProperty("image.context.form");
}
示例12: setOnScrollListener
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
/**
* Enables handling of scroll and mouse wheel events for the node.
* This type of events has a peculiarity on Windows. See the javadoc of notifyScrollEvents for more information.
* @see #notifyScrollEvent
* @param intersectionTestFunc a function that takes an event object and must return boolean
* @return itself to let you use a chain of calls
*/
MouseEventNotificator setOnScrollListener(Function<NativeMouseWheelEvent, Boolean> intersectionTestFunc) {
if (SystemUtils.IS_OS_WINDOWS) {
if (!GlobalScreen.isNativeHookRegistered()) {
try {
GlobalScreen.registerNativeHook();
} catch (NativeHookException | UnsatisfiedLinkError e) {
e.printStackTrace();
Main.log("Failed to initialize the native hooking. Rolling back to using JavaFX events...");
sender.addEventFilter(ScrollEvent.SCROLL, this::notifyScrollEvent);
return this;
}
}
mouseWheelListener = event -> notifyScrollEvent(event, intersectionTestFunc);
GlobalScreen.addNativeMouseWheelListener(mouseWheelListener);
} else {
sender.addEventFilter(ScrollEvent.SCROLL, this::notifyScrollEvent);
}
return this;
}
示例13: getSteamDir
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
public static File getSteamDir() throws RegistryException, IOException {
if (null == steamDir) {
if(SystemUtils.IS_OS_WINDOWS) {
steamDir = test(new File(WindowsRegistry.getInstance().readString(HKey.HKCU, "Software\\Valve\\Steam", "SteamPath")));
} else if(SystemUtils.IS_OS_MAC) {
steamDir = test(new File(SystemUtils.getUserHome()+"/Library/Application Support/Steam"));
} else if(SystemUtils.IS_OS_LINUX) {
ArrayList<File> fl = new ArrayList<>();
fl.add(new File(SystemUtils.getUserHome()+"/.steam/steam"));
fl.add(new File(SystemUtils.getUserHome()+"/.steam/Steam"));
fl.add(new File(SystemUtils.getUserHome()+"/.local/share/steam"));
fl.add(new File(SystemUtils.getUserHome()+"/.local/share/Steam"));
steamDir = test(fl);
}
}
return steamDir;
}
示例14: diaplayWarnForDetach
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
private void diaplayWarnForDetach(JFrame parent) {
if (Config.instance().to().getBoolean(Config.Entry.WARN_ON_OSX_TO_DETACH.key(), SystemUtils.IS_OS_MAC_OSX)) {
if (planTowerSensor.isConnected()) {
JOptionPane.showMessageDialog(parent,
"<html>The sensor is still attached.<br><br>" +
"This instance or the next start of the application may <b>hang</b><br>" +
"when the device is still attached while app or port is being closed.<br>" +
"<b>In such a case only reboot helps.</b><br><br>" +
"This behavior is being observed when using some cheap PL2303<br>" +
"uart-to-usb and their drivers.<br><br>" +
"You can now forcibly detach the device now.<br><br>" +
"Press OK to continue closing.</html>",
"Warning", JOptionPane.WARNING_MESSAGE);
}
}
}
示例15: setLookAndFeel
import org.apache.commons.lang3.SystemUtils; //导入依赖的package包/类
private static void setLookAndFeel() {
if (SystemUtils.IS_OS_MAC_OSX) {
// must be before any AWT interaction
System.setProperty("apple.laf.useScreenMenuBar", "true"); // place menubar (if any) in native menu bar
System.setProperty("apple.awt.application.name", Constants.PROJECT_NAME);
if (Config.instance().to().getBoolean(Config.Entry.SYSTEM_TRAY.key(), Constants.SYSTEM_TRAY)) {
logger.debug("Hiding dock icon since system-tray integration is enabled");
System.setProperty("apple.awt.UIElement", "true");
}
}
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
logger.error("Ooops, problem setting system L&F", e);
}
}