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


Java Command类代码示例

本文整理汇总了Java中org.apache.hadoop.fs.shell.Command的典型用法代码示例。如果您正苦于以下问题:Java Command类的具体用法?Java Command怎么用?Java Command使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Command类属于org.apache.hadoop.fs.shell包,在下文中一共展示了Command类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExceptionNullMessage

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
@Test
public void testExceptionNullMessage() throws Exception {
  final String cmdName = "-cmdExNullMsg";
  final Command cmd = Mockito.mock(Command.class);
  Mockito.when(cmd.run(Mockito.<String>anyVararg())).thenThrow(
      new IllegalArgumentException());
  Mockito.when(cmd.getUsage()).thenReturn(cmdName);

  final CommandFactory cmdFactory = Mockito.mock(CommandFactory.class);
  final String[] names = {cmdName};
  Mockito.when(cmdFactory.getNames()).thenReturn(names);
  Mockito.when(cmdFactory.getInstance(cmdName)).thenReturn(cmd);

  FsShell shell = new FsShell(new Configuration());
  shell.commandFactory = cmdFactory;
  try (GenericTestUtils.SystemErrCapturer capture =
           new GenericTestUtils.SystemErrCapturer()) {
    ToolRunner.run(shell, new String[]{cmdName});
    Assert.assertThat(capture.getOutput(),
        StringContains.containsString(cmdName
            + ": Null exception message"));
  }
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:24,代码来源:TestFsShell.java

示例2: displayError

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
private void displayError(String cmd, String message) {
  for (String line : message.split("\n")) {
    System.err.println(cmd + ": " + line);
    if (cmd.charAt(0) != '-') {
      Command instance = null;
      instance = commandFactory.getInstance("-" + cmd);
      if (instance != null) {
        System.err.println("Did you mean -" + cmd + "?  This command " +
            "begins with a dash.");
      }
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:14,代码来源:FsShell.java

示例3: printInstanceHelp

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
private void printInstanceHelp(PrintStream out, Command instance) {
  boolean firstLine = true;
  for (String line : instance.getDescription().split("\n")) {
    String prefix;
    if (firstLine) {
      prefix = instance.getUsage() + ":\t";
      firstLine = false;
    } else {
      prefix = "\t\t";
    }
    System.out.println(prefix + line);
  }    
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:14,代码来源:FsShell.java

示例4: getInstance

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
@Override
public Command getInstance(String cmd) {
    Command command = commandFactory.getInstance(cmd);
    command.err = this.err;
    command.out = this.out;
    return command;
}
 
开发者ID:intropro,项目名称:prairie,代码行数:8,代码来源:CommandFactoryWithIO.java

示例5: printInstanceUsage

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(getUsagePrefix() + " " + instance.getUsage());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:4,代码来源:FsShell.java

示例6: runCommand

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
String runCommand(String cmdName, String[] arguments)  {
        final Configuration conf = contextCommands.getConfiguration();

        cmdName = "-" + cmdName;
        final Command command = getCommandInstance(cmdName, conf);
        if (command == null) {
            return "Unknown command " + cmdName;
        }

        if (arguments.length == 0 && !NO_PARAMS_COMMANDS.contains(cmdName)) {
            return command.getDescription();
        }


        contextCommands.updateCurrentWorkingDirectory();

        arguments = replaceHdfsPath(arguments);
        final PrintStream printStream = ClientConnection.context.get();
        if (printStream != null) {
            command.err = printStream;
            command.out = printStream;
        }
//        final ByteArrayOutputStream out = new ByteArrayOutputStream();
//        final PrintStream printStream = new PrintStream(out);
//        command.err = printStream;
//        command.out = printStream;

        final int result = command.run(arguments);
        if (contextCommands.isShowResultCode()) {
            if (result == 0) {
                command.out.println("Exit code = " + result);
            } else {
                command.err.println("Exit code = " + result);
            }
        }

        //printStream.close();
        if (result != 0 && contextCommands.isFailOnError()) {
            throw new RuntimeException("HDFS Command finished with result code " + result);
        }
        return "";
    }
 
开发者ID:avast,项目名称:hdfs-shell,代码行数:43,代码来源:HadoopDfsCommands.java

示例7: getCommandInstance

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
private static Command getCommandInstance(String cmdName, Configuration conf) {
    final CommandFactory commandFactory = new CommandFactory(conf);
    FsCommand.registerCommands(commandFactory);
    return commandFactory.getInstance(cmdName, conf);
}
 
开发者ID:avast,项目名称:hdfs-shell,代码行数:6,代码来源:HadoopDfsCommands.java

示例8: printInstanceUsage

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
private void printInstanceUsage(PrintStream out, Command instance) {
  out.println(usagePrefix + " " + instance.getUsage());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:4,代码来源:FsShell.java

示例9: addClass

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
@Override
public void addClass(Class<? extends Command> cmdClass, String... names) {
    commandFactory.addClass(cmdClass, names);
}
 
开发者ID:intropro,项目名称:prairie,代码行数:5,代码来源:CommandFactoryWithIO.java

示例10: addObject

import org.apache.hadoop.fs.shell.Command; //导入依赖的package包/类
@Override
public void addObject(Command cmdObject, String... names) {
    commandFactory.addObject(cmdObject, names);
}
 
开发者ID:intropro,项目名称:prairie,代码行数:5,代码来源:CommandFactoryWithIO.java


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