org.apache.brooklyn.util.os.Os.isMicrosoftWindows()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中org.apache.brooklyn.util.os.Os.isMicrosoftWindows()方法的一些代码示例,展示了Os.isMicrosoftWindows()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Os.isMicrosoftWindows()方法的具体详情如下:
包路径:org.apache.brooklyn.util.os.Os
类名称:Os
方法名:isMicrosoftWindows

Os.isMicrosoftWindows介绍

暂无

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public static void copyDir(File srcDir, File destDir) throws IOException, InterruptedException {
  if (!Os.isMicrosoftWindows()) {
    String cmd = "cp -R '"+srcDir.getAbsolutePath()+"' '"+destDir.getAbsolutePath()+"'";
    Process proc = Runtime.getRuntime().exec(cmd);
    proc.waitFor();
    if (proc.exitValue() == 0) return;
  }
  
  FileUtils.copyDirectory(srcDir, destDir);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public static void moveDir(File srcDir, File destDir) throws IOException, InterruptedException {
  if (!Os.isMicrosoftWindows()) {
    String cmd = "mv '"+srcDir.getAbsolutePath()+"' '"+destDir.getAbsolutePath()+"'";
    Process proc = Runtime.getRuntime().exec(cmd);
    proc.waitFor();
    if (proc.exitValue() == 0) return;
  }
  
  FileUtils.moveDirectory(srcDir, destDir);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

private static void logSetFilePermissionsFailure(final String permissions, File file, IOException ex) {
  if (loggedSetFilePermissionsWarning) {
    if (LOG.isTraceEnabled()) LOG.trace("Failed to set permissions to {} for file {}: {}",
        new Object[] {permissions, file.getAbsolutePath(), ex});
  } else {
    if (Os.isMicrosoftWindows()) {
      if (LOG.isDebugEnabled()) LOG.debug("Failed to set permissions to {} for file {}; expected behaviour on Windows; {}; subsequent failures (on any file) will be logged at trace",
          new Object[] {permissions, file.getAbsolutePath(), ex});
    } else {
      LOG.warn("Failed to set permissions to {} for file {}: {}; subsequent failures (on any file) will be logged at trace",
          new Object[] {permissions, file.getAbsolutePath(), ex});
    }
    loggedSetFilePermissionsWarning = true;
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public void apply(File file) throws IOException {
  Path filePath = file.toPath();
  // the appropriate condition is actually Files.getFileStore(filePath).supportsFileAttributeView(PosixFileAttributeView.class)
  // but that downs performance to ~9000 calls per second
  boolean done = false;
  try {
    // ~59000 calls per sec
    if (!Os.isMicrosoftWindows()) {
      Files.setPosixFilePermissions(filePath, posixPermissions);
    }
    done = true;
  } catch (UnsupportedOperationException ex) {}
  
  if (!done) {
    // ~42000 calls per sec
    // TODO: what happens to group permissions ?
    boolean setRead = file.setReadable(posixPermissions.contains(OTHERS_READ), false) & file.setReadable(posixPermissions.contains(OWNER_READ), true);
    boolean setWrite = file.setWritable(posixPermissions.contains(OTHERS_WRITE), false) & file.setWritable(posixPermissions.contains(OWNER_WRITE), true);
    boolean setExec = file.setExecutable(posixPermissions.contains(OTHERS_EXECUTE), false) & file.setExecutable(posixPermissions.contains(OWNER_EXECUTE), true);
    if (!(setRead && setWrite && setExec)) {
      throw new IOException("setting file permissions failed: read=" + setRead + " write=" + setWrite + " exec=" + setExec);
    }
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

private List<String> getTestCommand() {
  if(Os.isMicrosoftWindows()) {
    return Arrays.asList("cmd", "/c", "echo", "hello", "world");
  } else {
    return Arrays.asList("echo", "hello", "world");
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

/**
 * This utility will be deleted when we move to Java 7
 * 
 * @return The file permission (in a form like "-rwxr--r--"), or null if the permissions could not be determined.
 */
@Beta
public static Maybe<String> getFilePermissions(File file) {
  if (!file.exists()) return Maybe.absent("File "+file+" does not exist");
  
  if (Os.isMicrosoftWindows()) {
    return Maybe.absent("Cannot determine permissions on windows");
  } else {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayOutputStream err = new ByteArrayOutputStream();
    int exitcode = exec(ImmutableList.of("ls", "-ld", file.getAbsolutePath()), out, err);
    if (exitcode != 0) {
      if (LOG.isDebugEnabled()) LOG.debug("Could not determine permissions of file "+file+"; exit code "+exitcode+"; stderr "+new String(err.toByteArray()));
      return Maybe.absent("Could not determine permission of file "+file+"; exit code "+exitcode);
    }
    String stdout = new String(out.toByteArray());
    return (stdout.trim().isEmpty() ? Maybe.<String>absent("empty output") : Maybe.of(stdout.split("\\s")[0]));
  }
}

相关文章