Example usage for java.text NumberFormat setMaximumFractionDigits

List of usage examples for java.text NumberFormat setMaximumFractionDigits

Introduction

In this page you can find the example usage for java.text NumberFormat setMaximumFractionDigits.

Prototype

public void setMaximumFractionDigits(int newValue) 

Source Link

Document

Sets the maximum number of digits allowed in the fraction portion of a number.

Usage

From source file:com.codebutler.farebot.transit.suica.SuicaTrip.java

@Override
public String getBalanceString() {
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN);
    format.setMaximumFractionDigits(0);
    return format.format(mBalance);
}

From source file:org.rhq.enterprise.gui.legacy.taglib.MetricDisplayTag.java

@Override
public int doEndTag() throws JspException {
    Locale userLocale = RequestUtils.retrieveUserLocale(pageContext, locale);
    if (unitIsSet) {
        setUnitVal((String) evalAttr("unit", unit_el, String.class));
    }/*from   w  w w.j  av  a  2s  . c om*/

    if (defaultKeyIsSet) {
        setDefaultKeyVal((String) evalAttr("defaultKey", defaultKey_el, String.class));
    }

    // if the metric value is empty, converting to a Double will
    // give a value of 0.0. this makes it impossible for us to
    // distinguish further down the line whether the metric was
    // actually collected with a value of 0.0 or whether it was
    // not collected at all. therefore, we'll let metricVal be
    // null if the metric was not collected, and we'll check for
    // null later when handling the not-avail case.
    // PR: 7588
    String mval = (String) evalAttr("metric", metric_el, String.class);
    if ((mval != null) && !mval.equals("")) {
        setMetricVal(new Double(mval));
    }

    StringBuffer sb = new StringBuffer("<span");
    if (spanIsSet && (getSpan().length() > 0)) {
        setSpanVal((String) evalAttr("span", span_el, String.class));
        sb.append(" class=\"");
        sb.append(getSpanVal());
        sb.append("\"");
    }

    sb.append(">");

    if ((getMetricVal() == null) || (Double.isNaN(getMetricVal().doubleValue()) && defaultKeyIsSet)) {
        sb.append(RequestUtils.message(pageContext, bundle, userLocale.toString(), getDefaultKeyVal()));
    }

    // XXXX remove duplication with the metric decorator
    // and the UnitsConvert/UnitsFormat stuff
    else if (getUnitVal().equals("ms")) {
        NumberFormat f = NumberFormat.getNumberInstance(userLocale);
        f.setMinimumFractionDigits(3);
        f.setMaximumFractionDigits(3);
        String formatted = f.format(getMetricVal().doubleValue() / 1000);
        String[] args = new String[] { formatted };
        sb.append(RequestUtils.message(pageContext, bundle, userLocale.toString(), "metric.tag.units.s.arg",
                args));
    } else {
        MeasurementUnits units = MeasurementUnits.valueOf(getUnitVal());
        Double dataValue = getMetricVal();
        String formattedValue = MeasurementConverter.format(dataValue, units, true);

        sb.append(formattedValue);
    }

    sb.append("</span>");

    try {
        pageContext.getOut().print(sb.toString());
    } catch (IOException e) {
        log.debug("could not write output: ", e);
        throw new JspException("Could not access metrics tag");
    }

    release();
    return EVAL_PAGE;
}

From source file:com.codebutler.farebot.transit.suica.SuicaTrip.java

@Override
public String getFareString() {
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN);
    format.setMaximumFractionDigits(0);
    if (mFare < 0) {
        return "+" + format.format(-mFare);
    } else {/*from   w  w  w.ja  v  a 2s. c o m*/
        return format.format(mFare);
    }
}

From source file:de.betterform.xml.xforms.ui.AbstractFormControl.java

/**
 * convert a localized value into its XML Schema datatype representation. If the value given cannot be parsed with
 * the locale in betterForm context the default locale (US) will be used as fallback. This can be convenient for
 * user-agents that do not pass a localized value back.
 *
 * @param value the value to convert/*from   www  . ja va  2s  . c o m*/
 * @return converted value that can be used to update instance data and match the Schema datatype lexical space
 * @throws java.text.ParseException in case the incoming string cannot be converted into a Schema datatype representation
 */
