/** * <p>Right pad a String with spaces (' ').</p> * * <p>The String is padded to the size of <code>size</code>.</p> * * <pre> * StringUtils.rightPad(null, *) = null * StringUtils.rightPad("", 3) = " " * StringUtils.rightPad("bat", 3) = "bat" * StringUtils.rightPad("bat", 5) = "bat " * StringUtils.rightPad("bat", 1) = "bat" * StringUtils.rightPad("bat", -1) = "bat" * </pre> * * @param str the String to pad out, may be null * @param size the size to pad to * @return right padded String or original String if no padding is necessary, * <code>null</code> if null String input */ public static String rightPad(String str, int size) { return rightPad(str, size, ' '); }
void setSystemInfoUrl(int processNumber, String url) { byte[] urlBytes = rightPad(url, SYSTEM_INFO_URL_SIZE_IN_BYTES).getBytes(StandardCharsets.US_ASCII); if (urlBytes.length > SYSTEM_INFO_URL_SIZE_IN_BYTES) { throw new IllegalArgumentException(format("System Info URL is too long. Max is %d bytes. Got: %s", SYSTEM_INFO_URL_SIZE_IN_BYTES, url)); } writeBytes(processNumber, SYSTEM_INFO_URL_BYTE_OFFSET, urlBytes); }
return rightPad(str, size, String.valueOf(padChar));
str = rightPad(str, size, padChar); return str;
str = rightPad(str, size, padStr); return str;
return rightPad(str, size, padStr.charAt(0));
public static synchronized String encrypt( String secret, String plainText ) { secret = substring( rightPad( secret, 16 ), 0, 16 ); SecretKey key = new SecretKeySpec( secret.getBytes(), "AES" ); try { cipher.init( Cipher.ENCRYPT_MODE, key ); byte[] cipherText = cipher.doFinal( plainText.getBytes() ); return new String( coder.encode( cipherText ) ); } catch ( Exception e ) { logger.error( "Encryption error", e ); } return null; }
@SuppressWarnings("unused") public static synchronized String decrypt( String secret, String codedText ) { secret = substring( rightPad( secret, 16 ), 0, 16 ); SecretKey key = new SecretKeySpec( secret.getBytes(), "AES" ); byte[] encypted = coder.decode( codedText.getBytes() ); try { cipher.init( Cipher.DECRYPT_MODE, key ); byte[] decrypted = cipher.doFinal( encypted ); return new String( decrypted ); } catch ( Exception e ) { logger.error( "Decryption error", e ); } return null; } }
public static String getPaddedValue(String val, int maxLength) { if (val == null) { return null; } if (maxLength < 0) { return val; } int valLength = val.codePointCount(0, val.length()); if (valLength > maxLength) { return enforceMaxLength(val, maxLength); } if (maxLength > valLength) { // Make sure we pad the right amount of spaces; valLength is in terms of code points, // while StringUtils.rpad() is based on the number of java chars. int padLength = val.length() + (maxLength - valLength); val = StringUtils.rightPad(val, padLength); } return val; }
public static CTabFolder createTabFolder( Composite composite, FormData fd, String... titles ) { Composite container = new Composite( composite, SWT.NONE ); WidgetUtils.setFormLayout( container, 0 ); container.setLayoutData( fd ); CTabFolder tabFolder = new CTabFolder( container, SWT.NONE ); tabFolder.setLayoutData( new FormDataBuilder().fullSize().result() ); for ( String title : titles ) { if ( title.length() < 8 ) { title = StringUtils.rightPad( title, 8 ); } Composite tab = new Composite( tabFolder, SWT.NONE ); WidgetUtils.setFormLayout( tab, ConstUI.MEDUIM_MARGIN ); CTabItem tabItem = new CTabItem( tabFolder, SWT.NONE ); tabItem.setText( title ); tabItem.setControl( tab ); } tabFolder.setSelection( 0 ); return tabFolder; }
private static String formatWithPadding(String[] columns, int[] padding, String delim, String paddingStr) { StringBuilder sb = new StringBuilder(); sb.append(delim); for (int i = 0; i < columns.length; i++) { sb.append(org.apache.commons.lang.StringUtils.rightPad(columns[i], padding[i], paddingStr)); sb.append(delim); } return sb.toString(); }
private static Object fill(FillDirection direction, Object inputObject, Object fillObject, Object requiredLengthObject)throws ParseException{ if(inputObject == null) { return null; } String input = inputObject.toString(); if(requiredLengthObject == null || fillObject == null) { throw new IllegalStateException("Required Length and Fill String are both required"); } String fill = fillObject.toString(); if(org.apache.commons.lang.StringUtils.isEmpty(fill)){ throw new IllegalStateException("The fill cannot be an empty string"); } fill = fill.substring(0,1); Integer requiredLength = ConversionUtils.convert(requiredLengthObject,Integer.class); if(requiredLength == null){ throw new IllegalStateException("Required Length not a valid Integer: " + requiredLengthObject.toString()); } if(direction == FillDirection.LEFT) { return org.apache.commons.lang.StringUtils.leftPad(input,requiredLength,fill); } return org.apache.commons.lang.StringUtils.rightPad(input,requiredLength,fill); }
private String getRps() { if (rpsQueue.size() < 1) return "<0.1"; else { BigDecimal d = new BigDecimal(rpsQueue.size() / 10.); d = d.setScale(1, RoundingMode.HALF_UP); return StringUtils.rightPad(""+d,2); } }
@Override protected String getCatalogValue(String origValue) { String[] origValueSplit = origValue.split("\\."); String majorVersion = origValueSplit[0]; String minorVersion = origValueSplit[1]; return StringUtils.leftPad(majorVersion, 2, "0") + "." + StringUtils.rightPad(minorVersion, 2, "0"); }
static void println(String text, @Nullable Double percent, AbstractTimeProfiling phaseProfiling) { StringBuilder sb = new StringBuilder(); sb.append(StringUtils.rightPad(text, TEXT_RIGHT_PAD)).append(StringUtils.leftPad(phaseProfiling.totalTimeAsString(), TIME_LEFT_PAD)); if (percent != null) { sb.append(" (").append((int) (phaseProfiling.totalTime() / percent)).append("%)"); } println(sb.toString()); }
private String getAlkamiskausi(HakukohdePerustieto curTulos) { String kausi = curTulos.getKoulutuksenAlkamiskausi().getUri(); kausi = kausi.substring(0, 1); return StringUtils.rightPad(kausi, 12); }
public static String getSpaceUniversityFiscalYear() { if (SPACE_UNIVERSITY_FISCAL_YEAR == null) { SPACE_UNIVERSITY_FISCAL_YEAR = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginEntryFull.class, KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR), ' '); } return SPACE_UNIVERSITY_FISCAL_YEAR; }
public static String getDashOrganizationReferenceId() { if (DASH_ORGANIZATION_REFERENCE_ID == null) { DASH_ORGANIZATION_REFERENCE_ID = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginEntryFull.class, KFSPropertyConstants.ORGANIZATION_REFERENCE_ID), '-'); } return DASH_ORGANIZATION_REFERENCE_ID; }
public static String getSpaceFinancialSystemOriginationCode() { if (SPACE_FINANCIAL_SYSTEM_ORIGINATION_CODE == null) { SPACE_FINANCIAL_SYSTEM_ORIGINATION_CODE = StringUtils.rightPad("", SpringContext.getBean(DataDictionaryService.class).getAttributeMaxLength(OriginationCode.class, KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE), ' '); } return SPACE_FINANCIAL_SYSTEM_ORIGINATION_CODE; }