Example usage for org.apache.commons.lang3 StringUtils leftPad

List of usage examples for org.apache.commons.lang3 StringUtils leftPad

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils leftPad.

Prototype

public static String leftPad(final String str, final int size, String padStr) 

Source Link

Document

Left pad a String with a specified String.

Pad to a size of size .

 StringUtils.leftPad(null, *, *)      = null StringUtils.leftPad("", 3, "z")      = "zzz" StringUtils.leftPad("bat", 3, "yz")  = "bat" StringUtils.leftPad("bat", 5, "yz")  = "yzbat" StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat" StringUtils.leftPad("bat", 1, "yz")  = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null)  = "  bat" StringUtils.leftPad("bat", 5, "")    = "  bat" 

Usage

From source file:se.alingsas.alfresco.repo.utils.byggreda.ByggRedaDocument.java

/**
 * @return the recordNumber// ww w .j  ava 2s  .c  o m
 */
public String getRecordNumber() {
    String newRecordNumber = StringUtils.leftPad(recordNumber, 4, "0");
    return newRecordNumber;
}

From source file:se.sawano.java.security.otp.rfc6238.ExploratoryTests.java

@Test
public void should_perform_TOTP() throws Exception {
    System.out.println("--> " + hexStr2Bytes(seed).length);

    final ReferenceDataRepository testData = new ReferenceDataRepository().init();

    final ReferenceDataRepository.ReferenceData data = testData
            .getForMode(ReferenceDataRepository.ReferenceData.Mode.SHA512);

    assertArrayEquals(hexStr2Bytes(seed64), secret().value());

    final int numberOfDigitsInCode = 8;
    final long T0 = ReferenceDataRepository.T0.toEpochMilli();
    final long stepSize = ReferenceDataRepository.TIME_STEP.toMillis();
    final long T = (data.time.toEpochMilli() - T0) / stepSize; // Number of steps

    final String hexT = StringUtils.leftPad(Long.toHexString(T), 16, '0');

    System.out.println("Thex=" + hexT);
    assertEquals(data.hexTime, hexT);//from ww w .  j  a  v a  2  s  . co  m

    final byte[] hexTBytes = Hex.decodeHex(hexT.toCharArray());
    final byte[] hextBytes2 = hexStr2Bytes(hexT);
    assertArrayEquals(hextBytes2, hexTBytes);

    final byte[] hashBytes = HmacUtils.hmacSha512(secret().value(), hexTBytes);
    System.out.println(hashBytes.length);

    final int binary = truncate(hashBytes);

    int otp = binary % DIGITS_POWER[numberOfDigitsInCode];

    final String totpString = StringUtils.leftPad(Integer.toString(otp), numberOfDigitsInCode, '0');
    System.out.println(totpString);
    assertEquals(data.totp, totpString);
}

From source file:se.sawano.java.security.otp.TOTP.java

private TOTP(final int value, final Length length) {
    notNull(length);/*  w  w w  .  j a  va2s. c  o m*/
    isTrue(value >= 0, "Value cannot be negative");

    final String paddedString = StringUtils.leftPad(Integer.toString(value), length.value(), '0');
    isTrue(paddedString.length() == length.value(), "Value must have length: %d. Was: %d", length.value(),
            paddedString.length());

    this.value = paddedString;
    this.length = length;
}

From source file:se.sawano.java.security.otp.TOTPService.java

private static byte[] toHexBytes(final long value) {
    final String hexValue = StringUtils.leftPad(Long.toHexString(value), 16, '0');
    return CodecUtils.decodeHex(hexValue);
}

From source file:se.trixon.almond.GraphicsHelper.java

