List of usage examples for org.apache.commons.lang3 StringUtils rightPad
public static String rightPad(final String str, final int size, String padStr)
Right pad a String with a specified String.
The String is padded to the size of size .
StringUtils.rightPad(null, *, *) = null StringUtils.rightPad("", 3, "z") = "zzz" StringUtils.rightPad("bat", 3, "yz") = "bat" StringUtils.rightPad("bat", 5, "yz") = "batyz" StringUtils.rightPad("bat", 8, "yz") = "batyzyzy" StringUtils.rightPad("bat", 1, "yz") = "bat" StringUtils.rightPad("bat", -1, "yz") = "bat" StringUtils.rightPad("bat", 5, null) = "bat " StringUtils.rightPad("bat", 5, "") = "bat "
From source file:com.github.tomakehurst.wiremock.RecordingDslAcceptanceTest.java
@Test public void doesNotWriteTextResponseFilesUnder1KbByDefault() { targetService.stubFor(get("/small.txt").willReturn( aResponse().withHeader(CONTENT_TYPE, "text/plain").withBody(StringUtils.rightPad("", 10239, 'a')))); proxyingService.startRecording(recordSpec().forTarget(targetBaseUrl)); client.get("/small.txt"); List<StubMapping> mappings = proxyingService.stopRecording().getStubMappings(); String bodyFileName = mappings.get(0).getResponse().getBodyFileName(); assertThat(bodyFileName, nullValue()); }
From source file:ca.uhn.fhir.model.primitive.BaseDateTimeDt.java
/** * Returns the nanoseconds within the current second * <p>/*from w ww. j ava 2 s .c o m*/ * Note that this method returns the * same value as {@link #getMillis()} but with more precision. * </p> */ public Long getNanos() { if (isBlank(myFractionalSeconds)) { return null; } String retVal = StringUtils.rightPad(myFractionalSeconds, 9, '0'); retVal = retVal.substring(0, 9); return Long.parseLong(retVal); }
From source file:com.moviejukebox.scanner.artwork.ArtworkScanner.java
/** * Pretty print method for the debug property output * * @param propName//from w w w.j a va 2s .c o m * @param propValue * @param addTypeToOutput */ protected final void debugProperty(String propName, Object propValue, boolean addTypeToOutput) { StringBuilder property = new StringBuilder("DEBUG - '"); if (addTypeToOutput) { property.append(artworkTypeName); } property.append( StringUtils.rightPad(propName + "' ", (addTypeToOutput ? 40 : 40 + artworkTypeName.length()), ".")) .append(" = "); property.append(propValue); LOG.debug(property.toString()); }
From source file:com.francetelecom.clara.cloud.core.service.ManageApplicationImplTest.java
@Test public void syntaxically_invalid_config_roles_are_rejected() throws ApplicationNotFoundException { TestHelper.loginAsUser(); // given Bob is authenticated Application elpaaso = new Application("elpaaso", "elpaaso"); Set<SSOId> joynMembers = new HashSet<>(); joynMembers.add(new SSOId(TestHelper.USER_WITH_USER_ROLE_SSOID.getValue())); elpaaso.setAsPrivate();/*from w w w .j a v a 2 s .co m*/ elpaaso.setMembers(joynMembers); Mockito.when(applicationRepository.findByUid(elpaaso.getUID())).thenReturn(elpaaso); Mockito.when(applicationRepository.findByUid(elpaaso.getUID())).thenReturn(elpaaso); //given invalid config role: too large comment List<ConfigOverrideDTO> overrideConfigs = new ArrayList<>(); String tooLargeComment = StringUtils.rightPad("value", ConfigOverrideDTO.MAX_CONFIG_VALUE_LENGTH + 2, 'X'); ConfigOverrideDTO configOverrideDTO = new ConfigOverrideDTO("configSet", "key", tooLargeComment, "comment"); overrideConfigs.add(configOverrideDTO); //when try { manageApplication.createConfigRole(elpaaso.getUID(), "role label", overrideConfigs); fail("expected config role to be rejected with invalid config role"); } catch (InvalidConfigOverrideException e) { Assert.assertTrue(e.getFaultyOverride() == configOverrideDTO); } }
From source file:nl.sidn.dnslib.message.records.AbstractResourceRecord.java
@Override public String toZone(int maxLength) { int paddedSize = (maxLength - name.length()) + name.length(); String ownerWithPadding = StringUtils.rightPad(name, paddedSize, " "); return ownerWithPadding + "\t" + ttl + "\t" + classz + "\t" + type; }
From source file:nl.sidn.dnslib.message.records.NotImplementedResourceRecord.java
@Override public String toZone(int maxLength) { StringBuffer b = new StringBuffer(); int paddedSize = (maxLength - name.length()) + name.length(); String ownerWithPadding = StringUtils.rightPad(name, paddedSize, " "); b.append(ownerWithPadding + "\t" + ttl + "\t"); if (classz == null) { b.append("CLASS" + (int) rawClassz); } else {//from w w w . j a v a 2 s . c o m b.append(classz); } b.append("\t"); if (type == null) { b.append("TYPE" + (int) rawType); } else { b.append(type); } b.append("\t"); b.append("\\# " + (int) rdLength); if (rdLength > 0) { b.append(" " + Hex.encodeHexString(rdata)); } return b.toString(); }
From source file:org.apache.beam.sdk.extensions.sql.impl.udf.BuiltinStringFunctions.java
@UDF(funcName = "RPAD", parameterArray = { TypeName.STRING, TypeName.INT64, TypeName.STRING }, returnType = TypeName.STRING) public String rpad(String originalValue, Long returnLength, String pattern) { if (originalValue == null || returnLength == null || pattern == null) { return null; }/*w ww . j av a 2 s .com*/ if (returnLength < -1 || pattern.isEmpty()) { throw new IllegalArgumentException("returnLength cannot be 0 or pattern cannot be empty."); } if (originalValue.length() == returnLength) { return originalValue; } else if (originalValue.length() < returnLength) { // add padding to right return StringUtils.rightPad(originalValue, Math.toIntExact(returnLength), pattern); } else { // truncating string by str.substring // Java String can only hold a string with Integer.MAX_VALUE as longest length. return originalValue.substring(0, Math.toIntExact(returnLength)); } }
From source file:org.apache.hadoop.hive.serde2.compression.TestSnappyCompDe.java
@Before public void init() { ByteBuffer firstRow = ByteBuffer.wrap(new byte[] { 2, 33, 7, 75, 5 }); ByteBuffer secondRow = ByteBuffer.wrap(new byte[] { 3, 21, 6 }); ByteBuffer thirdRow = ByteBuffer.wrap(new byte[] { 52, 25, 74, 74, 64 }); firstRow.flip();//from w w w . j ava 2s.co m secondRow.flip(); thirdRow.flip(); ArrayList<ByteBuffer> someBinaries = new ArrayList<ByteBuffer>(); someBinaries.add(firstRow); someBinaries.add(secondRow); someBinaries.add(thirdRow); columnBinary = new ColumnBuffer( TColumn.binaryVal(new TBinaryColumn(someBinaries, ByteBuffer.wrap(new byte[] {})))); // Test leading and trailing `false` in column ArrayList<Boolean> bools = new ArrayList<Boolean>(); bools.add(false); bools.add(true); bools.add(false); bools.add(true); bools.add(false); columnBool = new ColumnBuffer(TColumn.boolVal(new TBoolColumn(bools, ByteBuffer.wrap(noNullMask)))); ArrayList<Byte> bytes = new ArrayList<Byte>(); bytes.add((byte) 0); bytes.add((byte) 1); bytes.add((byte) 2); bytes.add((byte) 3); columnByte = new ColumnBuffer(TColumn.byteVal(new TByteColumn(bytes, ByteBuffer.wrap(noNullMask)))); ArrayList<Short> shorts = new ArrayList<Short>(); shorts.add((short) 0); shorts.add((short) 1); shorts.add((short) -127); shorts.add((short) 127); columnShort = new ColumnBuffer(TColumn.i16Val(new TI16Column(shorts, ByteBuffer.wrap(noNullMask)))); ArrayList<Integer> ints = new ArrayList<Integer>(); ints.add(0); ints.add(1); ints.add(-32767); ints.add(32767); columnInt = new ColumnBuffer(TColumn.i32Val(new TI32Column(ints, ByteBuffer.wrap(noNullMask)))); ArrayList<Long> longs = new ArrayList<Long>(); longs.add((long) 0); longs.add((long) 1); longs.add((long) -2147483647); longs.add((long) 2147483647); columnLong = new ColumnBuffer(TColumn.i64Val(new TI64Column(longs, ByteBuffer.wrap(noNullMask)))); ArrayList<Double> doubles = new ArrayList<Double>(); doubles.add((double) 0); doubles.add((double) 1.0); doubles.add((double) -2147483647.5); doubles.add((double) 2147483647.5); columnDouble = new ColumnBuffer(TColumn.doubleVal(new TDoubleColumn(doubles, ByteBuffer.wrap(noNullMask)))); ArrayList<String> strings = new ArrayList<String>(); strings.add("ABC"); strings.add("DEFG"); strings.add("HI"); strings.add(StringUtils.rightPad("", 65535, 'j')); strings.add(""); columnStr = new ColumnBuffer(TColumn.stringVal(new TStringColumn(strings, ByteBuffer.wrap(noNullMask)))); compDe.init(new HashMap<String, String>()); }
From source file:org.apache.nifi.properties.AESSensitivePropertyProvider.java
/** * Returns the decrypted plaintext./*from w ww . jav a 2 s. c om*/ * * @param protectedValue the cipher text read from the {@code nifi.properties} file * @return the raw value to be used by the application * @throws SensitivePropertyProtectionException if there is an error decrypting the cipher text */ @Override public String unprotect(String protectedValue) throws SensitivePropertyProtectionException { if (protectedValue == null || protectedValue.trim().length() < MIN_CIPHER_TEXT_LENGTH) { throw new IllegalArgumentException( "Cannot decrypt a cipher text shorter than " + MIN_CIPHER_TEXT_LENGTH + " chars"); } if (!protectedValue.contains(DELIMITER)) { throw new IllegalArgumentException("The cipher text does not contain the delimiter " + DELIMITER + " -- it should be of the form Base64(IV) || Base64(cipherText)"); } protectedValue = protectedValue.trim(); final String IV_B64 = protectedValue.substring(0, protectedValue.indexOf(DELIMITER)); byte[] iv = Base64.decode(IV_B64); if (iv.length < IV_LENGTH) { throw new IllegalArgumentException( "The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes"); } String CIPHERTEXT_B64 = protectedValue.substring(protectedValue.indexOf(DELIMITER) + 2); // Restore the = padding if necessary to reconstitute the GCM MAC check if (CIPHERTEXT_B64.length() % 4 != 0) { final int paddedLength = CIPHERTEXT_B64.length() + 4 - (CIPHERTEXT_B64.length() % 4); CIPHERTEXT_B64 = StringUtils.rightPad(CIPHERTEXT_B64, paddedLength, '='); } try { byte[] cipherBytes = Base64.decode(CIPHERTEXT_B64); cipher.init(Cipher.DECRYPT_MODE, this.key, new IvParameterSpec(iv)); byte[] plainBytes = cipher.doFinal(cipherBytes); logger.info(getName() + " decrypted a sensitive value successfully"); return new String(plainBytes, StandardCharsets.UTF_8); } catch (BadPaddingException | IllegalBlockSizeException | DecoderException | InvalidAlgorithmParameterException | InvalidKeyException e) { final String msg = "Error decrypting a protected value"; logger.error(msg, e); throw new SensitivePropertyProtectionException(msg, e); } }
From source file:org.apache.nifi.registry.properties.AESSensitivePropertyProvider.java
/** * Returns the decrypted plaintext.//from w ww . ja va2 s .c om * * @param protectedValue the cipher text read from the {@code nifi.properties} file * @return the raw value to be used by the application * @throws SensitivePropertyProtectionException if there is an error decrypting the cipher text */ @Override public String unprotect(String protectedValue) throws SensitivePropertyProtectionException { if (protectedValue == null || protectedValue.trim().length() < MIN_CIPHER_TEXT_LENGTH) { throw new IllegalArgumentException( "Cannot decrypt a cipher text shorter than " + MIN_CIPHER_TEXT_LENGTH + " chars"); } if (!protectedValue.contains(DELIMITER)) { throw new IllegalArgumentException("The cipher text does not contain the delimiter " + DELIMITER + " -- it should be of the form Base64(IV) || Base64(cipherText)"); } protectedValue = protectedValue.trim(); final String IV_B64 = protectedValue.substring(0, protectedValue.indexOf(DELIMITER)); byte[] iv = Base64.decode(IV_B64); if (iv.length < IV_LENGTH) { throw new IllegalArgumentException( "The IV (" + iv.length + " bytes) must be at least " + IV_LENGTH + " bytes"); } String CIPHERTEXT_B64 = protectedValue.substring(protectedValue.indexOf(DELIMITER) + 2); // Restore the = padding if necessary to reconstitute the GCM MAC check if (CIPHERTEXT_B64.length() % 4 != 0) { final int paddedLength = CIPHERTEXT_B64.length() + 4 - (CIPHERTEXT_B64.length() % 4); CIPHERTEXT_B64 = StringUtils.rightPad(CIPHERTEXT_B64, paddedLength, '='); } try { byte[] cipherBytes = Base64.decode(CIPHERTEXT_B64); cipher.init(Cipher.DECRYPT_MODE, this.key, new IvParameterSpec(iv)); byte[] plainBytes = cipher.doFinal(cipherBytes); logger.debug(getName() + " decrypted a sensitive value successfully"); return new String(plainBytes, StandardCharsets.UTF_8); } catch (BadPaddingException | IllegalBlockSizeException | DecoderException | InvalidAlgorithmParameterException | InvalidKeyException e) { final String msg = "Error decrypting a protected value"; logger.error(msg, e); throw new SensitivePropertyProtectionException(msg, e); } }