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:ec.edu.distri.clientejava.protocolo.Cabecera.java

public void setOriginador(String originador) {
    this.originador = StringUtils.leftPad(originador, 4, "0");
}

From source file:com.daraf.projectdarafprotocol.Cabecera.java

public void setOriginador(String originador) {
    this.originador = StringUtils.leftPad(originador, 20, "0");
}

From source file:annis.libgui.MatchedNodeColors.java

private String twoDigitHex(int i) {
    String result = Integer.toHexString(i).toLowerCase(new Locale("en"));

    if (result.length() > 2) {
        result = result.substring(0, 2);
    } else if (result.length() < 2) {
        result = StringUtils.leftPad(result, 2, '0');
    }/*from w  ww . j a  v  a  2 s.  c  o  m*/
    return result;
}

From source file:com.github.bjoern2.codegen.StringGenerator.java

@Override
public Generator writeLines(List<String> lines, String prefix, String postfix, int tabs) {
    for (String line : lines) {
        write(StringUtils.leftPad("", tabs, "\t") + prefix + line + postfix + "\n");
    }//from  ww  w .  j  a  va  2  s. c o m
    return this;
}

From source file:com.thinkbiganalytics.discovery.util.ParserHelperTest.java

@Test
public void testInvalidFile() throws Exception {
    String text = StringUtils.leftPad("Z", ParserHelper.MAX_CHARS, "Z");
    try {//from   www . ja v a 2s  .com
        textExtract(text, 100, 1);
        fail();
    } catch (IOException e) {
        // good
    }
}

From source file:dk.dma.ais.utils.aisbus.AisBusLauncher.java

@Override
protected void runDaemon(Injector injector) throws Exception {
    LOG.info("Starting AisBusLauncher with configuration: " + confFile);
    try {/*w  ww  .j  a  va 2  s.  co m*/
        aisBus = AisBusFactory.get(confFile);
    } catch (FileNotFoundException e) {
        LOG.error(e.getMessage());
        return;
    }
    LOG.info("Starting AisBus");
    aisBus.start();
    LOG.info("Starting consumers");
    aisBus.startConsumers();
    LOG.info("Starting providers");
    aisBus.startProviders();

    Thread.sleep(2000);

    while (true) {
        LOG.debug(StringUtils.leftPad("", 100, '-'));
        ratePrint(aisBus, null);
        for (AisBusProvider provider : aisBus.getProviders()) {
            ratePrint(provider, provider.getName());
            if (provider instanceof TcpServerProvider) {
                for (TcpClient tcpClient : ((TcpServerProvider) provider).getServer().getClients()) {
                    ratePrint(tcpClient);
                }
            }
        }
        for (AisBusConsumer consumer : aisBus.getConsumers()) {
            ratePrint(consumer, consumer.getName());
            if (consumer instanceof TcpServerConsumer) {
                for (TcpClient tcpClient : ((TcpServerConsumer) consumer).getServer().getClients()) {
                    ratePrint(tcpClient);
                }
            }
        }
        LOG.debug(StringUtils.leftPad("", 100, '-'));
        Thread.sleep(60000);
    }

}

From source file:com.daraf.projectdarafprotocol.Cabecera.java

public void setLongitudCuerpo(String longitudCuerpo) {
    this.longitudCuerpo = StringUtils.leftPad(longitudCuerpo, 4, "0");
}

From source file:net.openhft.chronicle.logger.slf4j.Slf4jVanillaChronicleBinaryLoggerPerfTest.java

@Test
public void testSingleThreadLogging1() throws IOException {
    Thread.currentThread().setName("perf-plain-vanilla");

    final String testId = "perf-binary-vanilla-chronicle";
    final Logger clogger = LoggerFactory.getLogger(testId);
    final long items = 1000000;

    warmup(clogger);//from   ww w . ja  va2 s  . c  o  m

    for (int s = 64; s <= 1024; s += 64) {
        final String staticStr = StringUtils.leftPad("", s, 'X');

        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(staticStr);
        }

        long cEnd1 = System.nanoTime();

        System.out.printf("items=%03d size=%04d => chronology=%.3f ms, chronology-average=%.3f us\n", items,
                staticStr.length(), (cEnd1 - cStart1) / 1e6, (cEnd1 - cStart1) / items / 1e3);
    }

    ChronicleTools.deleteOnExit(basePath(testId));
}

From source file:net.openhft.chronicle.logger.slf4j.Slf4jIndexedChronicleBinaryLoggerPerfTest.java

@Test
public void testSingleThreadLogging1() throws IOException {
    Thread.currentThread().setName("perf-plain-indexed");

    final String testId = "perf-binary-indexed-chronicle";
    final Logger clogger = LoggerFactory.getLogger(testId);
    final long items = 1000000;

    warmup(clogger);/* www .j  a v  a 2 s . c om*/

    for (int s = 64; s <= 1024; s += 64) {
        final String staticStr = StringUtils.leftPad("", s, 'X');

        long cStart1 = System.nanoTime();

        for (int i = 1; i <= items; i++) {
            clogger.info(staticStr);
        }

        long cEnd1 = System.nanoTime();

        System.out.printf("items=%03d size=%04d => chronology=%.3f ms, chronology-average=%.3f us\n", items,
                staticStr.length(), (cEnd1 - cStart1) / 1e6, (cEnd1 - cStart1) / items / 1e3);
    }

    ChronicleTools.deleteOnExit(basePath(testId));
}

From source file:com.sangupta.passcode.HashStream.java

private static String asBinary(byte[] hash) {
    String binary = "";
    for (byte b : hash) {
        int unsigned = b & 0xFF;
        String bin = Integer.toBinaryString(unsigned);
        bin = StringUtils.leftPad(bin, 8, '0');
        binary = binary + bin;/*w w  w  .  ja v a2  s  . co m*/
    }

    return binary;
}