in client/migrationx/migrationx-transformer/src/main/java/com/aliyun/dataworks/migrationx/transformer/core/sqoop/SqoopOptions.java [1080:1148]
public static char toChar(String charish) throws InvalidOptionsException {
if (null == charish || charish.length() == 0) {
throw new InvalidOptionsException("Character argument expected."
+ "\nTry --help for usage instructions.");
}
if (charish.startsWith("\\0x") || charish.startsWith("\\0X")) {
if (charish.length() == 3) {
throw new InvalidOptionsException(
"Base-16 value expected for character argument."
+ "\nTry --help for usage instructions.");
} else {
String valStr = charish.substring(3);
int val = Integer.parseInt(valStr, 16);
return (char)val;
}
} else if (charish.startsWith("\\0")) {
if (charish.equals("\\0")) {
// it's just '\0', which we can take as shorthand for nul.
return DelimiterSet.NULL_CHAR;
} else {
// it's an octal value.
String valStr = charish.substring(2);
int val = Integer.parseInt(valStr, 8);
return (char)val;
}
} else if (charish.startsWith("\\")) {
if (charish.length() == 1) {
// it's just a '\'. Keep it literal.
return '\\';
} else if (charish.length() > 2) {
// we don't have any 3+ char escape strings.
throw new InvalidOptionsException(
"Cannot understand character argument: " + charish
+ "\nTry --help for usage instructions.");
} else {
// this is some sort of normal 1-character escape sequence.
char escapeWhat = charish.charAt(1);
switch (escapeWhat) {
case 'b':
return '\b';
case 'n':
return '\n';
case 'r':
return '\r';
case 't':
return '\t';
case '\"':
return '\"';
case '\'':
return '\'';
case '\\':
return '\\';
default:
throw new InvalidOptionsException(
"Cannot understand character argument: " + charish
+ "\nTry --help for usage instructions.");
}
}
} else {
// it's a normal character.
if (charish.length() > 1) {
LOG.warn("Character argument " + charish + " has multiple characters; "
+ "only the first will be used.");
}
return charish.charAt(0);
}
}