Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

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

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

Usage

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  . ja  v a 2s. c om*/
    });
    // 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.prowidesoftware.swift.model.field.Field111.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*  w w w  . ja  va  2 s .c  om*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 111");
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(notNull(locale));
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field19Y.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*from ww w.j a v a 2  s .c o m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 19Y");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field19Z.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*  w w w.  ja v  a2s . c o m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 19Z");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field32J.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8// w w w.java2  s.c o m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 32J");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field36.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*  ww  w .  java2s . c o  m*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 36");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field36A.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8// ww  w  .j a  va2s .  c  o  m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 36A");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field37J.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8/*www. j a  v a 2 s  .com*/
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 37J");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field37L.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8//from   ww w.  jav a  2s  .  co m
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 37L");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}

From source file:com.prowidesoftware.swift.model.field.Field37P.java

/**
 * Returns a localized suitable for showing to humans string of a field component.<br>
 *
 * @param component number of the component to display
 * @param locale optional locale to format date and amounts, if null, the default locale is used
 * @return formatted component value or null if component number is invalid or not present
 * @throws IllegalArgumentException if component number is invalid for the field
 * @since 7.8// w  ww .j av a  2 s .  c  om
 */
@Override
public String getValueDisplay(int component, Locale locale) {
    if (component < 1 || component > 1) {
        throw new IllegalArgumentException("invalid component number " + component + " for field 37P");
    }
    if (locale == null) {
        locale = Locale.getDefault();
    }
    if (component == 1) {
        //number or amount
        java.text.NumberFormat f = java.text.NumberFormat.getNumberInstance(locale);
        Number n = getComponent1AsNumber();
        if (n != null) {
            return f.format(n);
        }
    }
    return null;
}