当前位置: 首页>>代码示例>>Java>>正文


Java Redirect.appendTo方法代码示例

本文整理汇总了Java中java.lang.ProcessBuilder.Redirect.appendTo方法的典型用法代码示例。如果您正苦于以下问题:Java Redirect.appendTo方法的具体用法?Java Redirect.appendTo怎么用?Java Redirect.appendTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.ProcessBuilder.Redirect的用法示例。


在下文中一共展示了Redirect.appendTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRedirect

import java.lang.ProcessBuilder.Redirect; //导入方法依赖的package包/类
/**
 * Returns a {@link java.lang.ProcessBuilder.Redirect} appropriate for the parameters. If a file
 * redirected to exists, deletes the file before redirecting to it.
 */
private Redirect getRedirect(StreamAction action, File file) {
  switch (action) {
    case DISCARD:
      return Redirect.to(new File("/dev/null"));

    case REDIRECT:
      // We need to use Redirect.appendTo() here, because on older Linux kernels writes are
      // otherwise not atomic and might result in lost log messages:
      // https://lkml.org/lkml/2014/3/3/308
      if (file.exists()) {
        file.delete();
      }
      return Redirect.appendTo(file);

    case STREAM:
      return Redirect.PIPE;

    default:
      throw new IllegalStateException();
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:26,代码来源:JavaSubprocessFactory.java

示例2: check

import java.lang.ProcessBuilder.Redirect; //导入方法依赖的package包/类
/**
 * check - tests to see if the current token contains a redirect
 * @param token    current command line token
 * @param iterator current command line iterator
 * @param cwd      current working directory
 * @return true if token is consumed
 */
boolean check(String token, final Iterator<String> iterator, final String cwd) {
    // Iterate through redirect prefixes to file a match.
    for (int i = 0; i < redirectPrefixes.length; i++) {
       final String prefix = redirectPrefixes[i];

       // If a match is found.
        if (token.startsWith(prefix)) {
            // Indicate we have at least one redirect (efficiency.)
            hasRedirects = true;
            // Map prefix to RedirectType.
            final RedirectType redirect = redirects[i];
            // Strip prefix from token
            token = token.substring(prefix.length());

            // Get file from either current or next token.
            File file = null;
            if (redirect != REDIRECT_ERROR_TO_OUTPUT) {
                // Nothing left of current token.
                if (token.length() == 0) {
                    if (iterator.hasNext()) {
                        // Use next token.
                        token = iterator.next();
                    } else {
                        // Send to null device if not provided.
                        token = IS_WINDOWS ? "NUL:" : "/dev/null";
                    }
                }

                // Redirect file.
                file = resolvePath(cwd, token).toFile();
            }

            // Define redirect based on prefix.
            switch (redirect) {
                case REDIRECT_INPUT:
                    inputRedirect = Redirect.from(file);
                    break;
                case REDIRECT_OUTPUT:
                    outputRedirect = Redirect.to(file);
                    break;
                case REDIRECT_OUTPUT_APPEND:
                    outputRedirect = Redirect.appendTo(file);
                    break;
                case REDIRECT_ERROR:
                    errorRedirect = Redirect.to(file);
                    break;
                case REDIRECT_ERROR_APPEND:
                    errorRedirect = Redirect.appendTo(file);
                    break;
                case REDIRECT_OUTPUT_ERROR_APPEND:
                    outputRedirect = Redirect.to(file);
                    errorRedirect = Redirect.to(file);
                    mergeError = true;
                    break;
                case REDIRECT_ERROR_TO_OUTPUT:
                    mergeError = true;
                    break;
                default:
                    return false;
            }

            // Indicate token is consumed.
            return true;
        }
    }

    // No redirect found.
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:77,代码来源:CommandExecutor.java

示例3: check

import java.lang.ProcessBuilder.Redirect; //导入方法依赖的package包/类
/**
 * check - tests to see if the current token contains a redirect
 * @param token    current command line token
 * @param iterator current command line iterator
 * @param cwd      current working directory
 * @return true if token is consumed
 */
boolean check(String token, final Iterator<String> iterator, final String cwd) {
    // Iterate through redirect prefixes to file a match.
    for (int i = 0; i < redirectPrefixes.length; i++) {
       String prefix = redirectPrefixes[i];

       // If a match is found.
        if (token.startsWith(prefix)) {
            // Indicate we have at least one redirect (efficiency.)
            hasRedirects = true;
            // Map prefix to RedirectType.
            RedirectType redirect = redirects[i];
            // Strip prefix from token
            token = token.substring(prefix.length());

            // Get file from either current or next token.
            File file = null;
            if (redirect != REDIRECT_ERROR_TO_OUTPUT) {
                // Nothing left of current token.
                if (token.length() == 0) {
                    if (iterator.hasNext()) {
                        // Use next token.
                        token = iterator.next();
                    } else {
                        // Send to null device if not provided.
                        token = IS_WINDOWS ? "NUL:" : "/dev/null";
                    }
                }

                // Redirect file.
                file = resolvePath(cwd, token).toFile();
            }

            // Define redirect based on prefix.
            switch (redirect) {
                case REDIRECT_INPUT:
                    inputRedirect = Redirect.from(file);
                    break;
                case REDIRECT_OUTPUT:
                    outputRedirect = Redirect.to(file);
                    break;
                case REDIRECT_OUTPUT_APPEND:
                    outputRedirect = Redirect.appendTo(file);
                    break;
                case REDIRECT_ERROR:
                    errorRedirect = Redirect.to(file);
                    break;
                case REDIRECT_ERROR_APPEND:
                    errorRedirect = Redirect.appendTo(file);
                    break;
                case REDIRECT_OUTPUT_ERROR_APPEND:
                    outputRedirect = Redirect.to(file);
                    errorRedirect = Redirect.to(file);
                    mergeError = true;
                    break;
                case REDIRECT_ERROR_TO_OUTPUT:
                    mergeError = true;
                    break;
                default:
                    return false;
            }

            // Indicate token is consumed.
            return true;
        }
    }

    // No redirect found.
    return false;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:77,代码来源:CommandExecutor.java

示例4: parseUri

import java.lang.ProcessBuilder.Redirect; //导入方法依赖的package包/类
/**
 * Parses the given URI into a new {@link Redirect}. The URI is supposed to start with one of {@link RedirectScheme}
 * prefixes. Examples of valid valid URIs: {@code read:/path/to/input-file.txt}, {@code write:/path/to/log.txt},
 * {@code append:/path/to/log.txt}, {@code inherit} {@code err2out}.
 *
 * @param uri
 *            the URI to parse
 * @return a new {@link Redirect}
 * @throws IllegalArgumentException
 *             if the given {@code uri} is not in proper format
 */
public static Redirect parseUri(String uri) {
    SrcdepsCoreUtils.assertArgNotNull(uri, "uri");
    SrcdepsCoreUtils.assertArgNotEmptyString(uri, "uri");

    int pos = uri.indexOf(':');

    switch (pos) {
    case -1:
        pos = uri.length();
        break;
    case 0:
        throw new IllegalArgumentException(String.format("Colon found at position 0 of URI string [%s]", uri));
    default:
        break;
    }

    final String redirectScheme = uri.substring(0, pos).toLowerCase(Locale.US);
    final RedirectScheme scheme = RedirectScheme.valueOf(redirectScheme);

    pos++;
    final String path = pos < uri.length() ? uri.substring(pos) : null;

    switch (scheme) {
    case err2out:
        if (path != null) {
            throw new IllegalArgumentException(
                    String.format("Unexpected characters found after [err2out] in [%s]", uri));
        }
        return null;
    case read:
        return Redirect.from(new File(path));
    case write:
        return Redirect.to(new File(path));
    case append:
        return Redirect.appendTo(new File(path));
    case inherit:
        if (path != null) {
            throw new IllegalArgumentException(
                    String.format("Unexpected characters found after [inherit] in [%s]", uri));
        }
        return Redirect.INHERIT;
    default:
        throw new IllegalStateException(String.format(
                "Unexpected redirect type [%s] in redirect URI [%s] only [read], [write], [append], [inherit] are supported. In addition, you can use [err2out] for the error stream",
                redirectScheme, uri));
    }
}
 
开发者ID:srcdeps,项目名称:srcdeps-core,代码行数:59,代码来源:IoRedirects.java

示例5: execute

import java.lang.ProcessBuilder.Redirect; //导入方法依赖的package包/类
@Override
public void execute() throws MojoExecutionException {
  //
  // Say hello to the world, my little constructor injected component!
  //
  //component.hello();

  final List<String> command = new ArrayList<>();
  command.add(getCanonicalPath(_execLocation, "exec"));

  getLog().debug(String.format("args=%s", _args));

  if (!_args.isEmpty()) {
    command.addAll(_args);
  }

  if (!_fileSets.isEmpty()) {
    getLog().debug(String.format("fileSets=%s", _fileSets));
    quoteList(getResourceFiles(_fileSets, _followLinks, _allowDuplicates, _allowFiles, 
        _allowDirs), 
        command);
  }

  if (_systemCommand) {
    convertToSystemCommandArgs(command, _argQuote);
  }

  getLog().debug(String.format("command=%s", command));
  Redirect errorRedirect;

  // if (!getCanonicalPath(_errorFile, "_errorFile").isEmpty()) {
  if (_errorFile != null) {
    _errorFile = getCanonicalFile(_errorFile, "_errorFile");
    errorRedirect = _errorAppend ? Redirect.appendTo(_errorFile) : Redirect.to(_errorFile);
  } else if (!_errorProperty.isEmpty()) {
    throw new MojoExecutionException("_errorProperty currently unsupported");
  } else if (_errorInherit) {
    errorRedirect = Redirect.INHERIT;
  } else if (_errorPipe) {
    errorRedirect = Redirect.PIPE;
  } else {
    throw new MojoExecutionException(
        "must specify one of these: _errorProperty, _errorFile, _errorPipe, _errorInherit");
  }

  Redirect outRedirect;

  // if (!getCanonicalPath(_outFile, "_outFile").isEmpty()) {
  if (_outFile != null) {
    _outFile = getCanonicalFile(_outFile, "_outFile");
    outRedirect = _outAppend ? Redirect.appendTo(_outFile) : Redirect.to(_outFile);
  } else if (_outInherit) {
    outRedirect = Redirect.INHERIT;
  } else if (_outPipe) {
    outRedirect = Redirect.PIPE;
  } else if (!_outProperty.isEmpty()) {
    throw new MojoExecutionException("_outProperty currently unsupported");
  } else {
    throw new MojoExecutionException(
        "must specify one of these: _outProperty, _outFile, _outPipe, _outInherit");
  }

  _exitCode =
      createProcess(command, errorRedirect, outRedirect, _workDir, _environment,
          _redirectErrorStream);
}
 
开发者ID:protobufel,项目名称:protobuf-el,代码行数:67,代码来源:ExecMojo.java

示例6: exec

import java.lang.ProcessBuilder.Redirect; //导入方法依赖的package包/类
/**
 * Runs the process redirecting both its error and output streams to the
 * specified file.
 * @param outputFile the file to redirect the process's streams to.
 * @return the process's exit status.
 * @throws IOException if an I/O error occurs while running the process.
 * @throws InterruptedException if the current thread is interrupted before 
 * the spawned process terminates.
 */
public int exec(Path outputFile) throws IOException, InterruptedException {
    requireNonNull(outputFile, "outputFile");

    Redirect withOutputFile = Redirect.appendTo(outputFile.toFile());
    return startProcess(withOutputFile).waitFor();
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:16,代码来源:CommandRunner.java


注:本文中的java.lang.ProcessBuilder.Redirect.appendTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。