protected String delocaliseValue(String value) throws XFormsException, ParseException {
    if (value == null || value.equals("")) {
        return value;
    }
    if (Config.getInstance().getProperty(XFormsProcessorImpl.BETTERFORM_ENABLE_L10N).equals("true")) {
        Locale locale = (Locale) getModel().getContainer().getProcessor().getContext()
                .get(XFormsProcessorImpl.BETTERFORM_LOCALE);
        XFormsProcessorImpl processor = this.model.getContainer().getProcessor();

        if (processor.hasControlType(this.id, NamespaceConstants.XMLSCHEMA_PREFIX + ":float")
                || processor.hasControlType(this.id, NamespaceConstants.XMLSCHEMA_PREFIX + ":decimal")
                || processor.hasControlType(this.id, NamespaceConstants.XMLSCHEMA_PREFIX + ":double")) {

            NumberFormat formatter = NumberFormat.getNumberInstance(locale);
            formatter.setMaximumFractionDigits(Double.SIZE);
            BigDecimal number;

            try {
                number = strictParse(value, locale);
            } catch (ParseException e) {
                LOGGER.warn("value: '" + value + "' could not be parsed for locale: " + locale);
                return value;
            } catch (NumberFormatException nfe) {
                LOGGER.warn("value: '" + value + "' could not be parsed for locale: " + locale);
                return value;
            } catch (InputMismatchException ime) {
                LOGGER.warn("value: '" + value + "' could not be parsed for locale: " + locale);
                return value;
            }
            return number.toPlainString();
        } else if (processor.hasControlType(this.id, NamespaceConstants.XMLSCHEMA_PREFIX + ":date")) {
            DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
            Date d = null;
            try {
                d = df.parse(value);
            } catch (ParseException e) {
                //try the default locale - else fail with ParseException
                df = new SimpleDateFormat("yyyy-MM-dd");
                df.setLenient(false);
                d = df.parse(value);
            }
            df = new SimpleDateFormat("yyyy-MM-dd");
            return df.format(d);
        } else if (processor.hasControlType(this.id, NamespaceConstants.XMLSCHEMA_PREFIX + ":dateTime")) {
            String timezone = "";
            // int position = ;
            if (value.contains("GMT")) {
                timezone = value.substring(value.indexOf("GMT") + 3, value.length());
            } else if (value.contains("+")) {
                timezone = value.substring(value.indexOf("+"), value.length());

            } else if (value.contains("Z")) {
                timezone = "Z";
            }

            DateFormat sf = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, locale);
            Date d = null;
            try {
                d = sf.parse(value);
            } catch (ParseException e) {
                //try the default locale - else fail with ParseException
                sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
                d = null;
                d = sf.parse(value);
            }
            sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            String converted = sf.format(d);
            if (!timezone.equals("")) {
                return converted + timezone;
            }
            return converted;
        }
    }
    return value;
}

From source file:org.apache.flex.utilities.converter.flash.FlashConverter.java

/**
 * This method generates those artifacts that resemble the runtime part of the Flash SDK.
 *
 * @throws ConverterException//from www. j  a v a 2 s .  c  om
 */
