當前位置: 首頁>>代碼示例>>Java>>正文


Java SystemUtils類代碼示例

本文整理匯總了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);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:21,代碼來源:TestSharedFileDescriptorFactory.java

示例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();
    }
}
 
開發者ID:testcontainers,項目名稱:testcontainers-java,代碼行數:17,代碼來源:SimpleMySQLTest.java

示例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);
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:27,代碼來源:Prefs.java

示例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;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:25,代碼來源:FileChooser.java

示例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;
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:17,代碼來源:FallbackImageTypeConverter.java

示例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);
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:21,代碼來源:MemoryUtilsTest.java

示例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();
}
 
開發者ID:jonfryd,項目名稱:tifoon,代碼行數:23,代碼來源:DockerExecutorPlugin.java

示例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();
    }
}
 
開發者ID:testcontainers,項目名稱:testcontainers-java-module-mariadb,代碼行數:17,代碼來源:SimpleMariaDBTest.java

示例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();
    });
}
 
開發者ID:petrleocompel,項目名稱:docker-dash,代碼行數:31,代碼來源:DockerConnectionService.java

示例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" });
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:22,代碼來源:TestExecSource.java

示例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>&quot;&nbsp;&nbsp;&nbsp;at&quot;.</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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:ExceptionUtils.java

示例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();
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:19,代碼來源:VersionInfo.java

示例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);
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:24,代碼來源:StreamCopier.java

示例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;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestEnhancedByteBufferAccess.java

示例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;
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:18,代碼來源:H2JdbcDataSourceFactory.java


注:本文中的org.apache.commons.lang.SystemUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。