List of usage examples for org.apache.commons.lang StringUtils leftPad
public static String leftPad(String str, int size, String padStr)
Left pad a String with a specified String.
From source file:com.syaku.commons.DateUtils.java
/** * @method : timeAdd(parameter, parameter2,parameter3) * @brief . 60 .//w w w. jav a 2 s. com * @parameters { parameter : (String) (-_:./\s) parameter2 : (String) (-_:./\s) parameter3 : (String) $1 = , $2 = , $3 = } * @return : (String) : 00:00:00 */ public static String timeAdd(String time, String time2, String patten) { String ret = "00:00:00"; if (StringUtils.isEmpty(patten)) patten = "$1:$2:$3"; int sh = Integer.parseInt(getTime("$1", time)); int sm = Integer.parseInt(getTime("$2", time)); int ss = Integer.parseInt(getTime("$3", time)); int eh = Integer.parseInt(getTime("$1", time2)); int em = Integer.parseInt(getTime("$2", time2)); int es = Integer.parseInt(getTime("$3", time2)); try { int h = sh + eh; int s = ss + es; int m = 0; if (s > 60) { Double mm = Math.floor(s / 60); df = new DecimalFormat("0"); int mmm = Integer.parseInt(df.format(mm)); s = s - (mmm * 60); m = m + mmm; } m = m + sm + em; if (m > 60) { Double hh = Math.floor(m / 60); df = new DecimalFormat("0"); int hhh = Integer.parseInt(df.format(hh)); m = m - (hhh * 60); h = h + hhh; } ret = StringUtils.leftPad(Integer.toString(h), 2, '0') + ":" + StringUtils.leftPad(Integer.toString(m), 2, '0') + ":" + StringUtils.leftPad(Integer.toString(s), 2, '0'); } catch (Exception e) { ret = "00:00:00"; } return getTime(patten, ret); }
From source file:fr.paris.lutece.plugins.workflow.modules.ticketingfacilfamilles.business.assignment.TaskAutomaticAssignmentDAO.java
@Override public List<UserAutomaticAssignmentConfig> initializeAssignementConf(int nIdTask) { int nSlotNb = AppPropertiesService.getPropertyInt(PROPERTY_AUTOMATIC_ASSIGNMENT_NB_SLOT, 100); for (int nCpt = 0; nCpt < nSlotNb; nCpt++) { DAOUtil daoUtil = new DAOUtil(SQL_QUERY_INSERT, PluginService.getPlugin(WorkflowTicketingFacilFamillesPlugin.PLUGIN_NAME)); int nIndex = 1; daoUtil.setInt(nIndex++, nIdTask); daoUtil.setString(nIndex++,//from w ww . j a v a 2s. c om StringUtils.leftPad(String.valueOf(nCpt), String.valueOf(nSlotNb).length() - 1, "0")); // no user assignment => set user_access_code to null daoUtil.setString(nIndex++, null); daoUtil.executeUpdate(); daoUtil.free(); } return getAllAutoAssignementConf(nIdTask); }
From source file:li.l1t.common.util.CommandHelper.java
/** * Returns an ASCII art bar indicating completion state of a task. * <br>/* w w w . ja v a2s .c o 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:com.haulmont.cuba.core.app.filestorage.amazon.AmazonS3FileStorage.java
/** * INTERNAL. Don't use in application code. *//* w w w . j a va2 s . c o m*/ protected String getStorageDir(Date createDate) { Calendar cal = Calendar.getInstance(); cal.setTime(createDate); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); return String.format("%d/%s/%s", year, StringUtils.leftPad(String.valueOf(month), 2, '0'), StringUtils.leftPad(String.valueOf(day), 2, '0')); }
From source file:com.asp.tranlog.TsvImporterMapper.java
/** * To create rowkey byte array, the rule is like this: row key can be * composed by several columns change every columns values to String, if * column type is date, change to long first if column values are "kv1 ", * "kv2", " kv3", ... then the row key string will be "kv1 +kv2+ kv3", * that means the space char will be kept * /*from w ww.j a v a2 s . co m*/ * @param lineBytes * @param parsed * @return * @throws BadTsvLineException */ protected byte[] createRowkeyByteArray(byte[] lineBytes, ImportTsv.TsvParser.ParsedLine parsed) throws BadTsvLineException { try { byte[] colBytes = null; Date tmpDate = null; StringBuffer sb = new StringBuffer(); for (int i = 0; i < keyColIndex.length; i++) { if (i > 0 && hbase_rowkey_separator.length() > 0) sb.append(hbase_rowkey_separator); colBytes = getInputColBytes(lineBytes, parsed, keyColIndex[i]); if (colBytes == null) throw new BadTsvLineException("Failed to get column bytes for " + keyColIndex[i]); String rowCol; if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_DATETIME) { tmpDate = parseTimestamp(colBytes, keyColIndex[i]); rowCol = Long.toString(tmpDate.getTime()); sb.append(rowCol); } else if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_STRING) { // String lineStr = new String(value.getBytes(), 0, // value.getLength(), "gb18030"); // byte[] lineBytes = new Text(lineStr).getBytes(); if (StringUtils.isEmpty(charset)) charset = HConstants.UTF8_ENCODING; String lineStr = new String(colBytes, charset); colBytes = new Text(lineStr).getBytes(); rowCol = Bytes.toString(colBytes); // if original string len < specified string len, then use // substring, else using space to right pad. if (keyColLen[i] != 0 && rowCol.length() > keyColLen[i]) sb.append(rowCol.substring(0, keyColLen[i])); else sb.append(StringUtils.rightPad(rowCol, keyColLen[i])); } else if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_INT) { int intVal = Integer.parseInt(Bytes.toString(colBytes)); rowCol = Integer.toString(intVal); sb.append(StringUtils.leftPad(rowCol, keyColLen[i], '0')); } else if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_DOUBLE) { double dbval = Double.parseDouble(Bytes.toString(colBytes)); rowCol = Double.toString(dbval); sb.append(rowCol); } else if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_LONG) { long longVal = Long.parseLong(Bytes.toString(colBytes)); rowCol = Long.toString(longVal); sb.append(StringUtils.leftPad(rowCol, keyColLen[i], '0')); } else { rowCol = Bytes.toString(colBytes); // if original string len < specified string len, then use // substring, else using space to right pad. if (keyColLen[i] != 0 && rowCol.length() > keyColLen[i]) sb.append(rowCol.substring(0, keyColLen[i])); else sb.append(StringUtils.rightPad(rowCol, keyColLen[i])); } } return sb.toString().getBytes(); } catch (Exception e) { throw new BadTsvLineException(e.getMessage()); } }
From source file:cross.datastructures.pipeline.ResultAwareCommandPipeline.java
/** * Calculates a byte-level digest of the given files. * * @param files the files to calculate the digest for. * @return the hexadecimal, zero-padded digest, or null if any exceptions * occurred//ww w .j a va 2 s .c o m */ public String digest(Collection<File> files) { try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); for (File file : files) { try (InputStream is = Files.newInputStream(file.toPath(), StandardOpenOption.READ)) { byte[] buffer = new byte[8192]; int read = 0; while ((read = is.read(buffer)) > 0) { digest.update(buffer, 0, read); } } catch (IOException ioex) { Logger.getLogger(ResultAwareCommandPipeline.class.getName()).log(Level.SEVERE, null, ioex); return null; } } byte[] sha1 = digest.digest(); BigInteger bigInt = new BigInteger(1, sha1); return StringUtils.leftPad(bigInt.toString(16), 40, "0"); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(ResultAwareCommandPipeline.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@GET @RequireAdmin//from w w w. j a v a 2 s.c o m @APIDescription("Gets config properties") @Produces({ MediaType.APPLICATION_JSON }) @DataType(LookupModel.class) @Path("/configproperties") public List<LookupModel> getConfigProperties() { List<LookupModel> lookupModels = new ArrayList<>(); Map<String, String> props = PropertiesManager.getAllProperties(); for (String key : props.keySet()) { LookupModel lookupModel = new LookupModel(); lookupModel.setCode(key); String value = props.get(key); if (key.contains(PropertiesManager.PW_PROPERTY)) { lookupModel.setDescription(StringUtils.leftPad("", value.length(), "*")); } else { lookupModel.setDescription(value); } lookupModels.add(lookupModel); } return lookupModels; }
From source file:com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.java
private void appendData(StringBuffer result, Character paddingChar, Integer offset, String data) { int zeroBasedOffset = offset - 1; while (result.length() < zeroBasedOffset) { result.append(paddingChar);/* w ww . j a v a 2 s.c o m*/ } int length = data.length(); if (result.length() < zeroBasedOffset + length) { result.append(StringUtils.leftPad("", (zeroBasedOffset + length) - result.length(), paddingChar)); } result.replace(zeroBasedOffset, zeroBasedOffset + length, data); }
From source file:de.cismet.cids.custom.utils.alkis.VermessungsrissPictureFinder.java
/** * DOCUMENT ME!/*from ww w . j a v a 2s .c om*/ * * @param schluessel DOCUMENT ME! * @param gemarkung DOCUMENT ME! * @param steuerbezirk DOCUMENT ME! * @param bezeichner DOCUMENT ME! * @param historisch isGrenzniederschrift DOCUMENT ME! * * @return DOCUMENT ME! * * @throws UnsupportedEncodingException DOCUMENT ME! */ public String getBuchwerkFilename(final String schluessel, final CidsBean gemarkung, final Integer steuerbezirk, final String bezeichner, final boolean historisch) throws UnsupportedEncodingException { final StringBuffer buf = new StringBuffer(); buf.append(getBuchwerkFolder(schluessel, gemarkung)); buf.append(SEP); if (SCHLUESSEL_ERGAENZUNGSKARTEN.equals(schluessel)) { buf.append(PREFIX_ERGAENZUNGSKARTEN).append("_"); } else if (SCHLUESSEL_FLURBUECHER1.equals(schluessel) || SCHLUESSEL_FLURBUECHER2.equals(schluessel)) { buf.append(PREFIX_FLURBUECHER).append("_"); } else if (SCHLUESSEL_LIEGENSCHAFTSBUECHER1.equals(schluessel) || SCHLUESSEL_LIEGENSCHAFTSBUECHER2.equals(schluessel)) { buf.append(PREFIX_LIEGENSCHAFTSBUECHER).append("_"); } else if (SCHLUESSEL_NAMENSVERZEICHNIS.equals(schluessel)) { buf.append(PREFIX_NAMENSVERZEICHNIS).append("_"); } buf.append(StringUtils.leftPad(schluessel, 3, '0')).append("-") .append(String.format("%04d", (Integer) gemarkung.getProperty("id"))).append("-") .append(historisch ? "001" : "000").append("-").append(steuerbezirk) .append(StringUtils.leftPad(bezeichner, 7, '0')); return buf.toString(); }
From source file:com.prowidesoftware.swift.model.mx.AbstractMX.java
/** * Returns the MX message identification.<br> * Composed by the business process, functionality, variant and version. * * @return the constructed message id//from ww w . j a v a2s .c om * @since 7.7 */ public MxId getMxId() { return new MxId(getBusinessProcess(), StringUtils.leftPad("" + getFunctionality(), 3, "0"), StringUtils.leftPad("" + getVariant(), 3, "0"), StringUtils.leftPad("" + getVersion(), 2, "0")); }