Java Code Examples for org.apache.commons.lang3.StringUtils.rightPad()

The following are Jave code examples for showing how to use rightPad() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OperatieBRP   File: DatumFormatterUtil.java   View Source Code Vote up 6 votes
/**
 * Zet een tekstuele representatie van een deels onbekende datum (formaat = yyyy-MM-dd) om naar een getal dat dezelfde datum representeert.
 * @param datum tekstuele representatie van een deels onbekende datum
 * @return getal representatie van een deels onbekende datum, null indien tekstuele representatie (1) null is, (2) leeg is of (3) een invalide formaat heeft
 */
public static Integer deelsOnbekendeDatumAlsStringNaarGetal(final String datum) {
    try {
        final DeelsOnbekendeDatum deelsOnbekendeDatum = new DeelsOnbekendeDatum(datum);
        if (!deelsOnbekendeDatum.isGeldig()) {
            return null;
        }

        String dateString = deelsOnbekendeDatum.datum.replaceAll("-", "");
        if (dateString.length() < LENGTE_DATUM) {
            dateString = StringUtils.rightPad(dateString, LENGTE_DATUM, NUL_ALS_STRING);
        }
        return Integer.parseInt(dateString);

    } catch (IllegalStateException e) {
        LOG.debug("Fout bij conversie deels onbekende datum naar getal", e);
        return null;
    }
}
 
Example 2
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: ValidatorsTest.java   View Source Code Vote up 5 votes
@Test
public void testCheckTopic_TooLongTopic() {
    String tooLongTopic = StringUtils.rightPad("TooLongTopic", Validators.CHARACTER_MAX_LENGTH + 1, "_");
    assertThat(tooLongTopic.length()).isGreaterThan(Validators.CHARACTER_MAX_LENGTH);
    try {
        Validators.checkTopic(tooLongTopic);
        failBecauseExceptionWasNotThrown(MQClientException.class);
    } catch (MQClientException e) {
        assertThat(e).hasMessageStartingWith("The specified topic is longer than topic max length 255.");
    }
}
 
Example 3
Project: TestDemo1-github   File: Util.java   View Source Code Vote up 5 votes
public static String createF63(String s, String bkName){
	if(null == bkName)bkName = "其它";
	StringBuffer sb = new StringBuffer(StringUtils.rightPad(s, 63));
	sb.append(getFixation(bkName, 30));
	sb.append(StringUtils.rightPad("48360000", 30));
	return sb.toString();
}
 
Example 4
Project: hybris-integration-intellij-idea-plugin   File: ImpexTableFormatter.java   View Source Code Vote up 5 votes
private static void writeValueLine(
    final int[] maxColumnWidth,
    final StringBuilder sb,
    final PsiElement currentValueLine
) {
    if (isImpexValueGroup(currentValueLine.getFirstChild())) {
        sb.append(StringUtils.rightPad("", maxColumnWidth[0] + 1));
    } else {
        final String text = StringUtils.rightPad(
            currentValueLine.getFirstChild().getText().trim(),
            maxColumnWidth[0]
        );
        sb.append(text);
    }
    final PsiElement[] children = currentValueLine.getChildren();

    int i = 1;
    for (final PsiElement element : children) {
        final int length = maxColumnWidth.length - 1;
        if (isFirstFieldValueIsEmpty(element)) {
            sb.append(';').append(' ').append(StringUtils.rightPad("", maxColumnWidth[min(i, length
            )]));
        } else {
            sb
                .append(';')
                .append(' ')
                .append(StringUtils.rightPad(
                    element.getLastChild().getText().trim(),
                    maxColumnWidth[min(i, length)]
                ));
        }
        i++;
    }
}
 
Example 5
Project: OperatieBRP   File: DatumFormatterUtil.java   View Source Code Vote up 5 votes
/**
 * Zet een getal representatie van een (deels onbekende) datum om naar een tekstuele representatie dat dezelfde datum representeert.
 * @param datum een getal representatie van een (deels onbekende) datum.
 * @return een tekstuele representatie van een (deels onbekende) datum.
 */
public static String datumAlsGetalNaarDatumAlsString(final Integer datum) {
    String resultaat = null;
    if (datum != null) {
        resultaat = "";
        String dateString = String.valueOf(datum);
        // Een datum kan 0 zijn. Dit zie je bij stamgegevens.
        if (dateString.length() < LENGTE_DATUM) {
            dateString = StringUtils.rightPad(
                    dateString.length() < LENGTE_JAAR ? StringUtils.leftPad(dateString, LENGTE_JAAR, NUL_ALS_STRING) : dateString,
                    LENGTE_DATUM,
                    NUL_ALS_STRING);
        }
        final String jaar = dateString.substring(0, LENGTE_JAAR);
        final String maand = dateString.substring(LENGTE_JAAR, LENGTE_JAAR + LENGTE_MAAND);
        final String dag = dateString.substring(LENGTE_JAAR + LENGTE_MAAND, LENGTE_DATUM);
        resultaat += jaar;
        if (!DUBBEL_NUL_ALS_STRING.equals(maand)) {
            resultaat += KOPPELTEKEN;
            resultaat += maand;
            if (!DUBBEL_NUL_ALS_STRING.equals(dag)) {
                resultaat += KOPPELTEKEN;
                resultaat += dag;
            }
        }
    }
    return resultaat;
}
 
