List of usage examples for java.util Formatter Formatter
public Formatter(OutputStream os, String csn) throws UnsupportedEncodingException
From source file:com.cloud.utils.NumbersUtil.java
public static String toReadableSize(long bytes) { if (bytes < KB && bytes >= 0) { return Long.toString(bytes) + " bytes"; }/* w ww . j av a 2s .co m*/ StringBuilder builder = new StringBuilder(); Formatter format = new Formatter(builder, Locale.getDefault()); if (bytes < MB) { format.format("%.2f KB", (float) bytes / (float) KB); } else if (bytes < GB) { format.format("%.2f MB", (float) bytes / (float) MB); } else if (bytes < TB) { format.format("%.2f GB", (float) bytes / (float) GB); } else { format.format("%.4f TB", (float) bytes / (float) TB); } format.close(); return builder.toString(); }
From source file:net.chrissearle.flickrvote.web.admin.ChallengeAction.java
@Override public String input() throws Exception { if (tag != null && !"".equals(tag)) { editFlag = true;//from w ww . ja v a2s.com ChallengeSummary challengeSummary = challengeService.getChallengeSummary(tag); challenge = new ChallengeAdmin(); challenge.setTag(challengeSummary.getTag()); challenge.setTitle(challengeSummary.getTitle()); challenge.setStartDate(challengeSummary.getStartDate()); challenge.setNotes(challengeSummary.getNotes()); } else { // Set some defaults ChallengeSummary mostRecentChallenge = challengeService.getMostRecent(); if (mostRecentChallenge != null) { challenge = new ChallengeAdmin(); challenge.setStartDate(mostRecentChallenge.getVoteDate()); int numIndex = mostRecentChallenge.getTag().indexOf(FlickrVoteWebConstants.TAGPREFIX) + FlickrVoteWebConstants.TAGPREFIX.length(); int tagNum = Integer.valueOf(mostRecentChallenge.getTag().substring(numIndex)); StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.getDefault()); formatter.format(FlickrVoteWebConstants.TAGPREFIX + "%03d", tagNum + 1); challenge.setTag(sb.toString()); } } return INPUT; }
From source file:org.apache.ambari.servicemonitor.utils.MonitorUtils.java
/** * Convert milliseconds to human time -the exact format is unspecified * @param milliseconds a time in milliseconds * @return a time that is converted to human intervals *///from w w w . jav a 2 s .co m public static String millisToHumanTime(long milliseconds) { StringBuilder sb = new StringBuilder(); // Send all output to the Appendable object sb Formatter formatter = new Formatter(sb, Locale.US); long s = Math.abs(milliseconds / 1000); long m = Math.abs(milliseconds % 1000); if (milliseconds > 0) { formatter.format("%d.%03ds", s, m); } else if (milliseconds == 0) { formatter.format("0"); } else { formatter.format("-%d.%03ds", s, m); } return sb.toString(); }
From source file:com.terrain.WorldBlock.java
@Override public String getName() { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("Block [x=%1s, z=%1s, y=%1s]", getLocalX(), getLocalZ(), getAltitude()); return sb.toString(); }
From source file:com.vangent.hieos.xutil.hl7.date.Hl7Date.java
/** * // w ww. ja va 2 s. co m * @param c * @return */ static private String formatDTM(Calendar c) { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("%s%02d%02d%02d%02d%02d", c.get(Calendar.YEAR), c.get(Calendar.MONTH) + 1, c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE), c.get(Calendar.SECOND)); String formattedTime = sb.toString(); return formattedTime; }
From source file:com.orange.ocara.ui.dialog.AudioPlayerDialog.java
void initPlayer() { mediaPlayer = new MediaPlayer(); mediaPlayer.setOnPreparedListener(this); mediaPlayer.setOnCompletionListener(this); formatBuilder = new StringBuilder(); formatter = new Formatter(formatBuilder, Locale.getDefault()); if (progressBar instanceof SeekBar) { SeekBar seeker = (SeekBar) progressBar; seeker.setOnSeekBarChangeListener(mSeekListener); }/*from w w w . ja v a2 s . c om*/ progressBar.setMax(1000); reset(); }
From source file:de.tudarmstadt.ukp.dkpro.core.performance.Stopwatch.java
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { super.collectionProcessComplete(); if (isDownstreamTimer()) { getLogger().info("Results from Timer '" + timerName + "' after processing all documents."); DescriptiveStatistics statTimes = new DescriptiveStatistics(); for (Long timeValue : times) { statTimes.addValue((double) timeValue / 1000); }/*from w w w. j av a 2 s .c om*/ double sum = statTimes.getSum(); double mean = statTimes.getMean(); double stddev = statTimes.getStandardDeviation(); StringBuilder sb = new StringBuilder(); sb.append("Estimate after processing " + times.size() + " documents."); sb.append("\n"); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("Aggregated time: %,.1fs\n", sum); formatter.format("Time / Document: %,.3fs (%,.3fs)\n", mean, stddev); formatter.close(); getLogger().info(sb.toString()); if (outputFile != null) { try { Properties props = new Properties(); props.setProperty(KEY_SUM, "" + sum); props.setProperty(KEY_MEAN, "" + mean); props.setProperty(KEY_STDDEV, "" + stddev); OutputStream out = new FileOutputStream(outputFile); props.store(out, "timer " + timerName + " result file"); } catch (FileNotFoundException e) { throw new AnalysisEngineProcessException(e); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } } }
From source file:com.terrain.WorldChunk.java
@Override public String getName() { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("Chunk [x=%1s, z=%1s]", getLocalX(), getLocalZ()); return sb.toString(); }
From source file:de.tudarmstadt.ukp.dkpro.core.performance.ThroughputTestAE.java
public String getPerformanceaAnalysis() { StringBuilder sb = new StringBuilder(); long sumMillis = 0; for (double timeValue : times) { sumMillis += timeValue;//from w ww.jav a 2 s . co m } DescriptiveStatistics statTimes = new DescriptiveStatistics(); for (Long timeValue : times) { statTimes.addValue((double) timeValue / 1000); } sb.append("Estimate after processing " + times.size() + " documents."); sb.append(LF); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("Time / Document: %,.3f (%,.3f)\n", statTimes.getMean(), statTimes.getStandardDeviation()); formatter.format("Time / 10^4 Token: %,.3f\n", getNormalizedTime(sumMillis, nrofTokens, 1000)); formatter.format("Time / 10^4 Sentences: %,.3f\n", getNormalizedTime(sumMillis, nrofSentences, 1000)); formatter.close(); return sb.toString(); }
From source file:com.scooter1556.sms.android.activity.VideoPlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video_player); restService = RESTService.getInstance(); player = new SMSVideoPlayer(); surface = (SurfaceView) findViewById(R.id.video_surface); surface.setOnSystemUiVisibilityChangeListener(onSystemUiVisibilityChanged); surface.setOnTouchListener(new View.OnTouchListener() { @Override//from www .j a va2 s . c o m public boolean onTouch(View view, MotionEvent motionEvent) { togglePlayback(); return false; } }); holder = surface.getHolder(); holder.addCallback(this); videoOverlay = (ImageView) findViewById(R.id.video_overlay); videoOverlay.setImageResource(R.drawable.play_overlay); timeline = (SeekBar) findViewById(R.id.video_controller_timeline); timeline.setOnSeekBarChangeListener(onSeek); formatBuilder = new StringBuilder(); formatter = new Formatter(formatBuilder, Locale.getDefault()); duration = (TextView) findViewById(R.id.video_controller_duration); duration.setText(stringForTime(0)); currentTime = (TextView) findViewById(R.id.video_controller_current_time); currentTime.setText(stringForTime(0)); playButton = (ImageButton) findViewById(R.id.video_controller_play); playButton.setImageResource(R.drawable.ic_play_light); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { togglePlayback(); } }); wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL, "sms"); controller = findViewById(R.id.video_controller); }