本文整理汇总了Java中org.apache.commons.lang.SystemUtils类的典型用法代码示例。如果您正苦于以下问题:Java SystemUtils类的具体用法?Java SystemUtils怎么用?Java SystemUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SystemUtils类属于org.apache.commons.lang包,在下文中一共展示了SystemUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCleanupRemainders
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
@Test(timeout=10000)
public void testCleanupRemainders() throws Exception {
Assume.assumeTrue(NativeIO.isAvailable());
Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
File path = new File(TEST_BASE, "testCleanupRemainders");
path.mkdirs();
String remainder1 = path.getAbsolutePath() +
Path.SEPARATOR + "woot2_remainder1";
String remainder2 = path.getAbsolutePath() +
Path.SEPARATOR + "woot2_remainder2";
createTempFile(remainder1);
createTempFile(remainder2);
SharedFileDescriptorFactory.create("woot2_",
new String[] { path.getAbsolutePath() });
// creating the SharedFileDescriptorFactory should have removed
// the remainders
Assert.assertFalse(new File(remainder1).exists());
Assert.assertFalse(new File(remainder2).exists());
FileUtil.fullyDelete(path);
}
示例2: testMySQLWithCustomIniFile
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
@Test
public void testMySQLWithCustomIniFile() throws SQLException {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
MySQLContainer mysqlCustomConfig = new MySQLContainer("mysql:5.6")
.withConfigurationOverride("somepath/mysql_conf_override");
mysqlCustomConfig.start();
try {
ResultSet resultSet = performQuery(mysqlCustomConfig, "SELECT @@GLOBAL.innodb_file_format");
String result = resultSet.getString(1);
assertEquals("The InnoDB file format has been set by the ini file content", "Barracuda", result);
} finally {
mysqlCustomConfig.stop();
}
}
示例3: initSharedGlobalPrefs
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
/**
* Initialize visible Global Preferences that are shared between the
* Module Manager and the Editor/Player.
*
*/
public static void initSharedGlobalPrefs() {
getGlobalPrefs();
// Option to disable D3D pipeline
if (SystemUtils.IS_OS_WINDOWS) {
final BooleanConfigurer d3dConf = new BooleanConfigurer(
DISABLE_D3D,
Resources.getString("Prefs.disable_d3d"),
Boolean.FALSE
);
globalPrefs.addOption(d3dConf);
}
final BooleanConfigurer wizardConf = new BooleanConfigurer(
WizardSupport.WELCOME_WIZARD_KEY,
Resources.getString("WizardSupport.ShowWizard"),
Boolean.TRUE
);
globalPrefs.addOption(wizardConf);
}
示例4: createFileChooser
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
/**
* Creates a FileChooser appropriate for the user's OS.
*
* @param parent
* The Component over which the FileChooser should appear.
* @param prefs
* A FileConfigure that stores the preferred starting directory of the FileChooser in preferences
*/
public static FileChooser createFileChooser(Component parent, DirectoryConfigurer prefs, int mode) {
FileChooser fc;
if (SystemUtils.IS_OS_MAC_OSX) {
// Mac has a good native file dialog
fc = new NativeFileChooser(parent, prefs, mode);
}
else if (mode == FILES_ONLY && SystemUtils.IS_OS_WINDOWS) {
// Window has a good native file dialog, but it doesn't support selecting directories
fc = new NativeFileChooser(parent, prefs, mode);
}
else {
// Linux's native dialog is inferior to Swing's
fc = new SwingFileChooser(parent, prefs, mode);
}
return fc;
}
示例5: tryConvertingInMemory
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
private boolean tryConvertingInMemory(Reference<BufferedImage> ref) {
/*
* Having an OutOfMemoryException while converting in memory is
* apparently catastrophic on Apple's Java 6 JVM (and possibly also
* on their Java 5 JVM as well). In-memory tiling also uses far more
* memory than it should on Apple's Java 6 JVM due to
* Graphics2D.drawImage making an intermediate copy of the image data.
* Hence, we ensure that when using Java 5 or 6 on Mac OS X, we never
* try in-memory conversion for images which can't comfortably have
* three copies existing simultaneously in memory.
*/
return !SystemUtils.IS_OS_MAC_OSX ||
(!SystemUtils.IS_JAVA_1_6 && !SystemUtils.IS_JAVA_1_5) ||
4*ref.obj.getHeight()*ref.obj.getWidth() <=
Runtime.getRuntime().maxMemory()/4;
}
示例6: testGetPhysicalMemoryUNIX
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
@Test
public void testGetPhysicalMemoryUNIX() throws IOException {
assumeTrue(SystemUtils.IS_OS_UNIX);
// get the total RAM from the system, in kB
final Process p = Runtime.getRuntime().exec(new String[] {
"sh",
"-c",
"grep '^MemTotal:' /proc/meminfo | sed 's/[^0-9]//g'"
});
final BufferedReader r =
new BufferedReader(new InputStreamReader(p.getInputStream()));
final int eRAM = Integer.parseInt(r.readLine());
r.close();
// check that it's correct
assertEquals(eRAM, MemoryUtils.getPhysicalMemory() >> 10);
}
示例7: getDockerClient
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
private DockerClient getDockerClient() {
/*
TLS connection: ...
DefaultDockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://192.168.99.100:2376")
.withDockerTlsVerify(true)
.withDockerCertPath("/Users/jon/.docker/machine/machines/default")
.build();
*/
final String localDockerHost = SystemUtils.IS_OS_WINDOWS ? "tcp://localhost:2375" : "unix:///var/run/docker.sock";
final DefaultDockerClientConfig config = DefaultDockerClientConfig
.createDefaultConfigBuilder()
.withDockerHost(localDockerHost)
.build();
return DockerClientBuilder
.getInstance(config)
.build();
}
示例8: testMariaDBWithCustomIniFile
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
@Test
public void testMariaDBWithCustomIniFile() throws SQLException {
assumeFalse(SystemUtils.IS_OS_WINDOWS);
MariaDBContainer mariadbCustomConfig = new MariaDBContainer("mariadb:10.1.16")
.withConfigurationOverride("somepath/mariadb_conf_override");
mariadbCustomConfig.start();
try {
ResultSet resultSet = performQuery(mariadbCustomConfig, "SELECT @@GLOBAL.innodb_file_format");
String result = resultSet.getString(1);
assertEquals("The InnoDB file format has been set by the ini file content", "Barracuda", result);
} finally {
mariadbCustomConfig.stop();
}
}
示例9: getDefaultConnection
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
/**
* TODO delete and make method with serverId param after thinking about it
*
* @return default connection to system docker
*/
public DockerClient getDefaultConnection() {
return connections.computeIfAbsent(DEFAULT_CONNECTION, id -> {
DockerClientConfig config = null;
if (SystemUtils.IS_OS_MAC_OSX) {
config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("unix:///var/run/docker.sock")
.build();
}
if (SystemUtils.IS_OS_LINUX) {
config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("unix:///var/run/docker.sock")
.build();
}
if (SystemUtils.IS_OS_WINDOWS) {
config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://localhost:2376")
.withDockerTlsVerify(true)
.withDockerTlsVerify("1")
.build();
}
return DockerClientBuilder.getInstance(config).build();
});
}
示例10: testShellCommandScript
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
@Test
public void testShellCommandScript() throws InterruptedException, LifecycleException,
EventDeliveryException, IOException {
// mini script
if (SystemUtils.IS_OS_WINDOWS) {
runTestShellCmdHelper("powershell -ExecutionPolicy Unrestricted -command",
"foreach ($i in 1..5) { $i }",
new String[] { "1", "2", "3", "4", "5" });
// shell arithmetic
runTestShellCmdHelper("powershell -ExecutionPolicy Unrestricted -command",
"if(2+2 -gt 3) { 'good' } else { 'not good' } ",
new String[] { "good" });
} else {
runTestShellCmdHelper("/bin/bash -c", "for i in {1..5}; do echo $i;done",
new String[] { "1", "2", "3", "4", "5" });
// shell arithmetic
runTestShellCmdHelper("/bin/bash -c",
"if ((2+2>3)); " + "then echo good; else echo not good; fi",
new String[] { "good" });
}
}
示例11: getStackFrameList
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
/**
* <p>Produces a <code>List</code> of stack frames - the message
* is not included. Only the trace of the specified exception is
* returned, any caused by trace is stripped.</p>
*
* <p>This works in most cases - it will only fail if the exception
* message contains a line that starts with:
* <code>" at".</code></p>
*
* @param t is any throwable
* @return List of stack frames
*/
static List getStackFrameList(Throwable t) {
String stackTrace = getStackTrace(t);
String linebreak = SystemUtils.LINE_SEPARATOR;
StringTokenizer frames = new StringTokenizer(stackTrace, linebreak);
List list = new ArrayList();
boolean traceStarted = false;
while (frames.hasMoreTokens()) {
String token = frames.nextToken();
// Determine if the line starts with <whitespace>at
int at = token.indexOf("at");
if (at != -1 && token.substring(0, at).trim().length() == 0) {
traceStarted = true;
list.add(token);
} else if (traceStarted) {
break;
}
}
return list;
}
示例12: getBuildVersion
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
/**
* Returns the buildVersion which includes version, revision, user and date.
*/
public static String getBuildVersion() {
StringBuilder buf = new StringBuilder();
buf.append(SystemUtils.LINE_SEPARATOR);
buf.append("[OTTER Version Info]").append(SystemUtils.LINE_SEPARATOR);
buf.append("[version ]").append(VersionInfo.getVersion()).append(SystemUtils.LINE_SEPARATOR);
buf.append("[revision]").append(VersionInfo.getRevision()).append(SystemUtils.LINE_SEPARATOR);
buf.append("[compiler]").append(VersionInfo.getUser()).append(SystemUtils.LINE_SEPARATOR);
buf.append("[date ]").append(VersionInfo.getDate()).append(SystemUtils.LINE_SEPARATOR);
buf.append("[checksum]").append(VersionInfo.getSrcChecksum()).append(SystemUtils.LINE_SEPARATOR);
buf.append("[branch ]").append(VersionInfo.getBranch()).append(SystemUtils.LINE_SEPARATOR);
buf.append("[url ]").append(VersionInfo.getUrl()).append(SystemUtils.LINE_SEPARATOR);
return buf.toString();
}
示例13: run
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
public void run() {
try {
StringBuffer buf = new StringBuffer();
String line = null;
while ((line = reader.readLine()) != null) {
if (identifier != null) {
line = identifier + line;
}
if (false == StringUtils.isBlank(line)) {
buf.append(line).append(SystemUtils.LINE_SEPARATOR);
}
}
out.write(buf.toString().getBytes());
out.flush();
} catch (IOException ioe) {
//ignore
} finally {
IOUtils.closeQuietly(reader);
}
}
示例14: initZeroCopyTest
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
public static HdfsConfiguration initZeroCopyTest() {
Assume.assumeTrue(NativeIO.isAvailable());
Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
HdfsConfiguration conf = new HdfsConfiguration();
conf.setBoolean(DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_KEY, true);
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE);
conf.setInt(DFSConfigKeys.DFS_CLIENT_MMAP_CACHE_SIZE, 3);
conf.setLong(DFSConfigKeys.DFS_CLIENT_MMAP_CACHE_TIMEOUT_MS, 100);
conf.set(DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_KEY,
new File(sockDir.getDir(),
"TestRequestMmapAccess._PORT.sock").getAbsolutePath());
conf.setBoolean(DFSConfigKeys.
DFS_CLIENT_READ_SHORTCIRCUIT_SKIP_CHECKSUM_KEY, true);
conf.setLong(DFS_HEARTBEAT_INTERVAL_KEY, 1);
conf.setLong(DFS_CACHEREPORT_INTERVAL_MSEC_KEY, 1000);
conf.setLong(DFS_NAMENODE_PATH_BASED_CACHE_REFRESH_INTERVAL_MS, 1000);
return conf;
}
示例15: getUrlUncached
import org.apache.commons.lang.SystemUtils; //导入依赖的package包/类
public static String getUrlUncached(String dbName, boolean persistToFile) {
Validate.notNull(dbName, "dbName parameter must be specified");
String url;
if (persistToFile) {
// In order to allow access to the db from multiple processes, the FILE_LOCK=NO setting is needed.
// This however, does not prevent concurrency issues from multiple writers.
// Other options found in the docs that we are not using: MVCC=TRUE;FILE_LOCK=SERIALIZED
String dbFileName = new File(SystemUtils.getJavaIoTmpDir(), dbName).getAbsolutePath();
LOG.info("writing db to file:{}", dbFileName);
url = String.format("jdbc:h2:file:%s;FILE_LOCK=NO", dbFileName);
} else {
// use DB_CLOSE_DELAY=-1 to keep the DB open for the duration of the JVM
url = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1", dbName);
}
LOG.info("setting up in memory db: {}", url);
return url;
}