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

The following examples show how to use org.apache.commons.lang.StringUtils#reverse() . 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: UnitLocalUnitUserToken.java    From io with Apache License 2.0 6 votes vote down vote up
final String doCreateTokenString() {
    StringBuilder raw = new StringBuilder();

    // 発行時刻のEpochからのミリ秒を逆順にした文字列が先頭から入るため、推測しづらい。
    String iaS = Long.toString(this.issuedAt);
    String iaSr = StringUtils.reverse(iaS);
    raw.append(iaSr);

    raw.append(SEPARATOR);
    raw.append(Long.toString(this.lifespan));
    raw.append(SEPARATOR);
    raw.append(this.subject);
    raw.append(SEPARATOR);
    raw.append(this.issuer);
    return LocalToken.encode(raw.toString(), getIvBytes(issuer));
}
 
Example 2
Source File: Cuboid.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
public static String getDisplayName(long cuboidID, int dimensionCount) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < dimensionCount; ++i) {
        if ((cuboidID & (1L << i)) == 0) {
            sb.append('0');
        } else {
            sb.append('1');
        }
    }
    return StringUtils.reverse(sb.toString());
}
 
Example 3
Source File: XSSServlet.java    From easybuggy with Apache License 2.0 5 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    try {
        String string = req.getParameter("string");
        Locale locale = req.getLocale();

        StringBuilder bodyHtml = new StringBuilder();

        bodyHtml.append("<form action=\"xss\" method=\"post\">");
        bodyHtml.append(getMsg("description.reverse.string", locale));
        bodyHtml.append("<br><br>");
        bodyHtml.append(getMsg("label.string", locale) + ": ");
        bodyHtml.append("<input type=\"text\" name=\"string\" size=\"100\" maxlength=\"100\">");
        bodyHtml.append("<br><br>");
        bodyHtml.append("<input type=\"submit\" value=\"" + getMsg("label.submit", locale) + "\">");
        bodyHtml.append("<br><br>");

        if (!StringUtils.isBlank(string)) {
            // Reverse the given string
            String reversedName = StringUtils.reverse(string);
            bodyHtml.append(getMsg("label.reversed.string", locale) + " : "
                    + reversedName);
        } else {
            bodyHtml.append(getMsg("msg.enter.string", locale));
        }
        bodyHtml.append("<br><br>");
        bodyHtml.append(getInfoMsg("msg.note.xss", locale));
        bodyHtml.append("</form>");

        responseToClient(req, res, getMsg("title.xss.page", locale), bodyHtml.toString());

    } catch (Exception e) {
        log.error("Exception occurs: ", e);
    }
}
 
Example 4
Source File: Cuboid.java    From kylin with Apache License 2.0 5 votes vote down vote up
public static String getDisplayName(long cuboidID, int dimensionCount) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < dimensionCount; ++i) {
        if ((cuboidID & (1L << i)) == 0) {
            sb.append('0');
        } else {
            sb.append('1');
        }
    }
    return StringUtils.reverse(sb.toString());
}
 
Example 5
Source File: LocalToken.java    From io with Apache License 2.0 5 votes vote down vote up
final String doCreateTokenString(final String[] contents) {
    StringBuilder raw = new StringBuilder();

    // 発行時刻のEpochからのミリ秒を逆順にした文字列が先頭から入るため、推測しづらい。
    String iaS = Long.toString(this.issuedAt);
    String iaSr = StringUtils.reverse(iaS);
    raw.append(iaSr);

    raw.append(SEPARATOR);
    raw.append(Long.toString(this.lifespan));
    raw.append(SEPARATOR);
    raw.append(this.subject);
    raw.append(SEPARATOR);
    if (this.schema != null) {
        raw.append(this.schema);
    }

    if (contents != null) {
        for (String cont : contents) {
            raw.append(SEPARATOR);
            if (cont != null) {
                raw.append(cont);
            }
        }
    }

    raw.append(SEPARATOR);
    raw.append(this.issuer);
    return encode(raw.toString(), getIvBytes(issuer));
}
 
Example 6
Source File: MutableMetadataHandler.java    From datawave with Apache License 2.0 4 votes vote down vote up
/**
 * Insert new field value with provided timestamp
 * 
 * @param writer
 * @param shardId
 * @param datatype
 * @param eventUid
 * @param viz
 * @param fieldName
 * @param fieldValue
 * @param timestamp
 * @param isIndexed
 * @param isReverseIndexed
 * @param dataTypes
 * @param historicalValue
 * @param insertHistory
 * @param user
 * @param mode
 * @throws Exception
 */