protected void generateRuntimeArtifacts() throws ConverterException {
    // Create a list of all libs that should belong to the Flash SDK runtime.
    final File directory = new File(rootSourceDirectory, "runtimes" + File.separator + "player");
    if (!directory.exists() || !directory.isDirectory()) {
        System.out.println("Skipping runtime generation.");
        return;
    }
    final List<File> playerVersions = new ArrayList<File>();
    playerVersions.addAll(Arrays.asList(directory.listFiles(new FlashRuntimeFilter())));

    // In really old SDKs the flash-player was installed in the players directory directly.
    if (new File(directory, "win").exists()) {
        playerVersions.add(directory);
    }

    // Generate artifacts for every jar in the input directories.
    for (final File versionDir : playerVersions) {
        // The flash-player 9 is installed directly in the player directory.
        String playerVersionString;
        if (versionDir == directory) {
            playerVersionString = "9.0";
        } else {
            playerVersionString = versionDir.getName();
        }

        final double playerVersion = Double.valueOf(playerVersionString);
        final NumberFormat doubleFormat = NumberFormat.getInstance(Locale.US);
        doubleFormat.setMinimumFractionDigits(1);
        doubleFormat.setMaximumFractionDigits(1);
        final String version = doubleFormat.format(playerVersion);

        final MavenArtifact playerArtifact = new MavenArtifact();
        playerArtifact.setGroupId("com.adobe.flash");
        playerArtifact.setArtifactId("runtime");
        playerArtifact.setVersion(version);
        playerArtifact.setPackaging("exe");

        // Deploy Windows binaries.
        final File windowsDirectory = new File(versionDir, "win");
        if (windowsDirectory.exists()) {
            // Find out if a flash-player binary exists.
            File flashPlayerBinary = null;
            if (new File(windowsDirectory, "FlashPlayerDebugger.exe").exists()) {
                flashPlayerBinary = new File(windowsDirectory, "FlashPlayerDebugger.exe");
            } else if (new File(windowsDirectory, "FlashPlayer.exe").exists()) {
                flashPlayerBinary = new File(windowsDirectory, "FlashPlayer.exe");
            }

            // If a binary exists, copy it to the target and create a pom for it.
            if (flashPlayerBinary != null) {
                playerArtifact.addBinaryArtifact("win", flashPlayerBinary);
            }
        }

        // Deploy Mac binaries.
        final File macDirectory = new File(versionDir, "mac");
        if (macDirectory.exists()) {
            // Find out if a flash-player binary exists.
            File flashPlayerBinary = null;
            if (new File(macDirectory, "Flash Player.app.zip").exists()) {
                flashPlayerBinary = new File(macDirectory, "Flash Player.app.zip");
            } else if (new File(macDirectory, "Flash Player Debugger.app.zip").exists()) {
                flashPlayerBinary = new File(macDirectory, "Flash Player Debugger.app.zip");
            }

            // If a binary exists, copy it to the target and create a pom for it.
            if (flashPlayerBinary != null) {
                playerArtifact.addBinaryArtifact("mac", flashPlayerBinary);
            }
        }

        // Deploy Linux binaries.
        final File lnxDirectory = new File(versionDir, "lnx");
        if (lnxDirectory.exists()) {
            // Find out if a flash-player binary exists.
            File flashPlayerBinary;
            if (new File(lnxDirectory, "flashplayer.tar.gz").exists()) {
                flashPlayerBinary = new File(lnxDirectory, "flashplayer.tar.gz");
            } else if (new File(lnxDirectory, "flashplayerdebugger.tar.gz").exists()) {
                flashPlayerBinary = new File(lnxDirectory, "flashplayerdebugger.tar.gz");
            } else {
                throw new ConverterException("Couldn't find player archive.");
            }

            // Decompress the archive.
            // First unzip it.
            final FileInputStream fin;
            try {
                fin = new FileInputStream(flashPlayerBinary);
                final BufferedInputStream in = new BufferedInputStream(fin);
                final File tempTarFile = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                        ".tar");
                final FileOutputStream out = new FileOutputStream(tempTarFile);
                final GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
                final byte[] buffer = new byte[1024];
                int n;
                while (-1 != (n = gzIn.read(buffer))) {
                    out.write(buffer, 0, n);
                }
                out.close();
                gzIn.close();

                // Then untar it.
                File uncompressedBinary = null;
                final FileInputStream tarFileInputStream = new FileInputStream(tempTarFile);
                final TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(
                        tarFileInputStream);
                ArchiveEntry entry;
                while ((entry = tarArchiveInputStream.getNextEntry()) != null) {
                    if ("flashplayer".equals(entry.getName())) {
                        uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                                ".uexe");
                        final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(
                                uncompressedBinary);
                        while (-1 != (n = tarArchiveInputStream.read(buffer))) {
                            uncompressedBinaryOutputStream.write(buffer, 0, n);
                        }
                        uncompressedBinaryOutputStream.close();
                    } else if ("flashplayerdebugger".equals(entry.getName())) {
                        uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                                ".uexe");
                        final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(
                                uncompressedBinary);
                        while (-1 != (n = tarArchiveInputStream.read(buffer))) {
                            uncompressedBinaryOutputStream.write(buffer, 0, n);
                        }
                        uncompressedBinaryOutputStream.close();
                    }
                }
                tarFileInputStream.close();

                // If a binary exists, copy it to the target and create a pom for it.
                if (uncompressedBinary != null) {
                    playerArtifact.addBinaryArtifact("linux", flashPlayerBinary);
                }
            } catch (FileNotFoundException e) {
                throw new ConverterException("Error processing the linux player tar file", e);
            } catch (IOException e) {
                throw new ConverterException("Error processing the linux player tar file", e);
            }
        }

        // Write this artifact to file.
        writeArtifact(playerArtifact);
    }
}