Example 6
Project: satisfy   File: DataGenerationSteps.java   View Source Code Vote up 5 votes
@Given("unique string with prefix '$prefix' and '$length' length saved to '$name' variable")
public void givenUniqueStringWithPrefixAndLengthSavedToVariable(String prefix, int length, String name) {
    String uniqueString = String.valueOf(UUID.randomUUID()).replace("-",
            "");
    String textElement = StringUtils.rightPad(prefix, length, uniqueString);
    SessionVariablesUtils.save(name, textElement);
}
 
Example 7
Project: rmq4note   File: ValidatorsTest.java   View Source Code Vote up 5 votes
@Test
public void testCheckTopic_TooLongTopic() {
    String tooLongTopic = StringUtils.rightPad("TooLongTopic", Validators.CHARACTER_MAX_LENGTH + 1, "_");
    assertThat(tooLongTopic.length()).isGreaterThan(Validators.CHARACTER_MAX_LENGTH);
    try {
        Validators.checkTopic(tooLongTopic);
        failBecauseExceptionWasNotThrown(MQClientException.class);
    } catch (MQClientException e) {
        assertThat(e).hasMessageStartingWith("The specified topic is longer than topic max length 255.");
    }
}
 
Example 8
Project: nifi-registry   File: AESSensitivePropertyProvider.java   View Source Code Vote up 5 votes
/**
 * Returns the decrypted plaintext.
 *
 * @param protectedValue the cipher text read from the {@code nifi.properties} file
 * @return the raw value to be used by the application
 * @throws SensitivePropertyProtectionException if there is an error decrypting the cipher text
 */
@Override
public String unprotect(String protectedValue) throws SensitivePropertyProtectionException {
    if (protectedValue == null || protectedValue.trim().length() < MIN_CIPHER_TEXT_LENGTH) {
        throw new IllegalArgumentException("Cannot decrypt a cipher text shorter than " + MIN_CIPHER_TEXT_LENGTH + " chars");
    }

    if (!protectedValue.contains(DELIMITER)) {
        throw new IllegalArgumentException("The cipher text does not contain the delimiter " + DELIMITER + " -- it should be of the form Base64(IV) || Base64(cipherText)");
    }

    protectedValue = protectedValue.trim();

    final String IV_B64 = protectedValue.substring(0, protectedValue.indexOf(DELIMITER));
    byte[] iv = Base64.decode(IV_B64);
    if (iv.length < IV_LENGTH) {
        throw new IllegalArgumentException("The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes");
    }

    String CIPHERTEXT_B64 = protectedValue.substring(protectedValue.indexOf(DELIMITER) + 2);

    // Restore the = padding if necessary to reconstitute the GCM MAC check
    if (CIPHERTEXT_B64.length() % 4 != 0) {
        final int paddedLength = CIPHERTEXT_B64.length() + 4 - (CIPHERTEXT_B64.length() % 4);
        CIPHERTEXT_B64 = StringUtils.rightPad(CIPHERTEXT_B64, paddedLength, '=');
    }

    try {
        byte[] cipherBytes = Base64.decode(CIPHERTEXT_B64);

        cipher.init(Cipher.DECRYPT_MODE, this.key, new IvParameterSpec(iv));
        byte[] plainBytes = cipher.doFinal(cipherBytes);
        logger.debug(getName() + " decrypted a sensitive value successfully");
        return new String(plainBytes, StandardCharsets.UTF_8);
    } catch (BadPaddingException | IllegalBlockSizeException | DecoderException | InvalidAlgorithmParameterException | InvalidKeyException e) {
        final String msg = "Error decrypting a protected value";
        logger.error(msg, e);
        throw new SensitivePropertyProtectionException(msg, e);
    }
}
 
Example 9
Project: csap-core   File: CSAP.java   View Source Code Vote up 4 votes
public static String pad( String input) {
	return StringUtils.rightPad( input, 25 ) ;
}
 
Example 10
Project: uroborosql   File: StringFunction.java   View Source Code Vote up 2 votes
/**
 * 文字列の末尾に空白を埋めて指定された長さにする
 *
 * <pre>
 * StringUtils.rightPad(null, *)   = null
 * StringUtils.rightPad("", 3)     = "   "
 * StringUtils.rightPad("bat", 3)  = "bat"
 * StringUtils.rightPad("bat", 5)  = "bat  "
 * StringUtils.rightPad("bat", 1)  = "bat"
 * StringUtils.rightPad("bat", -1) = "bat"
 * </pre>
 *
 * @param str 文字列
 * @param size 文字埋め後の長さ
 * @return 指定した長さになるまで末尾に空白を埋めた文字列
 */
public String rightPad(final String str, final int size) {
	return StringUtils.rightPad(str, size);
}
 
Example 11
Project: uroborosql   File: StringFunction.java   View Source Code Vote up 2 votes
/**
 * 文字列の末尾に指定した埋め込み文字を埋めて指定された長さにする
 *
 * <pre>
 * StringUtils.rightPad(null, *, *)     = null
 * StringUtils.rightPad("", 3, 'z')     = "zzz"
 * StringUtils.rightPad("bat", 3, 'z')  = "bat"
 * StringUtils.rightPad("bat", 5, 'z')  = "batzz"
 * StringUtils.rightPad("bat", 1, 'z')  = "bat"
 * StringUtils.rightPad("bat", -1, 'z') = "bat"
 * </pre>
 *
 * @param str 文字列
 * @param size 文字埋め後の長さ
 * @param padChar 埋め込み文字
 * @return 指定した長さになるまで末尾に埋め込み文字を埋めた文字列
 */
public String rightPad(final String str, final int size, final char padChar) {
	return StringUtils.rightPad(str, size, padChar);
}