Java Code Examples for org.apache.commons.lang.StringUtils#indexOfAny()

The following examples show how to use org.apache.commons.lang.StringUtils#indexOfAny() . 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: HdfsService.java    From hadoop-etl-udfs with MIT License 5 votes vote down vote up
public static List<String> getFilesFromTable(
        final String hdfsUserOrServicePrincipal,
        final String tableRootPath,
        final String partitionFilterSpec,
        final List<HCatTableColumn> partitionColumns,
        final boolean useKerberos,
        final KerberosCredentials kerberosCredentials,
        final List<String> hdfsAddressesToUse,
        boolean enableRPCEncryption) throws Exception {


    // Set login user. The value is actually not important, but something must be specified.
    // UnixLoginModule makes a native system call to get the username
    String loginUser = useKerberos ? kerberosCredentials.getPrincipal() : hdfsUserOrServicePrincipal;
    int endIndex = StringUtils.indexOfAny(loginUser, "/@");
    if (endIndex != -1) {
        loginUser = loginUser.substring(0, endIndex);
    }
    UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser(loginUser));
    UserGroupInformation ugi = useKerberos ? KerberosHadoopUtils.getKerberosUGI(kerberosCredentials) : UserGroupInformation.createRemoteUser(hdfsUserOrServicePrincipal);
    List<String> tableInfo = ugi.doAs(new PrivilegedExceptionAction<List<String>>() {
        @Override
        public List<String> run() throws Exception {
            Configuration conf = getHdfsConfiguration(useKerberos, hdfsUserOrServicePrincipal, enableRPCEncryption);
            // Get all directories (leafs only) of the table
            FileSystem realFs = getFileSystem(hdfsAddressesToUse, conf);
            FileSystemWrapper fs = new FileSystemWrapperImpl(realFs);
            List<String> partitionPaths = getPartitionPaths(fs, tableRootPath, partitionColumns, MultiPartitionFilter.parseMultiFilter(partitionFilterSpec));
            // Get all filenames for the table
            return getFilePaths(fs, partitionPaths);
        }
    });
    return tableInfo;
}
 
Example 2
Source File: BashCompletionContributor.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
/**
 * In a completion like "$abc<caret> def" the element is a word psi lead element, in this case to not expand the autocompletion after the whitespace character
 * https://code.google.com/p/bashsupport/issues/detail?id=51
 * a completion at the end of a line with an open string is parsed as string until the first quote in the next line(s)
 * in the case of a newline character in the string the end offset is set to the end of the string to avoid aggressive string replacements
 */
private boolean fixReplacementOffsetInString(PsiElement element, OffsetMap offsetMap) {
    int endCharIndex = StringUtils.indexOfAny(element.getText(), new char[]{'\n', ' '});
    if (endCharIndex > 0) {
        offsetMap.addOffset(IDENTIFIER_END_OFFSET, element.getTextOffset() + endCharIndex);
        return true;
    }

    return false;
}
 
Example 3
Source File: PrefixSuffixFormatterImpl.java    From MarriageMaster with GNU General Public License v3.0 5 votes vote down vote up
public static IMarriageAndPartnerFormatter produceFormatter(@NotNull String format)
{
	format = format.replaceAll("\\{StatusHeart}", at.pcgamingfreaks.MarriageMaster.Bukkit.Formatter.IMarriageAndPartnerFormatter.HEART_RED);
	if(StringUtils.indexOfAny(format, new String[]{ "{Surname}", "{PartnerName}", "{PartnerDisplayName}", "{MagicHeart}" }) != -1)
	{
		return new PlaceholderFormatter(format.replaceAll("\\{Surname}", "%1\\$s").replaceAll("\\{PartnerName}", "%2\\$s").replaceAll("\\{PartnerDisplayName}", "%3\\$s").replaceAll("\\{MagicHeart}", "%4\\$s"));
	}
	else return new StaticStringFormatter(format);
}
 
Example 4
Source File: KerberosHadoopUtils.java    From hadoop-etl-udfs with MIT License 4 votes vote down vote up
/**
 * Configure JAAS for Export if JDBC statements must be executed using Kerberos authentication.
 */