public static String colorToAABBGGRR(Color color, String... prefixSuffix) {
    String rr = StringUtils.leftPad(Integer.toHexString(color.getRed()), 2, "0");
    String gg = StringUtils.leftPad(Integer.toHexString(color.getGreen()), 2, "0");
    String bb = StringUtils.leftPad(Integer.toHexString(color.getBlue()), 2, "0");
    String aa = StringUtils.leftPad(Integer.toHexString(color.getAlpha()), 2, "0");
    StringBuilder builder = new StringBuilder();

    if (prefixSuffix.length > 0) {
        builder.append(prefixSuffix[0]);
    }/*w  w w  . j av  a 2  s. c o  m*/

    builder.append(aa).append(bb).append(gg).append(rr);

    if (prefixSuffix.length > 1) {
        builder.append(prefixSuffix[1]);
    }

    return builder.toString();
}

From source file:stepReport.model.PeriodoModel.java

public List<FuncionarioHoras> getHorasUnidadeMes(String mes) {
    String periodo[] = this.calcPeriodoMes(mes);
    String dataIni = mes.replace("/", "");

    String mesIni = dataIni.substring(2, 4);
    String anoIni = dataIni.substring(4, 8);
    dataIni = anoIni + mesIni + "01";
    String dataFim;//from  ww w .j a  v a2  s  .  co  m

    RelatoriosDAO conn = new RelatoriosDAOJDBCImpl();
    List<FuncionarioHoras> horas = null;
    if (mesIni.equals("12")) {
        dataFim = Integer.toString(Integer.parseInt(anoIni) + 1) + "0106";
        //horas = conn.totalHorasMensal(dataIni,dataFim);
    } else {
        dataFim = anoIni + StringUtils.leftPad(Integer.toString(Integer.parseInt(mesIni) + 1), 2, "0") + "06";
        //horas = conn.totalHorasMensal(dataIni,dataFim);
    }

    return null;
    //return horas;
}

From source file:ubic.gemma.core.analysis.preprocess.batcheffects.BatchInfoPopulationHelperServiceImpl.java

private String formatBatchName(int batchNum, DateFormat df, Date d) {
    String batchDateString;/*from ww w  .  ja v  a 2  s  .co m*/
    batchDateString = ExperimentalDesignUtils.BATCH_FACTOR_NAME_PREFIX
            + StringUtils.leftPad(Integer.toString(batchNum), 2, "0") + "_"
            + df.format(DateUtils.truncate(d, Calendar.HOUR));
    return batchDateString;
}

From source file:uk.org.funcube.fcdw.server.processor.DataProcessor.java

public static String convertHexBytePairToBinary(final String hexString) {
    final StringBuffer sb = new StringBuffer();

    for (int i = 0; i < hexString.length(); i += 2) {
        final String hexByte = hexString.substring(i, i + 2);
        final int hexValue = Integer.parseInt(hexByte, 16);
        sb.append(StringUtils.leftPad(Integer.toBinaryString(hexValue), 8, "0"));
    }//from w w  w  .jav a2 s .c  o m
    return sb.toString();
}

From source file:uk.org.funcube.fcdw.server.processor.FitterMessageProcessorImpl.java

private static String convertHexBytePairToBinary(final String hexString) {
    final StringBuffer sb = new StringBuffer();

    for (int i = 0; i < hexString.length(); i += 2) {
        final String hexByte = hexString.substring(i, i + 2);
        final int hexValue = Integer.parseInt(hexByte, 16);
        sb.append(StringUtils.leftPad(Integer.toBinaryString(hexValue), 8, "0"));
    }/*from  www. j  a  v  a 2 s.c o  m*/
    return sb.toString();
}

From source file:uk.org.funcube.fcdw.server.shared.Antenna.java

public final String toBinaryString() {
    final StringBuffer sb = new StringBuffer();
    sb.append(StringUtils.leftPad(Long.toString(antennaTemp0, 2), 8, ZERO));
    sb.append(StringUtils.leftPad(Long.toString(antennaTemp1, 2), 8, ZERO));
    sb.append(antennaDeployment0 ? ONE : ZERO);
    sb.append(antennaDeployment1 ? ONE : ZERO);
    sb.append(antennaDeployment2 ? ONE : ZERO);
    sb.append(antennaDeployment3 ? ONE : ZERO);
    return sb.toString();
}