From source file:org.hyperic.hq.ui.taglib.MetricDisplayTag.java

public int doEndTag() throws JspException {
    Locale userLocale = TagUtils.getInstance().getUserLocale(pageContext, locale);

    if (unitIsSet) {
        setUnitVal(getUnit());/*from w ww .  j  a  va 2 s. c o m*/
    }

    if (defaultKeyIsSet) {
        setDefaultKeyVal(getDefaultKey());
    }

    // if the metric value is empty, converting to a Double will
    // give a value of 0.0. this makes it impossible for us to
    // distinguish further down the line whether the metric was
    // actually collected with a value of 0.0 or whether it was
    // not collected at all. therefore, we'll let metricVal be
    // null if the metric was not collected, and we'll check for
    // null later when handling the not-avail case.
    // PR: 7588
    String mval = getMetric();

    if (mval != null && !mval.equals("")) {
        setMetricVal(new Double(mval));
    }

    StringBuffer sb = new StringBuffer("<span");

    if (spanIsSet && getSpan().length() > 0) {
        setSpanVal(getSpan());
        sb.append(" class=\"");
        sb.append(getSpanVal());
        sb.append("\"");
    }

    sb.append(">");

    if (getMetricVal() == null || Double.isNaN(getMetricVal().doubleValue()) && defaultKeyIsSet) {
        sb.append(
                TagUtils.getInstance().message(pageContext, bundle, userLocale.toString(), getDefaultKeyVal()));
    }
    // XXXX remove duplication with the metric decorator
    // and the UnitsConvert/UnitsFormat stuff
    else if (getUnitVal().equals("ms")) {
        NumberFormat f = NumberFormat.getNumberInstance(userLocale);

        f.setMinimumFractionDigits(3);
        f.setMaximumFractionDigits(3);

        String formatted = f.format(getMetricVal().doubleValue() / 1000);
        String[] args = new String[] { formatted };

        sb.append(TagUtils.getInstance().message(pageContext, bundle, userLocale.toString(),
                "metric.tag.units.s.arg", args));
    } else {
        FormattedNumber f = UnitsConvert.convert(getMetricVal().doubleValue(), getUnitVal(), userLocale);

        sb.append(f.getValue());

        if (f.getTag() != null && f.getTag().length() > 0) {
            sb.append(" ").append(f.getTag());
        }
    }

    sb.append("</span>");

    try {
        pageContext.getOut().print(sb.toString());
    } catch (IOException e) {
        log.debug("could not write output: ", e);

        throw new JspException("Could not access metrics tag");
    }

    release();

    return EVAL_PAGE;
}

From source file:org.kuali.rice.core.web.format.CurrencyFormatter.java

/**
 * Returns a string representation of its argument formatted as a currency value.
 *
 * begin Kuali Foundation modification//from  w  ww.  jav  a  2s.  c  o  m
 * @see org.kuali.rice.core.web.format.Formatter#format(java.lang.Object)
 * end Kuali Foundation modification
 */
