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:org.qifu.service.impl.SysMailHelperServiceImpl.java

@Override
public String findForMaxMailIdComplete(String mailId) throws ServiceException, Exception {
    if (StringUtils.isBlank(mailId) || !SimpleUtils.isDate(mailId)) {
        throw new ServiceException(SysMessageUtil.get(SysMsgConstants.PARAMS_BLANK));
    }/*  www  .  j  a va  2s . co m*/
    String maxMailId = this.findForMaxMailId(mailId);
    if (StringUtils.isBlank(maxMailId)) {
        return mailId + "000000001";
    }
    int maxSeq = Integer.parseInt(maxMailId.substring(8, 17)) + 1;
    if (maxSeq > 999999999) {
        throw new ServiceException(
                SysMessageUtil.get(SysMsgConstants.DATA_ERRORS) + " over max mail-id 999999999!");
    }
    return mailId + StringUtils.leftPad(String.valueOf(maxSeq), 9, "0");
}

From source file:org.qifu.util.PdfConvertUtils.java

public static List<File> toImageFiles(File pdfFile, int resolution) throws Exception {
    PDDocument document = PDDocument.load(pdfFile);
    PDFRenderer pdfRenderer = new PDFRenderer(document);
    /*/*from ww w.j  a va 2  s .c  o m*/
    List<PDPage> pages = new LinkedList<PDPage>();
    for (int i=0; i < document.getDocumentCatalog().getPages().getCount(); i++) {
       pages.add( document.getDocumentCatalog().getPages().get(i) );
    }
    */
    File tmpDir = new File(Constants.getWorkTmpDir() + "/" + PdfConvertUtils.class.getSimpleName() + "/"
            + System.currentTimeMillis() + "/");
    FileUtils.forceMkdir(tmpDir);
    List<File> files = new LinkedList<File>();
    //int len = String.valueOf(pages.size()+1).length();
    int len = String.valueOf(document.getDocumentCatalog().getPages().getCount() + 1).length();
    //for (int i=0; i<pages.size(); i++) {
    for (int i = 0; i < document.getDocumentCatalog().getPages().getCount(); i++) {
        String name = StringUtils.leftPad(String.valueOf(i + 1), len, "0");
        BufferedImage bufImage = pdfRenderer.renderImageWithDPI(i, resolution, ImageType.RGB);
        File imageFile = new File(tmpDir.getPath() + "/" + name + ".png");
        FileOutputStream fos = new FileOutputStream(imageFile);
        ImageIOUtil.writeImage(bufImage, "png", fos, resolution);
        fos.flush();
        fos.close();
        files.add(imageFile);
    }
    document.close();
    tmpDir = null;
    return files;
}

From source file:org.rifidi.edge.adapter.llrp.LLRPEventFactory.java

/**
 * This method parses a RO_ACCESS_REPORT into a ReadCycle
 * /*www  .ja v a 2 s  . c  o  m*/
 * @param rar
 *            The RO_ACCESS_REPORT to parse
 * @param readerID
 *            The reader ID of the reader that got the report
 * @return
 */
