org.apache.commons.lang.CharUtils Java Examples

The following examples show how to use org.apache.commons.lang.CharUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UrlTag.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
 
Example #2
Source File: DLConfig.java    From DataLink with Apache License 2.0 5 votes vote down vote up
/**
 * 根据用户提供的json path,寻址Character对象
 *
 * @return Character对象,如果path不存在或者Character不存在,返回null
 */
public Character getChar(final String path) {
    String result = this.getString(path);
    if (null == result) {
        return null;
    }

    try {
        return CharUtils.toChar(result);
    } catch (Exception e) {
        throw new DLConfigException(
                String.format("the config value [%s] for key [%s] can not be converted to char type.",
                        result, path));
    }
}
 
Example #3
Source File: MapperAnonymize.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
@Override
public boolean init(LogFeederProps logFeederProps, String inputDesc, String fieldName, String mapClassCode, MapFieldDescriptor mapFieldDescriptor) {
  init(inputDesc, fieldName, mapClassCode);
  
  pattern = ((MapAnonymizeDescriptor)mapFieldDescriptor).getPattern();
  if (StringUtils.isEmpty(pattern)) {
    logger.fatal("pattern is empty.");
    return false;
  }
  
  patternParts = Splitter.on("<hide>").omitEmptyStrings().split(pattern);
  hideChar = CharUtils.toChar(((MapAnonymizeDescriptor)mapFieldDescriptor).getHideChar(), DEFAULT_HIDE_CHAR);
  
  return true;
}
 
Example #4
Source File: UrlTag.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
static private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
 
Example #5
Source File: CheckstyleTestUtils.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void assertSimilarXml(String expectedXml, String xml) {
    XMLUnit.setIgnoreWhitespace(true);
    final Diff diff;
    try {
        diff = XMLUnit.compareXML(xml, expectedXml);
    }
    catch (SAXException | IOException ex) {
        throw new IllegalArgumentException("Could not run XML comparison", ex);
    }
    final String message = "Diff: " + diff + CharUtils.LF + "XML: " + xml;
    assertTrue(message, diff.similar());
}
 
Example #6
Source File: UrlTag.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
private boolean isAsciiAlphaNumeric(String s) {
    if (s == null) {
        return true;
    }

    for (int i = 0; i < s.length(); i++) {
        if (!CharUtils.isAsciiAlphanumeric(s.charAt(i))) {
            return false;
        }
    }
    return true;
}
 
Example #7
Source File: TestStringUtil.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnicodeEscapedDelimiter() {
  for (int i = 0; i < 128; i++) {
    char c = (char) i;
    String delimiter = CharUtils.unicodeEscaped(c);
    String escapedDelimiter = StringUtils.unicodeEscapedDelimiter(delimiter);
    assertEquals(delimiter, escapedDelimiter);
    assertEquals(1, StringEscapeUtils.unescapeJava(escapedDelimiter).length());
    assertEquals(c, StringEscapeUtils.unescapeJava(escapedDelimiter).charAt(0));
  }
}
 
Example #8
Source File: TestStringUtil.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnescapedDelimiter() {
  for (int i = 0; i < 128; i++) {
    char c = (char) i;
    String delimiter = String.valueOf(c);
    String escapedDelimiter = StringUtils.unicodeEscapedDelimiter(delimiter);
    assertEquals(CharUtils.unicodeEscaped(c), escapedDelimiter);
    assertEquals(1, StringEscapeUtils.unescapeJava(escapedDelimiter).length());
    assertEquals(c, StringEscapeUtils.unescapeJava(escapedDelimiter).charAt(0));
  }
}
 
