List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, int repeat)
Repeat a String repeat
times to form a new String.
From source file:com.liveramp.cascading_ext.flow.LoggingFlow.java
private String logJobErrors() { boolean exceptions = false; StringBuilder jobErrors = new StringBuilder(); final String divider = StringUtils.repeat("-", 80); logAndAppend(jobErrors, divider);/*from w ww .j a v a2s .c o m*/ try { List<FlowStepStats> stepStats = getFlowStats().getFlowStepStats(); Set<String> jobFailures = new HashSet<String>(); for (FlowStepStats stat : stepStats) { try { RunningJob job = ((HadoopStepStats) stat).getRunningJob(); TaskCompletionEvent[] events = job.getTaskCompletionEvents(0); ArrayList<TaskCompletionEvent> failures = new ArrayList<TaskCompletionEvent>(); for (TaskCompletionEvent event : events) { if (event.getTaskStatus() == Status.FAILED) { failures.add(event); } } // We limit the number of potential logs being pulled to spare the jobtracker if (failures.size() > 0) { Collections.shuffle(failures); for (int i = 0; i < FAILURES_TO_QUERY; i++) { jobFailures.add(getFailureLog(failures.get(i))); } } } catch (Exception e) { exceptions = true; } } if (exceptions) { logAndAppend(jobErrors, "unable to retrieve failures from all completed steps!"); logAndAppend(jobErrors, "successfully retrieved job failures: " + StringUtils.join(jobFailures, ", ")); } else { logAndAppend(jobErrors, "step attempt failures: " + StringUtils.join(jobFailures, ", ")); } } catch (Exception e) { logAndAppend(jobErrors, "unable to retrieve any failures from steps"); logAndAppend(jobErrors, e.toString()); } logAndAppend(jobErrors, divider); return jobErrors.toString(); }
From source file:ddf.catalog.source.solr.SolrProviderTestCase.java
protected static void messageBreak(String string) { String stars = StringUtils.repeat("*", string.length() + 2); LOGGER.info(stars);// www .j ava 2 s . c o m LOGGER.info("* {}", string); LOGGER.info(stars); }
From source file:adalid.util.meta.CodeAnalyzerTreeVisitor.java
private String tabs() { return StringUtils.repeat(SP, 4 * (depth() - 1)); }
From source file:com.projity.grouping.core.model.NamedNodeElement.java
public String getIndentedName() { return StringUtils.repeat("--", level) + name; }
From source file:chh.utils.db.source.common.JdbcClient.java
private String constructInsertQuery(String tableName, List<List<Column>> columnLists) { StringBuilder sb = new StringBuilder(); sb.append("Insert into ").append(tableName).append(" ("); Collection<String> columnNames = Collections2.transform(columnLists.get(0), new Function<Column, String>() { @Override// w ww .j a va2 s. c om public String apply(Column input) { return input.getColumnName(); } }); String columns = Joiner.on(",").join(columnNames); sb.append(columns).append(") values ( "); String placeHolders = StringUtils.chop(StringUtils.repeat("?,", columnNames.size())); sb.append(placeHolders).append(")"); return sb.toString(); }
From source file:musite.io.xml.ProteinsXMLWriter.java
/** * {@inheritDoc}//from w w w. j a va 2 s . c o m */ public void write(final OutputStream os, final Proteins data) throws IOException { if (data == null) { throw new IllegalArgumentException(); } OutputStreamWriter osw = new OutputStreamWriter(os); BufferedWriter bufWriter = new BufferedWriter(osw); int indent = getIndent(); String prefix0 = StringUtils.repeat("\t", indent); String prefix1 = prefix0 + "\t"; if (root != null) bufWriter.write(prefix0 + "<" + root + ">\n"); bufWriter.write(prefix0 + "<protein-list>\n"); Iterator<Protein> it = data.proteinIterator(); while (it.hasNext()) { Protein protein = it.next(); bufWriter.write(prefix0 + "<protein>\n"); Map<String, Object> infoMap = protein.getInfoMap(); for (String field : fieldList(infoMap.keySet())) { if (proteinFieldFilter != null && proteinFieldFilter.contains(field) != proteinFieldInclude) continue; Object value = infoMap.get(field); if (value == null) continue; bufWriter.write(prefix1 + "<" + field + ">"); Writer fieldWriter = proteinFieldWriters.get(field); if (fieldWriter == null) { fieldWriter = XMLUtil.createDefaultWriter(value); bufWriter.flush(); fieldWriter.write(os, value); } else { Boolean isIndent = proteinFieldIndent.get(field); if (isIndent != null && isIndent) bufWriter.write("\n"); bufWriter.flush(); if (isIndent != null && isIndent && fieldWriter instanceof AbstractXMLWriter) ((AbstractXMLWriter) fieldWriter).setIndent(indent + 2); fieldWriter.write(os, value); if (isIndent != null && isIndent) bufWriter.write(prefix1); } bufWriter.write("</" + field + ">\n"); } bufWriter.write(prefix0 + "</protein>\n"); } bufWriter.write(prefix0 + "</protein-list>\n"); if (root != null) bufWriter.write(prefix0 + "</" + root + ">"); bufWriter.flush(); }
From source file:de.pellepelster.ant.statistics.AsciiTable.java
private void createHorizontalLine(int totalTableWidth, StringBuffer result) { result.append(TABLE_CONNECTOR);// w w w . j av a2 s .c o m result.append(StringUtils.repeat(VERTICAL_TABLE_BORDER, totalTableWidth)); result.append(TABLE_CONNECTOR); result.append(NEWLINE); }
From source file:com.evolveum.midpoint.tools.ninja.ImportDDL.java
private Connection createConnection() { System.out.println("Creating JDBC connection."); String password = !config.isPromptForPassword() ? config.getPassword() : promptForPassword(); try {//from w w w .j a v a 2s . c o m Class.forName(config.getDriver()); return DriverManager.getConnection(config.getUrl(), config.getUsername(), password); } catch (Exception ex) { String pwd = password == null ? "<null>" : StringUtils.repeat("*", password.length()); System.out.println("Couldn't create JDBC connection to '" + config.getUrl() + "' with username '" + config.getUsername() + "' and password '" + pwd + "', reason: " + ex.getMessage()); ex.printStackTrace(); } return null; }
From source file:las.DBConnector.java
/** * Load CSV test data into SQL Table//from ww w .jav a2 s .c o m * * example for clearFirst: boolean check = * DBConnector.checkDataExistedInTable("MEMBERS"); * * if (check) { DBConnector.loadCSVIntoTable("src/resources/members.csv", * "MEMBERS", true); System.out.println("Test data inserted into MEMBERS * table"); } * * ignore createNewReader, since it uses for loadCSVIntoTable, don't modify * it * * Getter and Setter provided for Separator to set your own separator inside * your CSV File * * @param csvFile : src/resources/xxx.csv (put your csv file under this * path) * @param tableName: TABLENAME (All in capital letters) * @param clearFirst true = if data not existed in SQL Table, write test * data inside false = if data exisited in SQL Table, don't write again. * @throws java.lang.Exception */ public static void loadCSVIntoTable(String csvFile, String tableName, boolean clearFirst) throws Exception { CSVReader csvReader = null; if (null == DBConnector.conn) { throw new Exception("Not a valid connection."); } try { csvReader = DBConnector.getInstance().createNewReader(csvFile); } catch (ClassNotFoundException | SQLException | FileNotFoundException e) { e.printStackTrace(); throw new Exception("Error occured while executing file. " + e.getMessage()); } String[] headerRow = csvReader.readNext(); if (null == headerRow) { throw new FileNotFoundException( "No columns defined in given CSV file." + "Please check the CSV file format."); } String questionmarks = StringUtils.repeat("?,", headerRow.length); questionmarks = (String) questionmarks.subSequence(0, questionmarks.length() - 1); String query = SQL_INSERT.replaceFirst(TABLE_REGEX, tableName); query = query.replaceFirst(KEYS_REGEX, StringUtils.join(headerRow, ",")); query = query.replaceFirst(VALUES_REGEX, questionmarks); String[] nextLine; PreparedStatement ps = null; try { conn.setAutoCommit(false); ps = conn.prepareStatement(query); if (clearFirst) { //delete data from table before loading csv conn.createStatement().execute("DELETE FROM " + tableName); } final int batchSize = 1000; int count = 0; Date date = null; while ((nextLine = csvReader.readNext()) != null) { if (null != nextLine) { int index = 1; for (String string : nextLine) { date = DateUtil.convertToDate(string); if (null != date) { ps.setDate(index++, new java.sql.Date(date.getTime())); } else { ps.setString(index++, string); } } ps.addBatch(); } if (++count % batchSize == 0) { ps.executeBatch(); } } ps.executeBatch(); // insert remaining records conn.commit(); } catch (SQLException e) { conn.rollback(); e.printStackTrace(); throw new Exception("Error occured while loading data from file to database." + e.getMessage()); } finally { if (null != ps) { ps.close(); } csvReader.close(); } }
From source file:com.atlassian.theplugin.idea.config.serverconfig.defaultCredentials.TestDefaultCredentialsDialog.java
private synchronized void buildServerContent() { rootPanel.removeAll();// w w w. j a v a 2s. c o m rootPanel.add(new JLabel("Testing default credentials for enabled servers"), BorderLayout.NORTH); String rowsSpecs = "3dlu, pref, 3dlu, " + StringUtils.repeat("pref,", servers.size()); final FormLayout layout = new FormLayout("pref, 4dlu, pref, 4dlu, pref:grow", rowsSpecs.substring(0, rowsSpecs.length() - 1)); int row = 4; final CellConstraints cc = new CellConstraints(); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); builder.addSeparator("Servers", cc.xyw(1, 2, ALL_COLUMNS)); for (ServerDataExt server : servers) { // if (server.getServerType()) builder.add( new JLabel( server.getServerData().getName() + " (" + server.getServerType().getShortName() + ")"), cc.xy(1, row)); builder.add(new JLabel(server.getStatus().getIcon()), cc.xy(3, row)); if (server.getStatus() == ConnectionStatus.FAILED) { HyperlinkLabel hyperlinkLabel = new HyperlinkLabel("error details"); hyperlinkLabel.addMouseListener(getMouseListener(server)); builder.add(hyperlinkLabel, cc.xy(5, row)); } row++; } rootPanel.add(builder.getPanel(), BorderLayout.CENTER); changeCancelActionName(); }