Java源码示例:org.springframework.shell.support.util.FileUtils
示例1
private String convertCompletionBackIntoUserInputStyle(
final String originalUserInput, final String completion) {
if (FileUtils.denotesAbsolutePath(originalUserInput)) {
// Input was originally as a fully-qualified path, so we just keep the
// completion in that form
return completion;
}
if (originalUserInput.startsWith(HOME_DIRECTORY_SYMBOL)) {
// Input originally started with this symbol, so replace the user's home
// directory with it again
Assert.notNull(home,
"Home directory could not be determined from system properties");
return HOME_DIRECTORY_SYMBOL + completion.substring(home.length());
}
// The path was working directory specific, so strip the working directory
// given the user never typed it
return completion.substring(getWorkingDirectoryAsString().length());
}
示例2
/**
* If the user input starts with a tilde character (~), replace the tilde
* character with the user's home directory. If the user input does not start
* with a tilde, simply return the original user input without any changes if
* the input specifies an absolute path, or return an absolute path based on
* the working directory if the input specifies a relative path.
*
* @param userInput
* the user input, which may commence with a tilde (required)
* @return a string that is guaranteed to no longer contain a tilde as the
* first character (never null)
*/
private String convertUserInputIntoAFullyQualifiedPath(final String userInput) {
if (FileUtils.denotesAbsolutePath(userInput)) {
// Input is already in a fully-qualified path form
return userInput;
}
if (userInput.startsWith(HOME_DIRECTORY_SYMBOL)) {
// Replace this symbol with the user's actual home directory
Assert.notNull(home,
"Home directory could not be determined from system properties");
if (userInput.length() > 1) {
return home + userInput.substring(1);
}
}
// The path is working directory specific, so prepend the working directory
String fullPath = getWorkingDirectoryAsString() + userInput;
return fullPath;
}
示例3
private String convertCompletionBackIntoUserInputStyle(
final String originalUserInput, final String completion) {
if (FileUtils.denotesAbsolutePath(originalUserInput)) {
// Input was originally as a fully-qualified path, so we just keep the
// completion in that form
return completion;
}
if (originalUserInput.startsWith(HOME_DIRECTORY_SYMBOL)) {
// Input originally started with this symbol, so replace the user's home
// directory with it again
Assert.notNull(home,
"Home directory could not be determined from system properties");
return HOME_DIRECTORY_SYMBOL + completion.substring(home.length());
}
// The path was working directory specific, so strip the working directory
// given the user never typed it
return completion.substring(getWorkingDirectoryAsString().length());
}
示例4
/**
* If the user input starts with a tilde character (~), replace the tilde
* character with the user's home directory. If the user input does not start
* with a tilde, simply return the original user input without any changes if
* the input specifies an absolute path, or return an absolute path based on
* the working directory if the input specifies a relative path.
*
* @param userInput
* the user input, which may commence with a tilde (required)
* @return a string that is guaranteed to no longer contain a tilde as the
* first character (never null)
*/
private String convertUserInputIntoAFullyQualifiedPath(final String userInput) {
if (FileUtils.denotesAbsolutePath(userInput)) {
// Input is already in a fully-qualified path form
return userInput;
}
if (userInput.startsWith(HOME_DIRECTORY_SYMBOL)) {
// Replace this symbol with the user's actual home directory
Assert.notNull(home,
"Home directory could not be determined from system properties");
if (userInput.length() > 1) {
return home + userInput.substring(1);
}
}
// The path is working directory specific, so prepend the working directory
String fullPath = getWorkingDirectoryAsString() + userInput;
return fullPath;
}
示例5
@Override
public String getBanner() {
StringBuilder builder = new StringBuilder();
builder.append(FileUtils.readBanner(SpringDataReleaseCliBannerProvider.class, "banner.txt"));
builder.append(getVersion()).append(IOUtils.LINE_SEPARATOR);
builder.append(IOUtils.LINE_SEPARATOR);
return builder.toString();
}
示例6
@Override
public String getBanner() {
StringBuilder sb = new StringBuilder();
sb.append(FileUtils.readBanner(Main.class, "/banner.txt"));
sb.append(OsUtils.LINE_SEPARATOR);
sb.append("Connection urls: " + OsUtils.LINE_SEPARATOR);
sb.append(" - Kafka: " + kafkaBrokers);
sb.append(" - Zookeeper: " + zkQuorum);
sb.append(OsUtils.LINE_SEPARATOR);
return sb.toString();
}
示例7
private ExitShellRequest doRun() {
this.stopWatch.start();
try {
String[] commandsToExecuteAndThenQuit = this.commandLine.getShellCommandsToExecute();
ExitShellRequest exitShellRequest;
if (null != commandsToExecuteAndThenQuit) {
boolean successful = false;
exitShellRequest = ExitShellRequest.FATAL_EXIT;
for (String cmd : commandsToExecuteAndThenQuit) {
if (!(successful = this.lineShellComponent.executeCommand(cmd).isSuccess()))
break;
}
if (successful) {
exitShellRequest = ExitShellRequest.NORMAL_EXIT;
}
}
else if (this.applicationArguments.containsOption("help")) {
System.out.println(FileUtils.readBanner(ShellCommandLineRunner.class, "/usage.txt"));
exitShellRequest = ExitShellRequest.NORMAL_EXIT;
} else {
this.lineShellComponent.start();
this.lineShellComponent.promptLoop();
exitShellRequest = this.lineShellComponent.getExitShellRequest();
if (exitShellRequest == null) {
exitShellRequest = ExitShellRequest.NORMAL_EXIT;
}
this.lineShellComponent.waitForComplete();
}
if (this.lineShellComponent.isDevelopmentMode()) {
System.out.println("Total execution time: " + this.stopWatch
.getLastTaskTimeMillis() + " ms");
}
return exitShellRequest;
} catch (Exception ex) {
throw new ShellException(ex.getMessage(), ex);
} finally {
HandlerUtils.flushAllHandlers(this.logger);
this.stopWatch.stop();
}
}
示例8
@Override
public String getBanner() {
return FileUtils.readBanner(DataFlowBannerProvider.class, "/dataflow-banner.txt") +
"\n" + getVersion() + "\n";
}
示例9
private ExitShellRequest doRun() {
this.stopWatch.start();
try {
String[] commandsToExecuteAndThenQuit = this.commandLine.getShellCommandsToExecute();
ExitShellRequest exitShellRequest;
if (null != commandsToExecuteAndThenQuit) {
boolean successful = false;
exitShellRequest = ExitShellRequest.FATAL_EXIT;
for (String cmd : commandsToExecuteAndThenQuit) {
if (!(successful = this.lineShellComponent.executeCommand(cmd).isSuccess()))
break;
}
if (successful) {
exitShellRequest = ExitShellRequest.NORMAL_EXIT;
}
}
else if (this.applicationArguments.containsOption("help")) {
System.out.println(FileUtils.readBanner(ShellCommandLineRunner.class, "/usage.txt"));
exitShellRequest = ExitShellRequest.NORMAL_EXIT;
}
else {
this.lineShellComponent.start();
this.lineShellComponent.promptLoop();
exitShellRequest = this.lineShellComponent.getExitShellRequest();
if (exitShellRequest == null) {
exitShellRequest = ExitShellRequest.NORMAL_EXIT;
}
this.lineShellComponent.waitForComplete();
}
if (this.lineShellComponent.isDevelopmentMode()) {
System.out.println("Total execution time: " + this.stopWatch.getLastTaskTimeMillis() + " ms");
}
return exitShellRequest;
}
catch (Exception ex) {
throw new ShellException(ex.getMessage(), ex);
}
finally {
HandlerUtils.flushAllHandlers(this.logger);
this.stopWatch.stop();
}
}
示例10
@Override
public String getBanner() {
return FileUtils.readBanner(DataFlowBannerProvider.class, "/dataflow-banner.txt") + "\n" + getVersion() + "\n";
}
示例11
@Override
public String getBanner() {
return FileUtils.readBanner(AmbariShell.class, "banner.txt");
}
示例12
/**
* Prints an elephant to the console.
*
* @return elephant
*/
@CliCommand(value = "hello", help = "Prints a simple elephant to the console")
public String simple() {
return FileUtils.readBanner(AmbariShell.class, "elephant.txt");
}