Example usage for java.util Formatter close

List of usage examples for java.util Formatter close

Introduction

In this page you can find the example usage for java.util Formatter close.

Prototype

public void close() 

Source Link

Document

Closes this formatter.

Usage

From source file:edu.uga.cs.fluxbuster.analytics.ClusterSimilarityCalculator.java

/**
 * Calculate ip-based cluster similarities between all of the clusters generated
 * during the runs on the two supplied dates.
 * /*from   w  w w .  j  av  a  2s  .  com*/
 * @param adate the date of the first clustering run
 * @param bdate the date of the second clustering run
 * @return the list of ip-based cluster similarities
 * @throws IOException if the similarities could not be calculated
 */
public List<ClusterSimilarity> calculateIpSimilarities(Date adate, Date bdate) throws IOException {
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
    String adatestr = df.format(adate);
    String bdatestr = df.format(bdate);

    String query = properties.getProperty(IPKEY);
    StringBuffer querybuf = new StringBuffer();
    Formatter formatter = new Formatter(querybuf);
    formatter.format(query, adatestr, adatestr, bdatestr);
    query = querybuf.toString();
    formatter.close();
    return this.executeSimilarityQuery(query, adate, bdate);
}

From source file:com.cognifide.slice.cq.taglib.FormatTag.java

/** {@inheritDoc} */
@Override/*from   w ww  .j  av  a 2s.  co m*/
public int doStartTag() throws JspException {
    if (StringUtils.isNotBlank(format)) {
        Writer out = getJspWriter();

        Formatter formatter;
        if (locale == null) {
            formatter = new Formatter(out);
        } else {
            formatter = new Formatter(out, locale);
        }

        formatter.format(format, value);
        formatter.flush();
        formatter.close();
    }
    return SKIP_BODY;
}

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);
        }// w ww  . j  av  a  2 s.  com
        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:edu.uga.cs.fluxbuster.analytics.ClusterSimilarityCalculator.java

/**
 * Calculate domainname-based cluster similarities between all of the clusters generated
 * during the runs on the two supplied dates.
 *
 * @param adate the date of the first clustering run
 * @param bdate the date of the second clustering run
 * @return the list of domainname-based cluster similarities
 * @throws IOException if the similarities could not be calculated
 *//*ww w.j av a  2  s.  c o m*/
public List<ClusterSimilarity> calculateDomainnameSimilarities(Date adate, Date bdate) throws IOException {
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
    String adatestr = df.format(adate);
    String bdatestr = df.format(bdate);

    String query = properties.getProperty(DOMAINSKEY);
    StringBuffer querybuf = new StringBuffer();
    Formatter formatter = new Formatter(querybuf);
    formatter.format(query, adatestr, adatestr, adatestr, adatestr, bdatestr, bdatestr);
    query = querybuf.toString();
    formatter.close();
    return this.executeSimilarityQuery(query, adate, bdate);
}

From source file:org.kalypso.kalypsomodel1d2d.sim.TelemacKalypsoSimulation.java

private File findTelemacBatch(final String exeVersionName, File tmpdir) throws CoreException {
    final File batchFile = new File(tmpdir, "runTelemacKalypso.bat"); //$NON-NLS-1$

    OutputStream batchOutStream = null;
    try {/*from   w  ww  .j a v  a 2s. c o m*/
        batchOutStream = new BufferedOutputStream(new FileOutputStream(batchFile));

        Formatter formatter = new Formatter(batchOutStream);
        formatter.format("%s", exeVersionName);
        batchFile.setExecutable(true);
        formatter.close();
        batchOutStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (batchFile.exists())
        return batchFile;
    // final Location installLocation = Platform.getInstallLocation();
    // final File installDir = FileUtils.toFile( installLocation.getURL() );
    //    final File exeDir = new File( installDir, "bin" ); //$NON-NLS-1$
    // final File exeFile = new File( exeDir, exeName );
    // return exeFile;

    final String exeMissingMsg = String.format(
            Messages.getString("org.kalypso.kalypsomodel1d2d.sim.SWANCalculation.26"), //$NON-NLS-1$
            batchFile.getAbsolutePath());
    throw new CoreException(StatusUtilities.createErrorStatus(exeMissingMsg));
}

From source file:org.omegat.core.team2.impl.HTTPRemoteRepository.java

/**
 * Use SHA-1 as file version./* www.  ja  v  a2 s  . c om*/
 */
@Override
public String getFileVersion(String file) throws Exception {
    MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
    sha1.reset();

    // calculate SHA-1
    byte[] buffer = new byte[8192];
    InputStream in = new BufferedInputStream(new FileInputStream(file));
    try {
        while (true) {
            int len = in.read(buffer);
            if (len < 0) {
                break;
            }
            sha1.update(buffer, 0, len);
        }
    } finally {
        in.close();
    }

    // out as hex
    Formatter formatter = new Formatter();
    try {
        for (byte b : sha1.digest()) {
            formatter.format("%02x", b);
        }
        return formatter.toString();
    } finally {
        formatter.close();
    }
}

From source file:org.megam.deccanplato.provider.ProviderRegistry.java

public void Data() {
    StringBuilder strbd = new StringBuilder();
    final Formatter formatter = new Formatter(strbd);
    for (Map.Entry<String, Provider> entry : providersMap.entrySet()) {
        formatter.format("%10s = %s%n", entry.getKey(), entry.getValue());
    }//from   w w  w .j a v  a2  s  .c  o m
    for (Map.Entry<String, Set<BusinessActivity>> entry1 : bizActivityMap.entrySet()) {
        formatter.format("%10s = %s%n", entry1.getKey(), entry1.getValue());
    }
    formatter.close();

}

From source file:gdv.xport.util.XmlFormatter.java

private void write(final String attribute, final String format, final Object... args)
        throws XMLStreamException {
    Formatter formatter = new Formatter();
    String s = formatter.format(format, args).toString();
    xmlStreamWriter.writeAttribute(attribute, s);
    formatter.close();
}

From source file:it.geosolutions.android.map.geostore.fragment.GeoStoreResourceListFragment.java

/**
 * Update the info about pagination and visibility of more button
 *//* www . ja  va  2s .  c  om*/
private void updateView() {
    int count = adapter.getCount();
    if (loader != null) {
        TextView infoView = (TextView) getView().findViewById(R.id.info);

        Formatter f = new Formatter();
        String info = f.format(getString(R.string.geostore_info_format), count, loader.totalCount).toString();
        f.close();
        infoView.setText(info);
        //      if(count < loader.totalCount){
        //         moreButton.setVisibility(Button.VISIBLE);
        //      }
    }

}

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;//  w ww. j  a v  a  2s  .  c  o 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();
}