public static void configKerberosJaas(String path, String user, String password) throws Exception {
    final String krbKey = "ExaAuthType=Kerberos";
    String[] confKeytab = password.split(";");
    if (confKeytab.length != 3 || !confKeytab[0].equals(krbKey)) {
        throw new RuntimeException("An invalid Kerberos CONNECTION was specified.");
    }

    String confPath = UdfUtils.writeTempFile(DatatypeConverter.parseBase64Binary(confKeytab[1]), path, "krb5_", ".conf");
    String keytabPath = UdfUtils.writeTempFile(DatatypeConverter.parseBase64Binary(confKeytab[2]), path, "kt_", ".keytab");

    StringBuilder jaasData = new StringBuilder();
    jaasData.append("Client {\n");
    jaasData.append("com.sun.security.auth.module.Krb5LoginModule required\n");
    jaasData.append("principal=\"" + user + "\"\n");
    jaasData.append("useKeyTab=true\n");
    jaasData.append("keyTab=\"" + keytabPath + "\"\n");
    jaasData.append("doNotPrompt=true\n");
    jaasData.append("useTicketCache=false;\n");
    jaasData.append("};\n");
    jaasData.append("com.sun.security.jgss.initiate {\n");
    jaasData.append("com.sun.security.auth.module.Krb5LoginModule required\n");
    jaasData.append("principal=\"" + user + "\"\n");
    jaasData.append("useKeyTab=true\n");
    jaasData.append("keyTab=\"" + keytabPath + "\"\n");
    jaasData.append("doNotPrompt=true\n");
    jaasData.append("useTicketCache=false;\n");
    jaasData.append("};\n");
    String jaasPath = UdfUtils.writeTempFile(jaasData.toString().getBytes(Charset.forName("UTF-8")), path, "jaas_", ".conf");

    System.setProperty("java.security.auth.login.config", jaasPath);
    System.setProperty("java.security.krb5.conf", confPath);
    System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");

    // Set login user. The value is actually not important, but something must be specified.
    // UnixLoginModule makes a native system call to get the username.
    int endIndex = StringUtils.indexOfAny(user, "/@");
    if (endIndex != -1) {
        user = user.substring(0, endIndex);
    }
    UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser(user));
}
 
Example 5
Source File: OpenTsdbMetric.java    From StatsAgg with Apache License 2.0 4 votes vote down vote up
protected static boolean parseOpenTsdbJson_ValidateMetricValue_IsMetricValueSizeReasonable(String metricValueString) {
    
    if ((metricValueString == null) || metricValueString.isEmpty()) return false;
    
    if (metricValueString.length() > 100) {
        logger.debug("Metric parse error. Metric value can't be more than 100 characters long. Metric value was \"" + metricValueString.length() + "\" characters long. " +
                "MetricString=\"" + metricValueString + "\"");
        return false;
    }
 
    try {
        int exponentIndex = StringUtils.indexOfAny(metricValueString, EXPONENT_CHARS);

        if (exponentIndex != -1) {
            String exponentValue = metricValueString.substring(exponentIndex + 1);
            
            if (exponentValue.length() > 2) {
                boolean isNegativeExponent = exponentValue.startsWith("-");
                
                if (!isNegativeExponent) {
                    logger.debug("Metric parse error. Exponent is too large. " + "MetricString=\"" + metricValueString + "\"");
                    return false;
                }
                else if (exponentValue.length() > 3) {
                    logger.debug("Metric parse error. Exponent is too large. " + "MetricString=\"" + metricValueString + "\"");
                    return false;
                }
                else {
                    return true;
                }
            }
            else {
                return true;
            }
        }
        else {
            return true;
        }
    }
    catch (Exception e) {   
        logger.debug(e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e));
        return false;
    }
    
}
 
Example 6
Source File: HomematicTypeGeneratorImpl.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Returns true, if the given datapoint can be ignored for metadata generation.
 */
public static boolean isIgnoredDatapoint(HmDatapoint dp) {
    return StringUtils.indexOfAny(dp.getName(), IGNORE_DATAPOINT_NAMES) != -1;
}
 
Example 7
Source File: IniFileReader.java    From Kafdrop with Apache License 2.0 3 votes vote down vote up
/**
 * Tries to find the index of the separator character in the given string.
 * This method checks for the presence of separator characters in the given
 * string. If multiple characters are found, the first one is assumed to be
 * the correct separator. If there are quoting characters, they are taken
 * into account, too.
 *
 * @param line the line to be checked
 * @return the index of the separator character or -1 if none is found
 */
private int findSeparator(String line)
{
   int index = findSeparatorBeforeQuote(line, StringUtils.indexOfAny(line, QUOTE_CHARACTERS));
   if (index < 0)
   {
      index = StringUtils.indexOfAny(line, SEPARATOR_CHARS);
   }
   return index;
}
 
Example 8
Source File: StringFormatter.java    From fenixedu-academic with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Finds the first index of a special character within the given string
 * after a start position.
 * 
 * @param string
 *            the string to check
 * @param startPos
 *            the position to start from
 * @return the first index of a special character
 */
private static int indexOfAnySpecChar(String string, int startPos) {
    return StringUtils.indexOfAny(string.substring(startPos), specialChars);
}