private static ReadCycle createReadCycle(RO_ACCESS_REPORT rar, String readerID,
        Map<Integer, Integer> rssiFilterMap) {
    List<TagReportData> trdl = rar.getTagReportDataList();
    Set<TagReadEvent> tagreaderevents = new HashSet<TagReadEvent>();
    for (TagReportData t : trdl) {
        AntennaID antid = t.getAntennaID();
        EPCGeneration2Event gen2event = new EPCGeneration2Event();
        if (t.getEPCParameter() instanceof EPCData) {
            int epcLength = 0; // in 16-bit words
            List<AirProtocolTagData> aptdList = t.getAirProtocolTagDataList();
            if (aptdList != null) {
                for (AirProtocolTagData aptd : aptdList) {
                    if (aptd instanceof C1G2_PC) {
                        UnsignedShort pcBits = ((C1G2_PC) aptd).getPC_Bits();
                        if (pcBits != null && pcBits.toInteger() != null) {
                            epcLength = pcBits.intValue() >>> 11;
                            // Multiply by 4 to get the length
                            epcLength = epcLength * 4;
                        }
                    }
                }
            }
            EPCData id = (EPCData) t.getEPCParameter();
            String EPCData = id.getEPC().toString();
            EPCData = StringUtils.leftPad(EPCData, epcLength * 2, "0");
            gen2event.setEPCMemory(parseString(EPCData), EPCData, (id.getByteLength() - 1) * 8);
        } else {
            int epcLength = 0;
            List<AirProtocolTagData> aptdList = t.getAirProtocolTagDataList();
            if (aptdList != null) {
                for (AirProtocolTagData aptd : aptdList) {
                    if (aptd instanceof C1G2_PC) {
                        UnsignedShort pcBits = ((C1G2_PC) aptd).getPC_Bits();
                        if (pcBits != null && pcBits.toInteger() != null) {
                            epcLength = pcBits.intValue() >>> 11;
                            // Multiply by 4 to get the length
                            epcLength = epcLength * 4;
                        }
                    }
                }
            }
            EPC_96 id = (EPC_96) t.getEPCParameter();
            String EPCData = id.getEPC().toString();
            EPCData = StringUtils.leftPad(EPCData, epcLength, "0");
            gen2event.setEPCMemory(parseString(EPCData), EPCData, 96);
        }
        TagReadEvent tag;
        if (t.getLastSeenTimestampUTC() == null) {
            tag = new TagReadEvent(readerID, gen2event, antid.getAntennaID().intValue(),
                    System.currentTimeMillis());
        } else {
            tag = new TagReadEvent(readerID, gen2event, antid.getAntennaID().intValue(),
                    t.getLastSeenTimestampUTC().getMicroseconds().toLong() / 1000);

        }
        // Add the custom information to the tags.
        if (t.getROSpecID() != null) {
            String rosid = t.getROSpecID().getROSpecID().toInteger().toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.ROSPEC_ID, rosid);
        }
        if (t.getPeakRSSI() != null) {
            Integer rssi = t.getPeakRSSI().getPeakRSSI().toInteger();
            try {
                if (rssiFilterMap != null) {
                    boolean filter = false;
                    if (rssiFilterMap.get(tag.getAntennaID()) != null
                            && rssiFilterMap.get(tag.getAntennaID()) != 0) {
                        filter = rssiFilterMap.get(tag.getAntennaID()) > rssi;
                    } else if (rssiFilterMap.get(0) != null && rssiFilterMap.get(0) != 0) {
                        filter = rssiFilterMap.get(0) > rssi;
                    }
                    if (filter) {
                        continue;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            tag.addExtraInformation(StandardTagReadEventFieldNames.RSSI, rssi.toString());
        }

        if (t.getSpecIndex() != null) {
            String specindex = t.getSpecIndex().getSpecIndex().toInteger().toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.SPEC_INDEX, specindex);
        }
        if (t.getInventoryParameterSpecID() != null) {
            String invparamspecid = t.getInventoryParameterSpecID().getInventoryParameterSpecID().toInteger()
                    .toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.INVPARAMSPECID, invparamspecid);
        }

        if (t.getChannelIndex() != null) {
            String channelindex = t.getChannelIndex().getChannelIndex().toInteger().toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.CHANNELINDEX, channelindex);
        }

        if (t.getFirstSeenTimestampUTC() != null) {
            String firstseenutc = t.getFirstSeenTimestampUTC().getMicroseconds().toBigInteger().toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.FIRSTSEENUTC, firstseenutc);
        }

        if (t.getFirstSeenTimestampUptime() != null) {
            String firstseenuptime = t.getFirstSeenTimestampUptime().getMicroseconds().toBigInteger()
                    .toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.FIRSTSEENUPTIME, firstseenuptime);
        }

        if (t.getLastSeenTimestampUTC() != null) {
            String lastseenutc = t.getLastSeenTimestampUTC().getMicroseconds().toBigInteger().toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.LASTSEENUTC, lastseenutc);
        }

        if (t.getLastSeenTimestampUptime() != null) {
            String lastseenuptime = t.getLastSeenTimestampUptime().getMicroseconds().toBigInteger().toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.LASTSEENUPTIME, lastseenuptime);
        }

        if (t.getTagSeenCount() != null) {
            String tagseencount = t.getTagSeenCount().getTagCount().toInteger().toString();
            tag.addExtraInformation(LLRPTagReadEventFieldNames.TAGSEENCOUNT, tagseencount);
        }

        for (AirProtocolTagData aptd : t.getAirProtocolTagDataList()) {
            if (aptd instanceof C1G2_CRC) {
                String crc = ((C1G2_CRC) aptd).getCRC().toInteger().toString();
                tag.addExtraInformation(LLRPTagReadEventFieldNames.AIRPROT_CRC, crc);
            } else if (aptd instanceof C1G2_PC) {
                String pc = ((C1G2_PC) aptd).getPC_Bits().toInteger().toString();
                tag.addExtraInformation(LLRPTagReadEventFieldNames.AIRPROT_PC, pc);
            }
        }
        if (logger.isDebugEnabled()) {
            logger.debug(tag.getTag().getFormattedID() + " ANT: " + tag.getAntennaID());
        }

        tagreaderevents.add(tag);
    }

    if (tagreaderevents.size() == 0) {
        return null;
    }

    return new ReadCycle(tagreaderevents, readerID, System.currentTimeMillis());
}

From source file:org.segrada.model.base.AbstractColoredModel.java

@Override
public String getColorCode() {
    return (color == null) ? "" : "#" + StringUtils.leftPad(Long.toHexString(color).toUpperCase(), 6, "0");
}

From source file:org.segrada.search.SearchHit.java

public String getColorCode() {
    return (color == null) ? "" : "#" + StringUtils.leftPad(Long.toHexString(color).toUpperCase(), 6, "0");
}

From source file:org.springframework.cloud.sleuth.annotation.SleuthSpanCreatorAspectFluxTests.java

private static String toHexString(long value) {
    return StringUtils.leftPad(Long.toHexString(value), 16, '0');
}

From source file:org.springframework.xd.dirt.integration.bus.MessageBusSupportBenchmarkTests.java

@Test
public void run() {
    StopWatch watch = new StopWatch("MessageBusSupport");
    watch.start("simple tuple codec");
    runBenchmark(TupleBuilder.tuple().of("foo", "bar", "val", 1234));
    watch.stop();/*from   w  w  w  .  j  av  a 2  s  . co  m*/
    watch.start("string payload");
    runBenchmark(StringUtils.leftPad("hello", 1000, "*"));
    watch.stop();
    System.out.println(watch.prettyPrint());
}

From source file:org.squashtest.tm.domain.requirement.RequirementVersionAttachmentBridge.java

private String padRawValue(long rawValue) {
    return StringUtils.leftPad(Long.toString(rawValue), EXPECTED_LENGTH, '0');
}

From source file:org.squashtest.tm.domain.search.CollectionSizeBridge.java

private String padRawValue(String rawValue) {
    return StringUtils.leftPad(rawValue, EXPECTED_LENGTH, '0');
}

From source file:org.squashtest.tm.domain.testcase.TestCaseCallStepBridge.java

private String padRawValue(Long rawValue) {
    return StringUtils.leftPad(Long.toString(rawValue), EXPECTED_LENGTH, '0');
}