List of usage examples for java.util Formatter toString
public String toString()
From source file:de.huxhorn.sulky.blobs.impl.BlobRepositoryImpl.java
private String copyAndHash(InputStream input, File into) throws IOException { MessageDigest digest = createMessageDigest(); DigestInputStream dis = new DigestInputStream(input, digest); IOException ex;//from w w w . ja v a 2 s . c om FileOutputStream fos = null; try { fos = new FileOutputStream(into); IOUtils.copyLarge(dis, fos); byte[] hash = digest.digest(); Formatter formatter = new Formatter(); for (byte b : hash) { formatter.format("%02x", b); } return formatter.toString(); } catch (IOException e) { ex = e; } finally { IOUtils.closeQuietly(dis); IOUtils.closeQuietly(fos); } if (logger.isWarnEnabled()) logger.warn("Couldn't retrieve data from input!", ex); deleteTempFile(into); throw ex; }
From source file:de.huxhorn.sulky.blobs.impl.BlobRepositoryImpl.java
private boolean valid(String id, File file) { if (!validating) { return true; }//from w ww . jav a 2 s . c o m MessageDigest digest = createMessageDigest(); FileInputStream input = null; try { input = new FileInputStream(file); DigestInputStream dis = new DigestInputStream(input, digest); for (;;) { if (dis.read() < 0) { break; } } byte[] hash = digest.digest(); Formatter formatter = new Formatter(); for (byte b : hash) { formatter.format("%02x", b); } return formatter.toString().equals(id); } catch (IOException e) { // ignore... } finally { IOUtils.closeQuietly(input); } return false; }
From source file:adapters.BoxSeriesCollectionAdapter.java
/** * Returns in a <TT>String</TT> all data contained in the current object. * * @return All data contained in the current object as a {@link String}. * *//* w w w . j av a 2 s . c o m*/ public String toString() { Formatter formatter = new Formatter(Locale.US); for (int i = 0; i < seriesCollection.getRowCount(); i++) { formatter.format(" Series " + i + " : %n"); for (int j = 0; j < seriesCollection.getColumnCount(); j++) formatter.format(",%15e%n", seriesCollection.getValue(i, j)); } return formatter.toString(); }
From source file:org.kie.workbench.common.forms.migration.tool.pipelines.basic.impl.AbstractFormAdapter.java
protected void migrateFields(final Set<Field> fields, final FormDefinition newForm, final FormMigrationSummary formSummary) { LayoutHelper helper = new LayoutHelper(); fields.forEach(originalField -> { if (!StringUtils.isEmpty(originalField.getMovedToForm())) { return; }//from ww w . j a va 2 s. c o m if (!Boolean.TRUE.equals(originalField.getGroupWithPrevious())) { helper.newRow(); } String originalTypeCode = originalField.getFieldType().getCode(); FieldAdapter adapter = adaptersRegistry.get(originalTypeCode); if (adapter == null) { // trying a backup adapter UnSupportedFieldAdapter unSupportedFieldAdapter = unSupportedAdapters.get(originalTypeCode); if (unSupportedFieldAdapter != null) { warn("Problems migrating field '" + originalField.getFieldName() + "': the original field has an unsupported field type '" + originalTypeCode + "'. It will be added on the new Form as a '" + unSupportedFieldAdapter.getNewFieldType() + "'"); unSupportedFieldAdapter.parseField(originalField, formSummary, newForm, helper::add); } else { warn("Cannot migrate field '" + originalField.getFieldName() + "': Unsupported field type '" + originalTypeCode + "'"); Formatter formatter = new Formatter(); formatter.format(FormsMigrationConstants.UNSUPORTED_FIELD_HTML_TEMPLATE, originalField.getFieldName(), originalTypeCode); LayoutComponent component = new LayoutComponent(FormsMigrationConstants.HTML_COMPONENT); component.addProperty(FormsMigrationConstants.HTML_CODE_PARAMETER, formatter.toString()); formatter.close(); helper.add(component); } } else { try { adapter.parseField(originalField, formSummary, newForm, helper::add); } catch (Exception ex) { warn("Cannot migrate field '" + originalField.getFieldName() + "': Unexpected error, see message for details"); ex.printStackTrace(migrationContext.getSystem().err()); } } }); newForm.setLayoutTemplate(helper.build()); }
From source file:com.yeldi.yeldibazaar.ManageRepo.java
private void redraw() { try {/*from www . j ava2 s . c o m*/ DB db = DB.getDB(); repos = db.getRepos(); } finally { DB.releaseDB(); } List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); Map<String, Object> server_line; for (DB.Repo repo : repos) { server_line = new HashMap<String, Object>(); server_line.put("address", repo.address); if (repo.inuse) { server_line.put("inuse", R.drawable.btn_check_on); } else { server_line.put("inuse", R.drawable.btn_check_off); } if (repo.pubkey != null) { try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(Hasher.unhex(repo.pubkey)); byte[] fingerprint = digest.digest(); Formatter formatter = new Formatter(new StringBuilder()); formatter.format("%02X", fingerprint[0]); for (int i = 1; i < fingerprint.length; i++) { formatter.format(i % 5 == 0 ? " %02X" : ":%02X", fingerprint[i]); } server_line.put("fingerprint", formatter.toString()); formatter.close(); } catch (Exception e) { Log.w("FDroid", "Unable to get certificate fingerprint.\n" + Log.getStackTraceString(e)); } } result.add(server_line); } SimpleAdapter show_out = new SimpleAdapter(this, result, R.layout.repolisticons, new String[] { "address", "inuse", "fingerprint" }, new int[] { R.id.uri, R.id.img, R.id.fingerprint }); setListAdapter(show_out); }
From source file:com.itemanalysis.jmetrik.stats.transformation.LinearTransformationAnalysis.java
public String transformScore() throws SQLException { Statement stmt = null;/*from w w w.ja va 2 s. com*/ ResultSet rs = null; Double constrainedScore = null; try { //add variable to db dao.addColumnToDb(conn, tableName, addedVariableInfo); conn.setAutoCommit(false);//begin transaction Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); select.addColumn(sqlTable, selectedVariable.getName().nameForDatabase()); select.addColumn(sqlTable, addedVariableInfo.getName().nameForDatabase()); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); rs = stmt.executeQuery(select.toString()); this.firePropertyChange("message", "", "Transforming scores..."); double origValue = 0.0; double transValue = 0.0; double z = 0.0; StandardDeviation sd = new StandardDeviation(); Mean mean = new Mean(); Min min = new Min(); Max max = new Max(); while (rs.next()) { origValue = rs.getDouble(selectedVariable.getName().nameForDatabase()); if (!rs.wasNull()) { sd.increment(origValue); mean.increment(origValue); min.increment(origValue); max.increment(origValue); } updateProgress(); } double meanValue = mean.getResult(); double sdValue = sd.getResult(); double minValue = min.getResult(); double maxValue = max.getResult(); double A = 1.0; double B = 0.0; rs.beforeFirst(); while (rs.next()) { origValue = rs.getDouble(selectedVariable.getName().nameForDatabase()); if (!rs.wasNull()) { if (type1) { z = (origValue - meanValue) / sdValue; transValue = scaleSd * z + scaleMean; transValue = checkConstraints(transValue); } else { A = (maxPossibleScore - minPossibleScore) / (maxValue - minValue); B = minPossibleScore - minValue * A; transValue = origValue * A + B; transValue = checkConstraints(transValue); } descriptiveStatistics.increment(transValue); rs.updateDouble(addedVariableInfo.getName().nameForDatabase(), transValue); rs.updateRow(); } updateProgress(); } conn.commit(); conn.setAutoCommit(true); //create output DefaultLinearTransformation linearTransformation = new DefaultLinearTransformation(); linearTransformation.setScale(A); linearTransformation.setIntercept(B); StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format(publishHeader()); f.format(descriptiveStatistics.toString()); f.format(linearTransformation.toString()); f.format("%n"); f.format("%n"); return f.toString(); } catch (SQLException ex) { conn.rollback(); conn.setAutoCommit(true); throw ex; } finally { if (rs != null) rs.close(); if (stmt != null) stmt.close(); } }
From source file:com.hyperaware.conference.android.fragment.SessionDetailFragment.java
private void updateSessionDetail() { tvTopic.setText(agendaItem.getTopic()); host.setTitle(agendaItem.getTopic()); final StringBuilder sb = new StringBuilder(); final Formatter formatter = new Formatter(sb); final long start_ms = TimeUnit.SECONDS.toMillis(agendaItem.getEpochStartTime()); final long end_ms = TimeUnit.SECONDS.toMillis(agendaItem.getEpochEndTime()); sb.setLength(0);/* ww w .ja va2 s . co m*/ DateUtils.formatDateRange(getActivity(), formatter, start_ms, end_ms, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, tz.getID()); tvDate.setText(formatter.toString()); sb.setLength(0); DateUtils.formatDateRange(getActivity(), formatter, start_ms, end_ms, DateUtils.FORMAT_SHOW_TIME, tz.getID()); tvTime.setText(formatter.toString()); final String location = agendaItem.getLocation(); if (!Strings.isNullOrEmpty(location)) { tvLocation.setText(agendaItem.getLocation()); } else { tvLocation.setVisibility(View.GONE); } tvDescription.setText(agendaItem.getDescription()); // Only sessions with speakers can have feedback final View feedback = vgActions.findViewById(R.id.tv_session_feedback); if (speakerItems.size() > 0) { feedback.setOnClickListener(new SessionFeedbackOnClickListener()); vgActions.setVisibility(View.VISIBLE); } else { vgActions.setVisibility(View.GONE); } if (speakerItems.size() > 0) { vgSpeakers.setVisibility(View.VISIBLE); vgSpeakers.removeAllViews(); final LayoutInflater inflater = getActivity().getLayoutInflater(); for (final SpeakerItem item : speakerItems) { final View view = inflater.inflate(R.layout.item_session_speaker, vgSpeakers, false); ImageView iv = (ImageView) view.findViewById(R.id.iv_pic); Glide.with(SessionDetailFragment.this).load(item.getImage100()).placeholder(R.drawable.nopic) .into(iv); ((TextView) view.findViewById(R.id.tv_name)).setText(item.getName()); if (host != null) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment next = SpeakerDetailFragment.instantiate(item.getId()); host.pushFragment(next, "speaker_detail"); } }); } vgSpeakers.addView(view); } } }
From source file:com.zimbra.cs.mailclient.imap.ImapConnection.java
public String newTag() { Formatter fmt = new Formatter(); fmt.format(TAG_FORMAT, tagCount.incrementAndGet()); return fmt.toString(); }
From source file:org.jasig.cas.CasEnvironmentContextListener.java
/** * Collect environment info with/*w ww . j a v a 2 s .c o m*/ * details on the java and os deployment * versions. * * @return environment info */ private String collectEnvironmentInfo() { final Properties properties = System.getProperties(); final Formatter formatter = new Formatter(); formatter.format("\n******************** Welcome to CAS ********************\n"); formatter.format("CAS Version: %s\n", CasVersion.getVersion()); formatter.format("Java Home: %s\n", properties.get("java.home")); formatter.format("Java Vendor: %s\n", properties.get("java.vendor")); formatter.format("Java Version: %s\n", properties.get("java.version")); formatter.format("OS Architecture: %s\n", properties.get("os.arch")); formatter.format("OS Name: %s\n", properties.get("os.name")); formatter.format("OS Version: %s\n", properties.get("os.version")); formatter.format("*******************************************************\n"); return formatter.toString(); }
From source file:edu.cmu.tetrad.cli.simulation.data.AbstractDataSimulationCli.java
protected String printInformation(Simulation simulation) { Formatter fmt = new Formatter(); fmt.format("================================================================================%n"); fmt.format("%s (%s)%n", getSimulationType().getTitle(), AppTool.fmtDateNow()); fmt.format("================================================================================%n"); fmt.format("Description: %s%n", simulation.getDescription()); fmt.format("Delimiter: %s%n", Args.getDelimiterName(delimiter)); fmt.format("Number of Variables: %d%n", numOfVariables); fmt.format("Number of Cases: %d%n", numOfCases); fmt.format("Directory Out: %s%n", dirOut.getFileName().toString()); fmt.format("Output File Prefix: %s%n", outputPrefix); printSimulationParameters(fmt);/*from w w w .j av a2 s. co m*/ return fmt.toString().trim(); }