コード例 #1
0
ファイル: SystemUtilTest.java プロジェクト: koem/Zimbra
 @Test
 public void coalesce() {
   Assert.assertEquals(1, (int) SystemUtil.coalesce(null, 1));
   Assert.assertEquals(null, SystemUtil.coalesce(null, null, null, null));
   Assert.assertEquals(2, (int) SystemUtil.coalesce(2, 3));
   Assert.assertEquals("good", SystemUtil.coalesce("good", "bad", "ugly"));
 }
コード例 #2
0
  /**
   * Extract the MP3 tags from a given mp3 file
   *
   * @param mp3File The MP3 file to get tags from
   * @return An Mp3IdInfo object if successfull or null otherwise
   */
  public static Mp3IdInfo extractMp3Info(File mp3File) {
    // try to find the mp3 extract script
    String mp3ExtractScript = SystemUtil.getTargetFilePath(MP3_EXTRACT_SCRIPT);
    // if the script can't be found just return null
    if (mp3ExtractScript == null) return null;

    List<String> cmds = new ArrayList<String>(0);
    cmds.add(PYTHON);
    cmds.add(mp3ExtractScript);
    cmds.add(mp3File.getPath());

    try {
      String mp3TagResult = SystemUtil.executeCmdGetReturn(cmds);
      return parseResult(mp3TagResult);
    } catch (IOException e) {
      // error durring extracting tags, ignore and return null
      return null;
    }
  }
コード例 #3
0
ファイル: CommandLineTest.java プロジェクト: qiaoliang/GoCD
 @Test
 public void shouldReturnEchoResult() throws Exception {
   if (SystemUtil.isWindows()) {
     ConsoleResult result = CommandLine.createCommandLine("cmd").runOrBomb(null);
     assertThat(result.outputAsString(), containsString("Windows"));
   } else {
     String expectedValue = "my input";
     ConsoleResult result =
         CommandLine.createCommandLine("echo").withArgs(expectedValue).runOrBomb(null);
     assertThat(result.outputAsString(), is(expectedValue));
   }
 }
コード例 #4
0
ファイル: ClassLoaderUtil.java プロジェクト: roywang1985/jodd
 /** Finds <b>tools.jar</b>. Returns <code>null</code> if does not exist. */
 public static File findToolsJar() {
   String tools =
       new File(SystemUtil.getJavaHome()).getAbsolutePath()
           + File.separatorChar
           + "lib"
           + File.separatorChar
           + "tools.jar";
   File toolsFile = new File(tools);
   if (toolsFile.exists()) {
     return toolsFile;
   }
   return null;
 }
コード例 #5
0
 private static void runExportScript() {
   String extractScript = configIni.get("Reindex", "extractScript");
   if (extractScript.length() > 0) {
     logger.info("Running export script");
     try {
       String reindexResult = SystemUtil.executeCommand(extractScript, logger);
       logger.info("Result of extractScript (" + extractScript + ") was " + reindexResult);
     } catch (IOException e) {
       logger.error("Error running extract script, stopping reindex process", e);
       System.exit(1);
     }
   }
 }
コード例 #6
0
ファイル: ClassLoaderUtil.java プロジェクト: oblac/jodd
  /**
   * Returns default class path from all available <code>URLClassLoader</code> in classloader
   * hierarchy. The following is added to the classpath list:
   *
   * <ul>
   *   <li>file URLs from <code>URLClassLoader</code> (other URL protocols are ignored)
   *   <li>inner entries from containing <b>manifest</b> files (if exist)
   *   <li>bootstrap classpath
   * </ul>
   */
  public static File[] getDefaultClasspath(ClassLoader classLoader) {
    Set<File> classpaths = new TreeSet<>();

    while (classLoader != null) {
      if (classLoader instanceof URLClassLoader) {
        URL[] urls = ((URLClassLoader) classLoader).getURLs();
        for (URL u : urls) {
          File f = FileUtil.toFile(u);
          if ((f != null) && f.exists()) {
            try {
              f = f.getCanonicalFile();

              boolean newElement = classpaths.add(f);
              if (newElement) {
                addInnerClasspathItems(classpaths, f);
              }
            } catch (IOException ignore) {
            }
          }
        }
      }
      classLoader = classLoader.getParent();
    }

    String bootstrap = SystemUtil.getSunBootClassPath();
    if (bootstrap != null) {
      String[] bootstrapFiles = StringUtil.splitc(bootstrap, File.pathSeparatorChar);
      for (String bootstrapFile : bootstrapFiles) {
        File f = new File(bootstrapFile);
        if (f.exists()) {
          try {
            f = f.getCanonicalFile();

            boolean newElement = classpaths.add(f);
            if (newElement) {
              addInnerClasspathItems(classpaths, f);
            }
          } catch (IOException ignore) {
          }
        }
      }
    }

    File[] result = new File[classpaths.size()];
    return classpaths.toArray(result);
  }
コード例 #7
0
  /**
   * Format one line of the image display.
   *
   * @param activity the triggering activity.
   * @param resource The resource containing the label of the line.
   * @param value The value of the parameter.
   * @return The formatted line.
   */
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private static String formatImageInfoLine(
      @NonNull final Activity activity, final int resource, @NonNull final String value) {
    StringBuilder line = new StringBuilder("<b>");
    line.append(activity.getString(resource));
    line.append("</b><br>");

    if (SystemUtil.isAtLeastVersion(Build.VERSION_CODES.JELLY_BEAN)) {
      // Workaround to escape html, but transfer line breaks to HTML
      line.append(
          Html.escapeHtml(value.replace("\n", "|||LINEBREAK|||"))
              .replace("|||LINEBREAK|||", "<br>"));
    } else {
      line.append(
          value
              .replace("&", "&amp;")
              .replace("\n", "<br>")
              .replace("<", "&lt;")
              .replace(">", "&gt;"));
    }

    line.append("<br><br>");
    return line.toString();
  }
コード例 #8
0
 /**
  * use {@link SystemUtil#isGlass()} instead
  *
  * @return
  */
 @Deprecated
 public static boolean isGlass() {
   return SystemUtil.isGlass();
 }