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

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

Introduction

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

Prototype

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

Source Link

Document

Left pad a String with a specified String.

Usage

From source file:net.o3s.beans.registering.RegisteringBean.java

/**
  * String padding at left/*  w w  w.ja  v  a  2 s .co  m*/
  * @param s
  * @param n
  * @return
  */
 private String padLeft(String s, int n) {
     //        return String.format("%1$-" + n + "s", s);
     return StringUtils.leftPad(s, n, " ");

 }

From source file:com.artivisi.iso8583.Processor.java

public String messageToString(Message message) {
    message.calculateBitmap();//from  www  . j a  va 2  s  .  co  m

    LOGGER.debug("[MESSAGE2STRING] - [MTI] : [{}]", message.getMti());
    LOGGER.debug("[MESSAGE2STRING] - [Primary Bitmap] : [{}]", message.getPrimaryBitmapStream());
    LOGGER.debug("[MESSAGE2STRING] - [Secondary Bitmap] : [{}]", message.getSecondaryBitmapStream());
    LOGGER.debug("[MESSAGE2STRING] - [Data Element Content] : [{}]", message.getDataElementContent().size());

    StringBuilder builder = new StringBuilder();
    builder.append(message.getMti());
    builder.append(message.getPrimaryBitmapStream());
    builder.append(message.getSecondaryBitmapStream());

    for (int i = 2; i <= NUMBER_OF_DATA_ELEMENT; i++) {
        if (!message.isDataElementPresent(i)) {
            continue;
        }
        LOGGER.debug("[PROCESSING] - [DATA ELEMENT {}]", i);
        DataElement de = mapper.getDataElement().get(i);
        if (de == null) {
            LOGGER.error("[PROCESSING] - [DATA ELEMENT {}] : Not configured", i);
            throw new IllegalStateException("Invalid Mapper, Data Element [" + i + "] not configured");
        }

        LOGGER.debug("[PROCESSING] - [DATA ELEMENT {}] : Length : {}", i, de.getLengthType().name());
        if (DataElementLength.FIXED.equals(de.getLengthType())) {
            if (de.getLength() == null || de.getLength() < 1) {
                LOGGER.error(
                        "[PROCESSING] - [DATA ELEMENT {}] : Length not configured for fixed length element", i);
                throw new IllegalStateException("Invalid Mapper, Data Element [" + i
                        + "] length not configured for fixed length element");
            }

            builder.append(message.getDataElementContent().get(i));
            continue;
        }

        if (DataElementLength.VARIABLE.equals(de.getLengthType())) {
            if (de.getLengthPrefix() == null || de.getLengthPrefix() < 1) {
                LOGGER.error(
                        "[PROCESSING] - [DATA ELEMENT {}] : Length prefix not configured for variable length element",
                        i);
                throw new IllegalStateException("Invalid Mapper, Data Element [" + i
                        + "] length prefix not configured for variable length element");
            }

            String data = message.getDataElementContent().get(i);
            if (data == null) {
                data = "";
            }
            Integer dataLength = data.length();

            builder.append(StringUtils.leftPad(dataLength.toString(), de.getLengthPrefix(), "0"));
            builder.append(data);
            continue;
        }

        LOGGER.error("[PROCESSING] - [DATA ELEMENT {}] : Length type [{}] not fixed nor variable",
                new Object[] { i, de.getLengthType() });
        throw new IllegalStateException("Invalid Mapper, Data Element [" + i + "] length type ["
                + de.getLengthType() + "] not fixed nor variable");
    }
    return builder.toString();
}

From source file:com.github.jillesvangurp.persistentcachingmap.PersistentCachingMap.java

