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

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

Introduction

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

Prototype

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

Source Link

Document

Right pad a String with a specified String.

Usage

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminVolume.java

/**
 *  ? ? ?     Console? /*  ww  w  .  java  2s  . c  o  m*/
 * 
 * @param volumeId  ?
 */
public void removeVolume(int volumeId) {
    try {
        if (dao.deleteVolume(volumeId)) { // success
            StringBuilder volumes = new StringBuilder(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("?")
                    .append(LINE_SEPERATOR);
            volumes.append("")
                    .append(StringUtils.center("removeVolume Successfully : " + volumeId, 100, " "))
                    .append("").append(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("")
                    .append(LINE_SEPERATOR);
            if (printlog) {
                log.info(volumes.toString());
            } else {
                out.print(volumes.toString());
            }
        } else {
            logger.log(LoggerIF.LOG_ERROR, "removeVolume() failed");
        }
    } catch (Exception e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    }
}

From source file:com.devnexus.ting.web.WebAppInitializer.java

public void setupContext(final ServletContext servletContext) {

    final String contextPath = "";
    final String server = servletContext.getServerInfo();

    final Apphome apphome = SystemInformationUtils.retrieveBasicSystemInformation();

    final String outMessage;
    SpringContextMode springContextMode = null;

    switch (apphome.getAppHomeSource()) {

    case SYSTEM_PROPERTY:
        outMessage = "System Property '" + Apphome.APP_HOME_DIRECTORY + "' found: " + apphome.getAppHomePath();
        break;// w  w w  .j  a  v  a 2  s .  co  m

    case ENVIRONMENT_VARIABLE:
        System.setProperty(Apphome.APP_HOME_DIRECTORY, apphome.getAppHomePath());

        outMessage = "Environment Variable '" + Apphome.APP_HOME_DIRECTORY + "' found: "
                + apphome.getAppHomePath() + ". Using it to set system property.";
        break;

    case USER_DIRECTORY:

        outMessage = "'" + Apphome.APP_HOME_DIRECTORY + "' not found. Please set '" + Apphome.APP_HOME_DIRECTORY
                + "' as a system property or as an environment variable. DEMO Mode, using embedded database.";
        break;
    case CLOUD:
        outMessage = "You are running in the cloud (CloudFoundry). No file system access available.";
        break;
    default:
        throw new IllegalStateException("Was expecting to resolve a home directory.");

    }

    if (SystemInformationUtils.existsConfigFile(apphome.getAppHomePath())) {
        springContextMode = SpringContextMode.ProductionContextConfiguration;
    } else {
        springContextMode = SpringContextMode.DemoContextConfiguration;
    }

    System.setProperty("ting-spring-profile", springContextMode.getCode());

    final StringBuilder bootMessage = new StringBuilder();

    bootMessage.append("\n");
    bootMessage.append(outMessage);
    bootMessage.append("\n");
    bootMessage.append("Using Spring Context: " + springContextMode);
    bootMessage.append("\n");
    bootMessage.append("Booting Ting...                          ").append("\n");
    bootMessage.append("-----------------------------------------------").append("\n");

    final String contextPathLabel = StringUtils.rightPad("Context Path", 40, '.');
    final String serverLabel = StringUtils.rightPad("Server", 40, '.');

    bootMessage.append(contextPathLabel + ": " + contextPath).append("\n");
    bootMessage.append(serverLabel + ": " + server).append("\n");

    bootMessage.append(SystemInformationUtils.getAllSystemProperties());
    bootMessage.append("-----------------------------------------------").append("\n");

    LOGGER.info(bootMessage.toString());
}

From source file:com.sds.acube.ndisc.mts.xserver.util.XNDiscUtils.java

/**
 *    ByteBuffer? ?? garbage ? ?// ww  w . j a v  a  2 s .  c  om
 * 
 * @param data
 *            ? ?
 * @param size
 *            ByteBuffer ?
 * @return padding? ?
 */
public static String getFormatString(String data, int size) {
    if (data.length() > size) {
        return data.substring(0, size);
    } else {
        return StringUtils.rightPad(data, size, "0");
    }
}

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

/**
 * @param toFill//from   w  ww . ja  v  a 2s. com
 * @param length
 * @return
 */
private String fillRight(String toFill, int length) {

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

From source file:li.l1t.common.util.CommandHelper.java

/**
 * Returns an ASCII art bar indicating completion state of a task.
 * <br>/*  w  w w .  j  a v a2 s . co m*/
 * <b>Example:</b><br>
 *  for (6,1,2)
 *
 * @param maxLength How many characters the bar will take up.
 * @param value     the current progress
 * @param max       the goal (100%)
 * @return A nice ASCII art bar using ASCII blocks.
 */
public static String getProgressBar(int maxLength, int value, int max) {
    Preconditions.checkArgument(value <= max, "The current progress may not be greater than the goal.");
    double factor = (((double) value) / ((double) max));
    maxLength -= 5;// "[]xx%".length
    byte linesToDraw = (byte) (maxLength * factor);
    return StringUtils.rightPad(StringUtils.rightPad("[", linesToDraw, '\u2588'), maxLength, '\u2592') + "]"
            + StringUtils.leftPad(((byte) (factor * 100)) + "%", 3, '0');
}

From source file:net.sourceforge.fenixedu.presentationTier.docs.academicAdministrativeOffice.ApprovementMobilityCertificate.java

@Override
protected String getCreditsAndGradeInfo(final ICurriculumEntry entry, final ExecutionYear executionYear) {
    final StringBuilder result = new StringBuilder();

    if (getDocumentRequest().isToShowCredits()) {
        getCreditsInfo(result, entry);// w  w  w .  j a v a  2  s. co m
    }
    result.append(entry.getGradeValue());
    result.append(StringUtils.rightPad(
            "(" + BundleUtil.getString(Bundle.ENUMERATION, getLocale(), entry.getGradeValue()) + ")",
            SUFFIX_LENGTH, ' '));

    result.append(", ");

    result.append(getEctsGradeDescription());
    result.append(SINGLE_SPACE);
    result.append(getEctsGrade(entry));
    result.append(SINGLE_SPACE);
    result.append(", ");

    final String in = BundleUtil.getString(Bundle.ACADEMIC, getLocale(), "label.in");
    if (executionYear == null) {
        result.append(StringUtils.rightPad(EMPTY_STR, in.length(), ' '));
        result.append(SINGLE_SPACE).append(StringUtils.rightPad(EMPTY_STR, 9, ' '));
    } else {
        result.append(in);
        result.append(SINGLE_SPACE).append(executionYear.getYear());
    }

    return result.toString();
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminVolume.java

/**
 *    ?   Console ? /* w  w w  .  jav  a2 s  .com*/
 * 
 * @param id  ?
 * @param name  
 * @param accessAuth  
 * @param desc  
 */
public void changeVolume(int id, String name, String accessAuth, String desc) {
    try {
        Volume volume = new Volume();
        volume.setId(id);
        volume.setName(name);
        volume.setAccessable(accessAuth);
        volume.setDesc(desc);
        if (dao.updateVolume(volume)) {
            StringBuilder volumes = new StringBuilder(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("?")
                    .append(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.center("changeVolume Successfully : " + id, 100, " "))
                    .append("").append(LINE_SEPERATOR);
            volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("")
                    .append(LINE_SEPERATOR);
            if (printlog) {
                log.info(volumes.toString());
            } else {
                out.print(volumes.toString());
            }
        } else {
            logger.log(LoggerIF.LOG_ERROR, "changeVolume() failed..");
        }
    } catch (Exception ex) {
        logger.log(LoggerIF.LOG_ERROR, ex.getMessage());
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminFile.java

/**
 * ?? ? ?  Console? //w w w. j  a v a2 s  . c  om
 * 
 * @param host HOST 
 * @param port PORT 
 * @param regFilePath ? ?(?  )
 * @param regVolId ?  ?
 * @param regStatType ? ? 
 */
public void regFile(String host, int port, String regFilePath, int regVolId, String regStatType) {
    NFile[] nFile = null;
    try {
        int numOfFiles = 1;
        nFile = new NFile[numOfFiles];
        nFile[0] = new NFile();
        nFile[0].setName(regFilePath);
        nFile[0].setVolumeId(regVolId);
        nFile[0].setStatType(regStatType);

        xnapi.XNDisc_Connect(host, port);
        String[] arrRet = xnapi.XNDISC_FileReg(nFile);
        if (null == arrRet) {
            logger.log(LoggerIF.LOG_ERROR, "XNDISC_FileReg() return null");
        } else {
            StringBuilder files = new StringBuilder(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", 100, "-")).append("?").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.center("Registered File ID : " + arrRet[0], 100, " "))
                    .append("").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", 100, "-") + "").append(LINE_SEPERATOR);
            if (printlog) {
                log.info(files.toString());
            } else {
                out.print(files.toString());
            }
        }
    } catch (FileException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } catch (NetworkException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } catch (NDiscException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } finally {
        try {
            xnapi.XNDisc_Disconnect();
        } catch (NetworkException ne) {
            logger.log(LoggerIF.LOG_ERROR, ne.getMessage());
        } catch (IOException e) {
            logger.log(LoggerIF.LOG_ERROR, e.getMessage());
        }
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminFile.java

/**
 * ? ? ? ??    Console? //w  ww  . j  a v a  2 s  . c om
 * 
 * @param host HOST 
 * @param port PORT 
 * @param fileId ? ?
 * @param destFilePath  ? (?)
 */
public void getFile(String host, int port, String fileId, String destFilePath) {
    try {
        int numOfFiles = 1;
        NFile[] nFile = new NFile[numOfFiles];
        nFile[0] = new NFile();
        nFile[0].setId(fileId);
        nFile[0].setName(destFilePath);
        nFile[0].setStatType(XNDiscAdminConfig.STAT_AUTO); // AUTO

        xnapi.XNDisc_Connect(host, port);
        boolean reg = xnapi.XNDISC_FileGet(nFile);
        if (reg) {
            StringBuilder files = new StringBuilder(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", 100, "-")).append("?").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.center("getFile : " + getName(destFilePath, 100), 100, " "))
                    .append("").append(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", 100, "-")).append("").append(LINE_SEPERATOR);
            if (printlog) {
                log.info(files.toString());
            } else {
                out.print(files.toString());
            }
        } else {
            logger.log(LoggerIF.LOG_ERROR, "getFile() failed.");
        }
    } catch (Exception ex) {
        logger.log(LoggerIF.LOG_ERROR, ex.getMessage());
        ex.printStackTrace();
    } finally {
        try {
            xnapi.XNDisc_Disconnect();
        } catch (NetworkException ne) {
            logger.log(LoggerIF.LOG_ERROR, ne.getMessage());
        } catch (IOException e) {
            logger.log(LoggerIF.LOG_ERROR, e.getMessage());
        }
    }
}

From source file:com.artivisi.biller.simulator.gateway.pln.PlnGateway.java

private StringBuffer createBit48InquiryPostpaidResponse(String bit48Request, Pelanggan p,
        List<TagihanPascabayar> daftarTagihan, List<TagihanPascabayar> tagihanDikirim,
        InquiryPostpaidResponse ipr) {/*  w  ww . j a v  a 2s  . c  o m*/
    StringBuffer bit48Response = new StringBuffer();
    bit48Response.append(bit48Request);
    bit48Response.append(tagihanDikirim.size());
    bit48Response.append(StringUtils.leftPad(String.valueOf(daftarTagihan.size()), 2, "0"));
    bit48Response.append(ipr.getId().toUpperCase());
    bit48Response.append(StringUtils.rightPad(p.getNama(), 25, " "));
    bit48Response.append(StringUtils.rightPad(p.getServiceUnit(), 5, " "));
    bit48Response.append(StringUtils.rightPad(p.getServiceUnitPhone(), 15, " "));
    bit48Response.append(StringUtils.rightPad(p.getSubscriberSegmentation(), 4, " "));
    bit48Response.append(StringUtils.leftPad(p.getPowerConsumingCategory(), 9, "0"));
    bit48Response.append(StringUtils.leftPad("", 9, "0")); // total admin charges

    for (TagihanPascabayar t : tagihanDikirim) {
        bit48Response.append(DateTimeFormat.forPattern("yyyyMM").print(t.getBillPeriod().getTime()));
        bit48Response.append(DateTimeFormat.forPattern("ddMMyyyy").print(t.getDueDate().getTime()));
        bit48Response.append(DateTimeFormat.forPattern("ddMMyyyy").print(t.getMeterReadDate().getTime()));
        bit48Response.append(
                StringUtils.leftPad(t.getBill().setScale(0, RoundingMode.HALF_EVEN).toString(), 11, "0"));
        if (BigDecimal.ZERO.compareTo(t.getInsentif()) > 0) {
            bit48Response.append("D");
        } else {
            bit48Response.append("C");
        }
        bit48Response.append(StringUtils
                .leftPad(t.getInsentif().abs().setScale(0, RoundingMode.HALF_EVEN).toString(), 10, "0"));
        bit48Response.append(
                StringUtils.leftPad(t.getVat().setScale(0, RoundingMode.HALF_EVEN).toString(), 10, "0"));
        bit48Response.append(
                StringUtils.leftPad(t.getDenda().setScale(0, RoundingMode.HALF_EVEN).toString(), 10, "0"));
        bit48Response.append(StringUtils.leftPad(t.getPreviousMeterRead1(), 8, "0"));
        bit48Response.append(StringUtils.leftPad(t.getCurrentMeterRead1(), 8, "0"));
        bit48Response.append(StringUtils.leftPad(t.getPreviousMeterRead2(), 8, "0"));
        bit48Response.append(StringUtils.leftPad(t.getCurrentMeterRead2(), 8, "0"));
        bit48Response.append(StringUtils.leftPad(t.getPreviousMeterRead3(), 8, "0"));
        bit48Response.append(StringUtils.leftPad(t.getCurrentMeterRead3(), 8, "0"));
    }
    return bit48Response;
}