// begin Kuali Foundation modification
@Override
// end Kuali Foundation modification
public Object format(Object obj) {
    // begin Kuali Foundation modification
    // major code rewrite, original code commented
    /*
    if (obj == null)
    return null;
            
    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    String string = null;
            
    try {
    BigDecimal number = (BigDecimal) obj;
    number = number.setScale(SCALE, BigDecimal.ROUND_HALF_UP);
    string = formatter.format(number.doubleValue());
    } catch (IllegalArgumentException e) {
    throw new FormatException(FORMAT_MSG + obj, e);
    } catch (ClassCastException e) {
    throw new FormatException(FORMAT_MSG + obj, e);
    }
            
    return showSymbol() ? string : removeSymbol(string);
    */
    LOG.debug("format '" + obj + "'");
    if (obj == null) {
        return null;
    }
    if (obj instanceof String && StringUtils.isEmpty((String) obj)) {
        return null;
    }

    NumberFormat formatter = getCurrencyInstanceUsingParseBigDecimal();
    String string = null;

    try {
        Number number;

        if (obj instanceof KualiInteger) {
            formatter.setMaximumFractionDigits(0);
            number = (KualiInteger) obj;

            // Note that treating the number as a KualiDecimal below is obsolete. But it doesn't do any harm either since
            // we already set maximumFractionDigits above.
        } else {
            number = (KualiDecimal) obj;
        }

        // run the incoming KualiDecimal's string representation through convertToObject, so that KualiDecimal objects
        // containing ill-formatted incoming values will cause the same errors here that ill-formatted Strings do in
        // convertToObject
        KualiDecimal convertedNumber = (KualiDecimal) convertToObject(number.toString());

        string = formatter.format(convertedNumber.bigDecimalValue());
    } catch (IllegalArgumentException e) {
        throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
    } catch (ClassCastException e) {
        throw new FormatException("formatting", RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
    }

    return showSymbol() ? string : removeSymbol(string);
    // end Kuali Foundation modification
}

From source file:org.apache.maven.graph.common.version.SingleVersionComparisonsTest.java

@After
public void checkErrors() {
    if (!failed.isEmpty()) {
        final NumberFormat fmt = NumberFormat.getPercentInstance();
        fmt.setMaximumFractionDigits(2);

        final String message = name.getMethodName() + ": "
                + (fmt.format(failed.size() / ((double) failed.size() + (double) okay.size()))) + " ("
                + failed.size() + "/" + (failed.size() + okay.size()) + ") of version comparisons FAILED.";

        System.out.println(message);

        if (!okay.isEmpty()) {
            System.out.println("OKAY " + join(okay, "\nOKAY "));
        }//from  w w  w  . ja  v a  2 s  .c  o  m

        System.out.println("FAIL " + join(failed, "\nFAIL "));
        fail(message);
    } else {
        System.out.println(name.getMethodName() + ": All tests OKAY");
    }
}

From source file:air.AirRuntimeGenerator.java

protected void processFlashRuntime(File sdkSourceDirectory, File sdkTargetDirectory) throws Exception {
    final File runtimeDirectory = new File(sdkSourceDirectory, "runtimes");
    final File flashPlayerDirectory = new File(runtimeDirectory, "player");

    File[] versions = flashPlayerDirectory.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.isDirectory() && !"win".equalsIgnoreCase(pathname.getName())
                    && !"lnx".equalsIgnoreCase(pathname.getName())
                    && !"mac".equalsIgnoreCase(pathname.getName());
        }/*from   w ww .  j a va  2 s .com*/
    });
    // The flash-player 9 is installed directly in the player directory.
    if (new File(flashPlayerDirectory, "win").exists()) {
        final File[] extendedVersions = new File[versions.length + 1];
        System.arraycopy(versions, 0, extendedVersions, 0, versions.length);
        extendedVersions[versions.length] = flashPlayerDirectory;
        versions = extendedVersions;
    }

    if (versions != null) {
        for (final File versionDir : versions) {
            // If the versionDir is called "player", then this is the home of the flash-player version 9.
            final String playerVersionString = "player".equalsIgnoreCase(versionDir.getName()) ? "9.0"
                    : versionDir.getName();
            final double playerVersion = Double.valueOf(playerVersionString);
            final NumberFormat doubleFormat = NumberFormat.getInstance(Locale.US);
            doubleFormat.setMinimumFractionDigits(1);
            doubleFormat.setMaximumFractionDigits(1);
            final String version = doubleFormat.format(playerVersion);

            final File targetDir = new File(sdkTargetDirectory, "com/adobe/flash/runtime/" + version);

            // Deploy Windows binaries.
            final File windowsDirectory = new File(versionDir, "win");
            if (windowsDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(windowsDirectory, "FlashPlayerDebugger.exe").exists()) {
                    flashPlayerBinary = new File(windowsDirectory, "FlashPlayerDebugger.exe");
                } else if (new File(windowsDirectory, "FlashPlayer.exe").exists()) {
                    flashPlayerBinary = new File(windowsDirectory, "FlashPlayer.exe");
                }

                // If a binary exists, copy it to the target and create a pom for it.
                if (flashPlayerBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-win.exe");
                    copyFile(flashPlayerBinary, targetFile);
                }
            }

            // Deploy Mac binaries.
            final File macDirectory = new File(versionDir, "mac");
            if (macDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(macDirectory, "Flash Player.app.zip").exists()) {
                    flashPlayerBinary = new File(macDirectory, "Flash Player.app.zip");
                } else if (new File(macDirectory, "Flash Player Debugger.app.zip").exists()) {
                    flashPlayerBinary = new File(macDirectory, "Flash Player Debugger.app.zip");
                }

                // If a binary exists, copy it to the target and create a pom for it.
                if (flashPlayerBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-mac.zip");
                    copyFile(flashPlayerBinary, targetFile);
                }
            }

            // Deploy Linux binaries.
            final File lnxDirectory = new File(versionDir, "lnx");
            if (lnxDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(lnxDirectory, "flashplayer.tar.gz").exists()) {
                    flashPlayerBinary = new File(lnxDirectory, "flashplayer.tar.gz");
                } else if (new File(lnxDirectory, "flashplayerdebugger.tar.gz").exists()) {
                    flashPlayerBinary = new File(lnxDirectory, "flashplayerdebugger.tar.gz");
                }

                // Decompress the archive.
                // First unzip it.
                final FileInputStream fin = new FileInputStream(flashPlayerBinary);
                final BufferedInputStream in = new BufferedInputStream(fin);
                final File tempTarFile = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                        ".tar");
                final FileOutputStream out = new FileOutputStream(tempTarFile);
                final GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
                final byte[] buffer = new byte[1024];
                int n;
                while (-1 != (n = gzIn.read(buffer))) {
                    out.write(buffer, 0, n);
                }
                out.close();
                gzIn.close();

                // Then untar it.
                File uncompressedBinary = null;
                final FileInputStream tarFileInputStream = new FileInputStream(tempTarFile);
                final TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(
                        tarFileInputStream);
                ArchiveEntry entry;
                while ((entry = tarArchiveInputStream.getNextEntry()) != null) {
                    if ("flashplayer".equals(entry.getName())) {
                        uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                                ".uexe");
                        final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(
                                uncompressedBinary);
                        while (-1 != (n = tarArchiveInputStream.read(buffer))) {
                            uncompressedBinaryOutputStream.write(buffer, 0, n);
                        }
                        uncompressedBinaryOutputStream.close();
                    } else if ("flashplayerdebugger".equals(entry.getName())) {
                        uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                                ".uexe");
                        final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(
                                uncompressedBinary);
                        while (-1 != (n = tarArchiveInputStream.read(buffer))) {
                            uncompressedBinaryOutputStream.write(buffer, 0, n);
                        }
                        uncompressedBinaryOutputStream.close();
                    }
                }
                tarFileInputStream.close();

                // If a binary exists, copy it to the target and create a pom for it.
                if (uncompressedBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-linux.uexe");
                    copyFile(uncompressedBinary, targetFile);

                    // Clean up in the temp directory.
                    if (!uncompressedBinary.delete()) {
                        System.out.println("Could not delete: " + uncompressedBinary.getAbsolutePath());
                    }
                }

                // Clean up in the temp directory.
                if (!tempTarFile.delete()) {
                    System.out.println("Could not delete: " + tempTarFile.getAbsolutePath());
                }
            }

            final MavenMetadata playerArtifact = new MavenMetadata();
            playerArtifact.setGroupId("com.adobe.flash");
            playerArtifact.setArtifactId("runtime");
            playerArtifact.setVersion(version);
            playerArtifact.setPackaging("exe");

            writeDocument(createPomDocument(playerArtifact),
                    new File(targetDir, "runtime-" + version + ".pom"));
        }
    }
}

From source file:com.levien.audiobuffersize.AudioBufferSize.java

ThreadMeasurement analyzeJitter(double[] arr) {
    int n = arr.length / 4;
    double maxCbDoneDelay = 0;
    double maxThreadDelay = 0;
    double maxRenderDelay = 0;
    for (int i = 100; i < n; i++) {
        double callback_ts = arr[i - 0];
        double cbdone_ts = arr[n + i];
        double thread_ts = arr[2 * n + i];
        double render_ts = arr[3 * n + i];
        maxCbDoneDelay = Math.max(maxCbDoneDelay, cbdone_ts - callback_ts);
        maxThreadDelay = Math.max(maxThreadDelay, thread_ts - callback_ts);
        maxRenderDelay = Math.max(maxRenderDelay, render_ts - callback_ts);
    }/*from   w w  w  . j a v  a2  s .c  o  m*/
    NumberFormat f = NumberFormat.getInstance();
    f.setMinimumFractionDigits(3);
    f.setMaximumFractionDigits(3);
    ThreadMeasurement tm = new ThreadMeasurement();
    tm.cbDone = maxCbDoneDelay;
    tm.renderStart = maxThreadDelay;
    tm.renderEnd = maxRenderDelay;
    return tm;
}