File bucketPath(long id) {
    String paddedId = StringUtils.leftPad("" + id, 10, '0');
    String d1 = paddedId.substring(0, 3);
    String d2 = paddedId.substring(3, 6);

    return new File(dataDir, d1 + "/" + d2 + "/" + paddedId);
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

private String getNextGeneratedBiCollectionUID(Study study) {
    Study studyToUse = null;/*from  w  ww.  j a v a  2 s  .c  o m*/
    if (study.getParentStudy() != null) {
        studyToUse = study.getParentStudy();
    } else {
        studyToUse = study;
    }
    BioCollectionUidTemplate biocollectionUidTemplate = getBioCollectionUidTemplate(studyToUse);
    String bioCollectionUidPrefix = new String("");
    String bioCollectionUidToken = new String("");
    String bioCollectionUidPaddedIncrementor = new String("");
    String bioCollectionUidPadChar = new String("0");
    StringBuilder nextIncrementedBioCollectionUid = new StringBuilder("");
    StringBuilder biospecimenUid = new StringBuilder();

    if (biocollectionUidTemplate != null) {
        if (biocollectionUidTemplate.getBioCollectionUidPrefix() != null)
            bioCollectionUidPrefix = biocollectionUidTemplate.getBioCollectionUidPrefix();

        if (biocollectionUidTemplate.getBioCollectionUidToken() != null
                && biocollectionUidTemplate.getBioCollectionUidToken().getName() != null) {
            bioCollectionUidToken = biocollectionUidTemplate.getBioCollectionUidToken().getName();
        }

        if (biocollectionUidTemplate.getBioCollectionUidPadChar() != null
                && biocollectionUidTemplate.getBioCollectionUidPadChar().getName() != null) {
            bioCollectionUidPadChar = biocollectionUidTemplate.getBioCollectionUidPadChar().getName().trim();
        }

        int incrementedValue = getNextUidSequence(studyToUse).intValue();
        nextIncrementedBioCollectionUid = nextIncrementedBioCollectionUid.append(incrementedValue);

        int size = Integer.parseInt(bioCollectionUidPadChar);
        bioCollectionUidPaddedIncrementor = StringUtils.leftPad(nextIncrementedBioCollectionUid.toString(),
                size, "0");
        biospecimenUid.append(bioCollectionUidPrefix);
        biospecimenUid.append(bioCollectionUidToken);
        biospecimenUid.append(bioCollectionUidPaddedIncrementor);
    } else {
        biospecimenUid = null;
    }

    // handle for a null BiospecimenUID
    if (biospecimenUid == null || biospecimenUid.length() == 0) {
        String uid = "" + getNextUidSequence(studyToUse); //UniqueIdGenerator.generateUniqueId();
        biospecimenUid = new StringBuilder();
        biospecimenUid.append(uid);
        log.error("Biocollection Template is not defined for the Study: " + studyToUse.getName());
    }

    return biospecimenUid.toString();
}

From source file:io.mandrel.OtherTest.java

public void inspect(int level, Type clazz, String name) {

    if (level > 6)
        return;//from www. j  a v  a2  s .  c  o m

    if (clazz instanceof Class && !((Class<?>) clazz).isEnum() && ((Class<?>) clazz).getPackage() != null
            && ((Class<?>) clazz).getPackage().getName().startsWith("io.mandrel")) {
        int newLevel = level + 1;
        Field[] fields = ((Class<?>) clazz).getDeclaredFields();

        for (Field field : fields) {
            Class<?> fieldType = field.getType();
            String text;
            if (!field.isAnnotationPresent(JsonIgnore.class) && !Modifier.isStatic(field.getModifiers())) {
                if (List.class.equals(fieldType) || Map.class.equals(fieldType)) {
                    Type type = field.getGenericType();
                    if (type instanceof ParameterizedType) {
                        ParameterizedType pType = (ParameterizedType) type;
                        Type paramType = pType.getActualTypeArguments()[pType.getActualTypeArguments().length
                                - 1];

                        text = field.getName() + "(container of " + paramType + ")";
                        System.err.println(StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                        inspect(newLevel, paramType, "");
                    }
                } else {
                    text = field.getName()
                            + (field.getType().isPrimitive() || field.getType().equals(String.class)
                                    || field.getType().equals(LocalDateTime.class)
                                            ? " (" + field.getType().getName() + ")"
                                            : "");
                    System.err.println(StringUtils.leftPad(text, text.length() + newLevel * 5, "\t-   "));
                    inspect(newLevel, fieldType, field.getName());
                }

                // JsonSubTypes subtype =
                // fieldType.getAnnotation(JsonSubTypes.class);
                // if (subtype != null) {
                // int subLevel = level + 2;
                // text = "subtypes:";
                // System.err.println(StringUtils.leftPad(text,
                // text.length() + subLevel * 5, "\t-   "));
                // for (JsonSubTypes.Type type : subtype.value()) {
                // text = "subtype:" + type.name();
                // System.err.println(StringUtils.leftPad(text,
                // text.length() + (subLevel + 1) * 5, "\t-   "));
                // inspect((subLevel + 1), type.value(), type.name());
                // }
                // }
            }
        }

        JsonSubTypes subtype = ((Class<?>) clazz).getAnnotation(JsonSubTypes.class);
        if (subtype != null) {
            int subLevel = level + 1;
            String text = "subtypes:";
            System.err.println(StringUtils.leftPad(text, text.length() + subLevel * 5, "\t-   "));
            for (JsonSubTypes.Type type : subtype.value()) {
                text = "subtype:" + type.name();
                System.err.println(StringUtils.leftPad(text, text.length() + (subLevel + 1) * 5, "\t-   "));
                inspect((subLevel + 1), type.value(), type.name());
            }
        }
    }
}

From source file:com.music.web.MusicController.java

@RequestMapping("/purchase/download/{id}/{hmac}")
public void downloadPurchase(@PathVariable String id, @PathVariable String hmac, HttpServletResponse response)
        throws IOException {
    if (SecurityUtils.hmac(StringUtils.leftPad(id, 10, '0'), hmacKey).equals(hmac)) {
        response.setContentType("application/zip");
        response.setHeader("Content-Disposition",
                "Content-Disposition: attachment; filename=computoser-tracks-" + id + ".zip;");
        purchaseService.download(Long.parseLong(id), response.getOutputStream());
    }/*from www .j a  va  2s .c  om*/
}

From source file:de.cismet.cids.custom.utils.alkis.VermessungsrissPictureFinder.java

/**
 * DOCUMENT ME!//  w w  w. j  a  v a 2  s.  c  om
 *
 * @param   withPath              DOCUMENT ME!
 * @param   isGrenzniederschrift  blattnummer DOCUMENT ME!
 * @param   schluessel            laufendeNummer DOCUMENT ME!
 * @param   gemarkung             DOCUMENT ME!
 * @param   flur                  DOCUMENT ME!
 * @param   blatt                 DOCUMENT ME!
 *
 * @return  DOCUMENT ME!
 */
public String getObjectFilename(final boolean withPath, final boolean isGrenzniederschrift,
        final String schluessel, final Integer gemarkung, final String flur, final String blatt) {
    final boolean isErganzungskarte = SCHLUESSEL_ERGAENZUNGSKARTEN.equals(schluessel);
    final StringBuffer buf = new StringBuffer();
    if (isGrenzniederschrift) {
        buf.append(PREFIX_GRENZNIEDERSCHRIFT);
    } else {
        buf.append(PREFIX_VERMESSUNGSRISS);
    }
    buf.append("_");
    buf.append(StringUtils.leftPad(schluessel, 3, '0'));
    buf.append("-");
    buf.append(String.format("%04d", gemarkung));
    buf.append("-");
    buf.append(StringUtils.leftPad(flur, 3, '0'));
    buf.append("-");
    buf.append(StringUtils.leftPad(blatt, 8, '0'));
    final StringBuffer b = new StringBuffer();
    if (withPath) {
        b.append(getFolder(isErganzungskarte, isGrenzniederschrift, gemarkung));
        b.append(SEP);
    }
    b.append(buf.toString());
    return b.toString();
}

From source file:br.com.nordestefomento.jrimum.texgit.type.component.Filler.java

/**
 * @param toFill/*ww w  .j a v  a2  s . c o  m*/
 * @param length
 * @return
 */
private String fillLeft(String toFill, int length) {

    return StringUtils.leftPad(toFill, length, padding.toString());
}

From source file:com.skratchdot.electribe.model.esx.presentation.EsxComposite.java

/**
 * This function is intended to be called from within a loop, passing
 * a different currentIndex each time.  It will return the given string
 * with a number appended to the end of it.
 * @param string The string to append a number to
 * @param currentIndex The current index (the number appended will be currentIndex+1)
 * @param listSize The total size of the list you are appending numbers to
 * @param maxAppendStringLength The maximum length of the string that is returned
 * @return/*from www.  ja v a  2 s .c om*/
 */
protected String getMultiNumberString(final String string, final int currentIndex, final int listSize,
        final int maxAppendStringLength) {
    if (listSize <= 1) {
        return string;
    } else {
        int listSizeStringLength = Integer.toString(listSize).length();
        return StringUtils.left(string, maxAppendStringLength - listSizeStringLength)
                + StringUtils.leftPad(Integer.toString(currentIndex + 1), listSizeStringLength, "0");
    }
}

From source file:io.github.jeddict.jcode.task.AbstractNBTask.java

@Override
public void log(String msg, int padding) {
    String messages[] = msg.split("\n");
    log(messages[0], true);/*  ww  w. j  ava2  s  .  co  m*/
    for (int i = 1; i < messages.length; i++) {
        log(StringUtils.leftPad("\t" + messages[i], padding * 2 - 1, ' '), true);
        //            log("\t" + padLeft(messages[i], padding - 1), true);
    }
}