protected void insert(MultiTableBatchWriter writer, String shardId, String datatype, String eventUid, ColumnVisibility viz, String fieldName,
                String fieldValue, long timestamp, boolean isIndexOnlyField, boolean isIndexed, boolean isReverseIndexed, Set<Type<?>> dataTypes,
                boolean historicalValue, boolean insertHistory, String user, MODE mode) throws Exception {
    
    // increment the term frequency
    Mutation m = new Mutation(fieldName);
    if (!isIndexOnlyField) {
        m.put(ColumnFamilyConstants.COLF_E, new Text(datatype), NULL_VALUE);
        m.put(ColumnFamilyConstants.COLF_F, new Text(datatype + NULL_BYTE + DateHelper.format(timestamp)),
                        new Value(SummingCombiner.VAR_LEN_ENCODER.encode(1L)));
    }
    
    // Insert the new field.
    Mutation e = new Mutation(shardId);
    if (!isIndexOnlyField) {
        e.put(new Text(datatype + NULL_BYTE + eventUid), new Text(fieldName + NULL_BYTE + fieldValue), viz, timestamp, NULL_VALUE);
    }
    
    if (isIndexed) {
        
        long tsToDay = (timestamp / MS_PER_DAY) * MS_PER_DAY;
        
        // Create a UID object for the Value
        Builder uidBuilder = Uid.List.newBuilder();
        uidBuilder.setIGNORE(false);
        uidBuilder.setCOUNT(1);
        uidBuilder.addUID(eventUid);
        Uid.List uidList = uidBuilder.build();
        Value val = new Value(uidList.toByteArray());
        
        for (Type<?> n : dataTypes) {
            String indexTerm = fieldValue;
            if (historicalValue) {
                int lastColon = fieldValue.lastIndexOf(":");
                // The next two lines build up to the beginning of the indexTerm by finding the first two colons
                // We could use split if we could guarantee a colon never appears in the index term itself
                int indexTermLeadingColon = fieldValue.indexOf(":", 0);
                indexTermLeadingColon = fieldValue.indexOf(":", indexTermLeadingColon + 1);
                indexTerm = fieldValue.substring(indexTermLeadingColon + 1, lastColon);
            }
            String indexedValue = n.normalize(indexTerm);
            
            // Insert the global index entry
            Mutation i = new Mutation(indexedValue);
            i.put(fieldName, shardId + NULL_BYTE + datatype, viz, tsToDay, val);
            writer.getBatchWriter(this.getIndexTableName()).addMutation(i);
            m.put(ColumnFamilyConstants.COLF_I, new Text(datatype + NULL_BYTE + n.getClass().getName()), NULL_VALUE);
            
            if (isReverseIndexed) {
                String reverseIndexedValue = StringUtils.reverse(indexedValue);
                // Insert the global reverse index entry
                Mutation rm = new Mutation(reverseIndexedValue);
                rm.put(fieldName, shardId + NULL_BYTE + datatype, viz, tsToDay, val);
                writer.getBatchWriter(this.getReverseIndexTableName()).addMutation(rm);
                m.put(ColumnFamilyConstants.COLF_RI, new Text(datatype + NULL_BYTE + n.getClass().getName()), NULL_VALUE);
            }
            // Insert the field index entry
            e.put(new Text(FIELD_INDEX_PREFIX + fieldName), new Text(indexedValue + NULL_BYTE + datatype + NULL_BYTE + eventUid), viz, timestamp,
                            NULL_VALUE);
        }
    }
    writer.getBatchWriter(this.getEventTableName()).addMutation(e);
    writer.getBatchWriter(this.getMetadataTableName()).addMutation(m);
    writer.flush();
    
    if (!isIndexOnlyField && insertHistory) {
        insertHistory(writer, shardId, datatype, eventUid, viz, fieldName, fieldValue, timestamp, isIndexOnlyField, isIndexed, isReverseIndexed, dataTypes,
                        user, mode);
    }
}
 
Example 7
Source File: PasswordUtil.java    From ankush with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Gets the random password.
 *
 * @param length the length
 * @param smallChars the small chars
 * @param capsChars the caps chars
 * @param digits the digits
 * @param specialChars the special chars
 * @return the random password
 */
private static String getRandomPassword(int length, char[] smallChars,
		char[] capsChars, char[] digits, char[] specialChars) {
	char[][] charsArrArr = { smallChars, capsChars, digits, specialChars };
	String password = null;
	final int charSetCategories = 4;

	StringBuilder passwordGenBuff = new StringBuilder();
	Random r = new Random();

	int arrIdx[] = new int[charSetCategories];
	for (int pos = 0; pos < charSetCategories; ++pos) {
		arrIdx[pos] = 0;
	}

	while (passwordGenBuff.length() < length) {
		int setIdx = r.nextInt(charSetCategories);
		char[] chArr = charsArrArr[setIdx];
		if ((chArr == null) || (chArr.length == 0)) {
			continue;
		} else {
			int generatedPasswordLength = passwordGenBuff.length();
			int untouchedSetCount = 0;

			if (generatedPasswordLength > 0) {
				for (int idx = 0; idx < charSetCategories; idx++) {
					char[] currArr = charsArrArr[idx];
					if ((currArr != null) && (currArr.length > 0)) {
						if (arrIdx[idx] == 0) {
							++untouchedSetCount;
						}
					}
				}

				if ((untouchedSetCount >= (length - generatedPasswordLength))
						&& (arrIdx[setIdx] > 0)) {
					continue;
				}
			}

			passwordGenBuff.append(RandomStringUtils.random(1, chArr));

			++arrIdx[setIdx];
		}
	}

	password = passwordGenBuff.toString();

	if (r.nextInt() % 2 == 0) {
		password = StringUtils.reverse(password);
	}

	return passwordGenBuff.toString();
}