List of usage examples for org.apache.commons.lang StringUtils rightPad
public static String rightPad(String str, int size, String padStr)
Right pad a String with a specified String.
From source file:org.apache.usergrid.query.validator.QueryResponse.java
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("\n"); builder.append(StringUtils.rightPad("", 20, "-")); builder.append("\n"); builder.append(StringUtils.rightPad("* Expected", 20, " ")); builder.append("\n"); builder.append("list size : " + expacted.size()); builder.append("\n"); for (Entity entity : expacted) { builder.append(entity.toString()); builder.append("\n"); }/*from w w w . ja v a 2s. c o m*/ builder.append("\n"); builder.append(StringUtils.rightPad("* Actually", 20, " ")); builder.append("\n"); builder.append("list size : " + actually.size()); builder.append("\n"); for (Entity entity : actually) { builder.append(entity.toString()); builder.append("\n"); } builder.append(StringUtils.rightPad("", 20, "-")); builder.append("\n"); return builder.toString(); }
From source file:org.apereo.portal.io.xml.JaxbPortalDataHandlerService.java
@Override public boolean exportData(String typeId, String dataId, File directory) { directory.mkdirs();//from w w w . j a v a 2 s .co m final File exportTempFile; try { exportTempFile = File.createTempFile( SafeFilenameUtils.makeSafeFilename(StringUtils.rightPad(dataId, 2, '-') + "-"), SafeFilenameUtils.makeSafeFilename("." + typeId), directory); } catch (IOException e) { throw new RuntimeException("Could not create temp file to export " + typeId + " " + dataId, e); } try { final String fileName = this.exportData(typeId, dataId, new StreamResult(exportTempFile)); if (fileName == null) { logger.info("Skipped: type={} id={}", typeId, dataId); return false; } final File destFile = new File(directory, fileName + "." + typeId + ".xml"); if (destFile.exists()) { logger.warn("Exporting " + typeId + " " + dataId + " but destination file already exists, it will be overwritten: " + destFile); destFile.delete(); } FileUtils.moveFile(exportTempFile, destFile); logger.info("Exported: {}", destFile); return true; } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException("Failed to export " + typeId + " " + dataId, e); } finally { FileUtils.deleteQuietly(exportTempFile); } }
From source file:org.codehaus.mojo.javascript.AbstractCompressMojo.java
private long compress(File in, File compressed, JSCompressor jscompressor) throws MojoExecutionException { if (in.length() > 0) { File stripped = stripDebugs(in); try {/*from w w w. j ava 2 s . c om*/ jscompressor.compress(stripped, compressed, optimizationLevel, languageVersion); } catch (CompressionException e) { throw new MojoExecutionException("Failed to compress Javascript file " + e.getScript(), e); } String describe = in.getName() + " (" + INTEGER.format(in.length()) + " bytes) "; String title = StringUtils.rightPad(describe, 60, "."); logStats(title + " compressed at " + ratio(compressed, in) + "%"); return in.length() - compressed.length(); } else { try { compressed.createNewFile(); getLog().info(in.getName() + " was zero length; not compressed."); return 0; } catch (IOException e) { throw new MojoExecutionException("Error handling zero length file.", e); } } }
From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProvider.java
List<String> getContentFilePathParts(String id, String qualifier) { String partsId = id;//from ww w .j ava2s .c o m if (id.length() < 6) { partsId = StringUtils.rightPad(id, 6, "0"); } List<String> parts = new ArrayList<>(); parts.add(partsId.substring(0, 3)); parts.add(partsId.substring(3, 6)); parts.add(partsId); if (StringUtils.isNotBlank(qualifier)) { parts.add(qualifier); } return parts; }
From source file:org.dataconservancy.packaging.gui.presenter.impl.PackageGenerationPresenterImplTest.java
@Test public void testLongFilenameShowsWarning() { presenter.display();// ww w . ja v a 2 s . com view.getPackageNameField().setText(StringUtils.rightPad("fakepackage", 300, "xyz")); outputDirectory = new File("/tmp"); view.getSelectOutputDirectoryButton().fire(); assertFalse(view.getCurrentOutputDirectoryTextField().getText().isEmpty()); assertTrue(view.getStatusLabel().isVisible()); assertEquals( messages.formatFilenameLengthWarning(view.getCurrentOutputDirectoryTextField().getText().length()), view.getStatusLabel().getText()); }
From source file:org.eclipse.mylyn.gerrit.tests.core.GerritConnectorTest.java
@Test public void testPerformQueryAnonymous() throws Exception { // XXX some test repositories require OpenID auth which is not supported when running tests repository.setCredentials(AuthenticationType.REPOSITORY, null, false); IRepositoryQuery query = new RepositoryQuery(repository.getConnectorKind(), "query"); //$NON-NLS-1$ query.setAttribute(GerritQuery.TYPE, GerritQuery.ALL_OPEN_CHANGES); query.setAttribute(GerritQuery.QUERY_STRING, GerritQuery.ALL_OPEN_CHANGES); InMemoryTaskDataCollector resultCollector = new InMemoryTaskDataCollector(); IStatus status = connector.performQuery(repository, query, resultCollector, null, new NullProgressMonitor()); assertEquals(Status.OK_STATUS, status); assertTrue(resultCollector.getResults().size() > 0); for (TaskData result : resultCollector.getResults()) { assertTrue(result.isPartial());//from w ww .ja v a 2 s.c o m assertNull(result.getRoot().getAttribute(GerritTaskSchema.getDefault().UPLOADED.getKey())); TaskAttribute key = result.getRoot().getAttribute(GerritTaskSchema.getDefault().KEY.getKey()); assertNotNull(key); String value = key.getValue(); assertNotNull(value); assertTrue(value.startsWith("I")); // Change-Ids are prefixed with an uppercase I // 'expand' the abbreviated SHA-1 with 'a's String objId = StringUtils.rightPad(value.substring(1), Constants.OBJECT_ID_STRING_LENGTH, 'a'); assertTrue(ObjectId.isId(objId)); } }
From source file:org.eclipse.mylyn.internal.gerrit.core.remote.GerritReviewRemoteFactoryTest.java
@Test public void testDependencies() throws Exception { boolean isversion29OrLater = isVersion29OrLater(); String changeIdDep1 = "I" + StringUtils.rightPad(System.currentTimeMillis() + "", 40, "a"); CommitCommand commandDep1 = reviewHarness.createCommitCommand(changeIdDep1); reviewHarness.addFile("testFile1.txt", "test 2"); CommitResult resultDep1 = reviewHarness.commitAndPush(commandDep1); String resultIdDep1 = StringUtils .trimToEmpty(StringUtils.substringAfterLast(resultDep1.push.getMessages(), "/")); assertThat("Bad Push: " + resultDep1.push.getMessages(), resultIdDep1.length(), greaterThan(0)); TestRemoteObserverConsumer<IRepository, IReview, String, GerritChange, String, Date> consumerDep1 = retrieveForRemoteKey( reviewHarness.getProvider().getReviewFactory(), reviewHarness.getRepository(), resultIdDep1, true); IReview reviewDep1 = consumerDep1.getModelObject(); assertThat(reviewDep1.getParents().size(), is(1)); IChange parentChange = reviewDep1.getParents().get(0); //Not expected to be same instance assertThat(parentChange.getId(), is(getReview().getId())); assertThat(parentChange.getSubject(), is(getReview().getSubject())); if (isversion29OrLater) { //There s an offset ~ 1 sec, so no test for now } else {// www . j a va 2s . c o m assertThat(parentChange.getModificationDate().getTime(), is(getReview().getModificationDate().getTime())); } reviewHarness.retrieve(); assertThat(getReview().getChildren().size(), is(1)); IChange childChange = getReview().getChildren().get(0); //Not expected to be same instance assertThat(childChange.getId(), is(reviewDep1.getId())); assertThat(childChange.getSubject(), is(reviewDep1.getSubject())); if (isversion29OrLater) { //There s an offset ~ 1 sec, so no test for now } else { assertThat(childChange.getModificationDate().getTime(), is(reviewDep1.getModificationDate().getTime())); } }
From source file:org.fenixedu.academic.report.academicAdministrativeOffice.DegreeFinalizationCertificate.java
final private String getCreditsAndGradeInfo(final ICurriculumEntry entry) { final StringBuilder result = new StringBuilder(); if (getDocumentRequest().isToShowCredits()) { getCreditsInfo(result, entry);/*from w ww . ja va 2 s . co m*/ } result.append(BundleUtil.getString(Bundle.ACADEMIC, getDocumentRequest().getLanguage(), "label.with")); final Grade grade = entry.getGrade(); result.append(SINGLE_SPACE).append(grade.getValue()); result.append(StringUtils.rightPad( "(" + grade.getExtendedValue().getContent(getDocumentRequest().getLanguage()) + ")", SUFFIX_LENGTH, ' ')); String values = BundleUtil.getString(Bundle.ACADEMIC, getDocumentRequest().getLanguage(), "values"); result.append(grade.isNumeric() ? values : StringUtils.rightPad(EMPTY_STR, values.length(), ' ')); return result.toString(); }
From source file:org.fenixedu.academic.util.NumberToWordsConverter.java
public static void main(String[] args) { int[] values = new int[] { 1, 23, 52, 100, 102, 223, 1000, 1023, 2000, 2453, 9000, 10000, 10001, 11342, 100000, 1000000, 2000000, 10000000, 100000000, 1000000000 }; for (final int value : values) { int quotient = value / 1000; int remainder = value % 1000; int nextRemainder = quotient % 1000; logger.info(StringUtils.rightPad("V: " + value, 11, ' ') + "\t"); logger.info(StringUtils.rightPad("Q: " + quotient, 11, ' ')); logger.info("\tR: " + remainder); logger.info("\tRQ: " + nextRemainder); logger.info("\twords: " + convert(value)); }// ww w . jav a 2 s .c o m }
From source file:org.jumpmind.db.platform.AbstractDatabasePlatform.java
protected Object getObjectValue(String value, Column column, BinaryEncoding encoding, boolean useVariableDates, boolean fitToColumn) throws DecoderException { Object objectValue = value;/*from w ww. j a v a2 s.c o m*/ int type = column.getMappedTypeCode(); if ((value == null || (getDdlBuilder().getDatabaseInfo().isEmptyStringNulled() && value.equals(""))) && column.isRequired() && column.isOfTextType()) { objectValue = REQUIRED_FIELD_NULL_SUBSTITUTE; } if (value != null) { if (type == Types.DATE || type == Types.TIMESTAMP || type == Types.TIME) { objectValue = parseDate(type, value, useVariableDates); } else if (type == Types.CHAR) { String charValue = value.toString(); if ((StringUtils.isBlank(charValue) && getDdlBuilder().getDatabaseInfo().isBlankCharColumnSpacePadded()) || (StringUtils.isNotBlank(charValue) && getDdlBuilder().getDatabaseInfo().isNonBlankCharColumnSpacePadded())) { objectValue = StringUtils.rightPad(value.toString(), column.getSizeAsInt(), ' '); } } else if (type == Types.BIGINT) { objectValue = parseBigInteger(value); } else if (type == Types.INTEGER || type == Types.SMALLINT || type == Types.BIT || type == Types.TINYINT) { objectValue = parseInteger(value); } else if (type == Types.NUMERIC || type == Types.DECIMAL || type == Types.FLOAT || type == Types.DOUBLE || type == Types.REAL) { objectValue = parseBigDecimal(value); } else if (type == Types.BOOLEAN) { objectValue = value.equals("1") ? Boolean.TRUE : Boolean.FALSE; } else if (!(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOMETRY)) && !(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase().contains(TypeMap.GEOGRAPHY)) && (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY || type == Types.VARBINARY || // SQLServer ntext type type == -10)) { if (encoding == BinaryEncoding.NONE) { objectValue = value.getBytes(); } else if (encoding == BinaryEncoding.BASE64) { objectValue = Base64.decodeBase64(value.getBytes()); } else if (encoding == BinaryEncoding.HEX) { objectValue = Hex.decodeHex(value.toCharArray()); } } else if (type == Types.ARRAY) { objectValue = createArray(column, value); } } if (objectValue instanceof String) { String stringValue = cleanTextForTextBasedColumns((String) objectValue); int size = column.getSizeAsInt(); if (fitToColumn && size > 0 && stringValue.length() > size) { stringValue = stringValue.substring(0, size); } objectValue = stringValue; } return objectValue; }