Example #9
Source File: HiveResolver.java    From pxf with Apache License 2.0 4 votes vote down vote up
void parseDelimiterChar(RequestContext input) {

        String userDelim = input.getGreenplumCSV().getDelimiter() != null ?
                String.valueOf(input.getGreenplumCSV().getDelimiter()) : null;

        if (userDelim == null) {
            /* No DELIMITER in URL, try to get it from fragment's user data*/
            HiveUserData hiveUserData = HiveUtilities.parseHiveUserData(input);
            if (hiveUserData.getDelimiter() == null) {
                throw new IllegalArgumentException("DELIMITER is a required option");
            }
            delimiter = (char) Integer.valueOf(hiveUserData.getDelimiter()).intValue();
        } else {
            final int VALID_LENGTH = 1;
            final int VALID_LENGTH_HEX = 4;
            if (userDelim.startsWith("\\x")) { // hexadecimal sequence
                if (userDelim.length() != VALID_LENGTH_HEX) {
                    throw new IllegalArgumentException(
                            "Invalid hexdecimal value for delimiter (got"
                                    + userDelim + ")");
                }
                delimiter = (char) Integer.parseInt(
                        userDelim.substring(2, VALID_LENGTH_HEX), 16);
                if (!CharUtils.isAscii(delimiter)) {
                    throw new IllegalArgumentException(
                            "Invalid delimiter value. Must be a single ASCII character, or a hexadecimal sequence (got non ASCII "
                                    + delimiter + ")");
                }
                return;
            }
            if (userDelim.length() != VALID_LENGTH) {
                throw new IllegalArgumentException(
                        "Invalid delimiter value. Must be a single ASCII character, or a hexadecimal sequence (got "
                                + userDelim + ")");
            }
            if (!CharUtils.isAscii(userDelim.charAt(0))) {
                throw new IllegalArgumentException(
                        "Invalid delimiter value. Must be a single ASCII character, or a hexadecimal sequence (got non ASCII "
                                + userDelim + ")");
            }
            delimiter = userDelim.charAt(0);
        }
    }
 
Example #10
Source File: CharacterUtils.java    From zstack with Apache License 2.0 4 votes vote down vote up
public static boolean checkCharacter(String s){
    return s.codePoints().allMatch(code -> CharUtils.isAsciiPrintable((char) code));
}
 
Example #11
Source File: DescTableCommand.java    From tajo with Apache License 2.0 4 votes vote down vote up
protected String toFormattedString(TableDesc desc) {
  StringBuilder sb = new StringBuilder();
  sb.append("\ntable name: ").append(desc.getName()).append("\n");
  sb.append("table uri: ").append(desc.getUri()).append("\n");
  sb.append("store type: ").append(desc.getMeta().getDataFormat()).append("\n");
  if (desc.getStats() != null) {

    long row = desc.getStats().getNumRows();
    String rowText = row == TajoConstants.UNKNOWN_ROW_NUMBER ? "unknown" : row + "";
    sb.append("number of rows: ").append(rowText).append("\n");
    sb.append("volume: ").append(
        FileUtil.humanReadableByteCount(desc.getStats().getNumBytes(),
            true)).append("\n");
  }
  sb.append("Options:\n");
  for(Map.Entry<String, String> entry : desc.getMeta().toMap().entrySet()){

    /*
    *  Checks whether the character is ASCII 7 bit printable.
    *  For example, a printable unicode '\u007c' become the character ‘|’.
    *
    *  Control-chars : ctrl-a(\u0001), tab(\u0009) ..
    *  Printable-chars : '|'(\u007c), ','(\u002c) ..
    * */

    String value = entry.getValue();
    String unescaped = StringEscapeUtils.unescapeJava(value);
    if (unescaped.length() == 1 && CharUtils.isAsciiPrintable(unescaped.charAt(0))) {
      value = unescaped;
    }
    sb.append("\t").append("'").append(entry.getKey()).append("'").append("=")
        .append("'").append(value).append("'").append("\n");
  }
  sb.append("\n");
  sb.append("schema: \n");

  for(int i = 0; i < desc.getSchema().size(); i++) {
    Column col = desc.getSchema().getColumn(i);
    sb.append(col.getSimpleName()).append("\t").append(col.getTypeDesc());
    sb.append("\n");
  }

  sb.append("\n");
  if (desc.getPartitionMethod() != null) {
    PartitionMethodDesc partition = desc.getPartitionMethod();
    sb.append("Partitions: \n");

    sb.append("type:").append(partition.getPartitionType().name()).append("\n");

    sb.append("columns:").append(":");
    sb.append(StringUtils.join(partition.getExpressionSchema().toArray()));
  }

  return sb.toString();
}
 
Example #12
Source File: StringUtils.java    From tajo with Apache License 2.0 4 votes vote down vote up
public static String unicodeEscapedDelimiter(char c) {
  return CharUtils.unicodeEscaped(c);
}