List of usage examples for java.text NumberFormat setMinimumFractionDigits
public void setMinimumFractionDigits(int newValue)
From source file:com.att.aro.main.TraceOverviewPanel.java
/** * Creates the plot data set from the current analysis * // w ww. j ava 2 s .c o m * @param analysis * The analysis data for the trace * @return CategoryDataset The plot data set for promotion ratio , * throughput and J/Kb. */ private CategoryDataset createDataset(TraceData.Analysis analysis) { this.throughputPct = analysis != null ? analysis.calculateThroughputPercentage(analysis) : 0; this.jpkbPct = analysis != null ? analysis.calculateJpkbPercentage(analysis) : 0; this.promotionRatioPct = analysis != null ? analysis.calculatePromotionRatioPercentage(analysis) : 0; this.kbps = analysis != null ? analysis.getAvgKbps() : 0; this.jpkb = analysis != null ? analysis.getRrcStateMachine().getJoulesPerKilobyte() : 0; this.promo = analysis != null ? analysis.getRrcStateMachine().getPromotionRatio() : 0; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(1); nf.setMinimumFractionDigits(1); double[][] data = new double[2][3]; data[0][0] = throughputPct; data[0][1] = jpkbPct; data[0][2] = promotionRatioPct; data[1][0] = 100.0 - throughputPct; data[1][1] = 100.0 - jpkbPct; data[1][2] = 100.0 - promotionRatioPct; return DatasetUtilities.createCategoryDataset(new Integer[] { 1, 2 }, new String[] { MessageFormat.format(rb.getString("overview.traceoverview.throughput"), nf.format(kbps)), MessageFormat.format(rb.getString("overview.traceoverview.jpkb"), nf.format(jpkb)), MessageFormat.format(rb.getString("overview.traceoverview.promoratio"), nf.format(promo)) }, data); }
From source file:me.philnate.textmanager.utils.PDFCreator.java
@SuppressWarnings("deprecation") private void preparePDF() { try {/* w ww . ja v a 2 s. c o m*/ File path = new File(SystemUtils.getUserDir(), "template"); File template = new File(path, Setting.find("template").getValue()); Velocity.setProperty("file.resource.loader.path", path.getAbsolutePath()); Velocity.init(); VelocityContext ctx = new VelocityContext(); // User data/Settings for (Setting setting : ds.find(Setting.class).asList()) { ctx.put(setting.getKey(), setting.getValue()); } NumberFormat format = NumberFormat.getNumberInstance(new Locale(Setting.find("locale").getValue())); // #60 always show 2 digits for fraction no matter if right most(s) // are zero format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); ctx.put("number", format); // TODO update schema to have separate first and lastname // Customer data ctx.put("customer", customer); // General data ctx.put("month", new DateFormatSymbols().getMonths()[month]); ctx.put("math", new MathTool()); // Billing data ctx.put("allItems", BillingItem.find(customer.getId(), year, month)); ctx.put("billNo", bill.getBillNo()); StringWriter writer = new StringWriter(); Velocity.mergeTemplate(template.getName(), ctx, writer); File filledTemplate = new File(path, bill.getBillNo() + ".tex"); FileUtils.writeStringToFile(filledTemplate, writer.toString(), "ISO-8859-1"); ProcessBuilder pdfLatex = new ProcessBuilder(Setting.find("pdfLatex").getValue(), "-interaction nonstopmode", "-output-format pdf", filledTemplate.toString()); // Saving template file (just in case it may be needed later GridFSFile texFile = tex.createFile(filledTemplate); texFile.put("month", month); texFile.put("year", year); texFile.put("customerId", customer.getId()); texFile.save(); pdfLatex.directory(path); String pdfPath = filledTemplate.toString().replaceAll("tex$", "pdf"); if (0 == printOutputStream(pdfLatex)) { // display Bill in DocumentViewer new ProcessBuilder(Setting.find("pdfViewer").getValue(), pdfPath).start().waitFor(); GridFSFile pdfFile = pdf.createFile(new File(pdfPath)); pdfFile.put("month", month); pdfFile.put("year", year); pdfFile.put("customerId", customer.getId()); pdf.remove(QueryBuilder.start("month").is(month).and("year").is(year).and("customerId") .is(customer.getId()).get()); pdfFile.save(); File[] files = path.listFiles((FileFilter) new WildcardFileFilter(bill.getBillNo() + ".*")); for (File file : files) { FileUtils.forceDelete(file); } } else { new JOptionPane( "Bei der Erstellung der Rechnung ist ein Fehler aufgetreten. Es wurde keine Rechnung erstellt.\n Bitte Schauen sie in die Logdatei fr nhere Fehlerinformationen.", JOptionPane.ERROR_MESSAGE).setVisible(true); } } catch (IOException e) { Throwables.propagate(e); } catch (InterruptedException e) { Throwables.propagate(e); } }
From source file:net.kjmaster.cookiemom.scout.ScoutFragment.java
private String getNumberFormatAsCash(Double amt) { NumberFormat fmt = NumberFormat.getCurrencyInstance(); fmt.setMaximumFractionDigits(0);/*w w w . j a v a 2 s . co m*/ fmt.setMinimumFractionDigits(0); return fmt.format(amt); }
From source file:API.JSONPractice.java
private void getMatch() throws Exception { Integer[] apIds = { 1026, 1052, 1056, 1058, 3001, 3003, 3020, 3023, 3025, 3027, 3040, 3041, 3050, 3057, 3060, 3089, 3092, 3098, 3100, 3108, 3113, 3115, 3116, 3124, 3135, 3136, 3145, 3146, 3151, 3152, 3157, 3165, 3174, 3191, 3285, 3303, 3504, 3708, 3716, 3720, 3724 }; List<Integer> apIdsList = Arrays.asList(apIds); Files.walk(Paths.get("C:\\AP_ITEMS\\")).forEach(filePath -> { if (Files.isRegularFile(filePath)) { try (FileReader fileReader = new FileReader(filePath.toString())) { File file = new File(filePath.toString()); String fileName = file.getName(); String region = fileName.replace(".json", "").toLowerCase(); JSONParser jsonParser = new JSONParser(); JSONArray matchId = (JSONArray) jsonParser.parse(fileReader); for (int i = 0; i < jsonFileSize; i++) { url = "https://" + region + ".api.pvp.net/api/lol/" + region + "/v2.2/match/" + matchId.get(i) + "?api_key=" + api_key; System.out.println(url); File jsonFile = new File("C:\\Riot_API\\" + region + "\\" + matchId.get(i) + ".json"); if (!jsonFile.exists()) { FileWriter fileWriter = new FileWriter(jsonFile); BufferedWriter bw = new BufferedWriter(fileWriter); URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); do { // optional default is GET con.setRequestMethod("GET"); int responseCode = con.getResponseCode(); System.out.println("\nSending 'GET' request to URL : " + url); System.out.println("Response Code : " + responseCode); if (responseCode == 500 || responseCode == 503) { tryAgain = true; } else { tryAgain = false; }//from w w w. j a v a 2 s. co m } while (tryAgain); StringBuffer response = new StringBuffer(); try (BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream()))) { String inputLine; while ((inputLine = in.readLine()) != null) { response.append(inputLine); } // do try in.close(); } catch (IOException e) { e.printStackTrace(); } JSONObject jsonObject = new JSONObject(response.toString()); for (int n = 0; n < numberOfParticipants; n++) { JSONObject stats = jsonObject.getJSONArray("participants").getJSONObject(n) .getJSONObject("stats"); JSONObject object = new JSONObject(); JSONArray arr = new JSONArray(); // String test = jsonObject.getJSONArray("participants").getJSONObject(i).getJSONObject("timeline").getString("lane"); for (int count = 0; count < itemSlots; count++) { if (stats.getInt("item" + count) != 0) { arr.add(stats.getInt("item" + count)); itemList.add(stats.getInt("item" + count)); } } object.put("participant" + (n + 1), arr); bw.write(object.toString()); } bw.flush(); bw.close(); } /* for (int itemId : itemList) { if (apIdsList.contains(itemId)) { fullApList.add(itemId); } } */ // Sleep count came from request limit of 500 request per 10 minute. // Therefore, 1.2 sec per request is allowed. Thread.sleep(1200); } NumberFormat defaultFormat = NumberFormat.getPercentInstance(); defaultFormat.setMinimumFractionDigits(1); /* for (int value : apIdsList) { double occurrences = Collections.frequency(fullApList, value); System.out.println(defaultFormat.format(occurrences / itemList.size())); } */ } catch (Exception e) { e.printStackTrace(); } } }); // } catch (FileNotFoundException | IOException | ParseException e) }
From source file:handlers.voicedcommands.WhoAmI.java
/** * Method useVoicedCommand./*from w w w. ja va 2 s.c o m*/ * @param command String * @param player Player * @param args String * @return boolean * @see lineage2.gameserver.handlers.IVoicedCommandHandler#useVoicedCommand(String, Player, String) */ @Override public boolean useVoicedCommand(String command, Player player, String args) { Creature target = null; double hpRegen = Formulas.calcHpRegen(player); double cpRegen = Formulas.calcCpRegen(player); double mpRegen = Formulas.calcMpRegen(player); double hpDrain = player.calcStat(Stats.ABSORB_DAMAGE_PERCENT, 0., target, null); double mpDrain = player.calcStat(Stats.ABSORB_DAMAGEMP_PERCENT, 0., target, null); double hpGain = player.calcStat(Stats.HEAL_EFFECTIVNESS, 100., target, null); double mpGain = player.calcStat(Stats.MANAHEAL_EFFECTIVNESS, 100., target, null); double critPerc = 2 * player.calcStat(Stats.CRITICAL_DAMAGE, target, null); double critStatic = player.calcStat(Stats.CRITICAL_DAMAGE_STATIC, target, null); double mCritDmg = player.calcStat(Stats.MCRITICAL_DAMAGE, target, null); double blowRate = player.calcStat(Stats.FATALBLOW_RATE, target, null); ItemInstance shld = player.getSecondaryWeaponInstance(); boolean shield = (shld != null) && (shld.getItemType() == WeaponType.NONE); double shieldDef = shield ? player.calcStat(Stats.SHIELD_DEFENCE, player.getTemplate().getBaseShldDef(), target, null) : 0.; double shieldRate = shield ? player.calcStat(Stats.SHIELD_RATE, target, null) : 0.; double xpRate = player.getRateExp(); double spRate = player.getRateSp(); double dropRate = player.getRateItems(); double adenaRate = player.getRateAdena(); double spoilRate = player.getRateSpoil(); double fireResist = player.calcStat(Element.FIRE.getDefence(), 0., target, null); double windResist = player.calcStat(Element.WIND.getDefence(), 0., target, null); double waterResist = player.calcStat(Element.WATER.getDefence(), 0., target, null); double earthResist = player.calcStat(Element.EARTH.getDefence(), 0., target, null); double holyResist = player.calcStat(Element.HOLY.getDefence(), 0., target, null); double unholyResist = player.calcStat(Element.UNHOLY.getDefence(), 0., target, null); double bleedPower = player.calcStat(Stats.BLEED_POWER, target, null); double bleedResist = player.calcStat(Stats.BLEED_RESIST, target, null); double poisonPower = player.calcStat(Stats.POISON_POWER, target, null); double poisonResist = player.calcStat(Stats.POISON_RESIST, target, null); double stunPower = player.calcStat(Stats.STUN_POWER, target, null); double stunResist = player.calcStat(Stats.STUN_RESIST, target, null); double rootPower = player.calcStat(Stats.ROOT_POWER, target, null); double rootResist = player.calcStat(Stats.ROOT_RESIST, target, null); double sleepPower = player.calcStat(Stats.SLEEP_POWER, target, null); double sleepResist = player.calcStat(Stats.SLEEP_RESIST, target, null); double paralyzePower = player.calcStat(Stats.PARALYZE_POWER, target, null); double paralyzeResist = player.calcStat(Stats.PARALYZE_RESIST, target, null); double mentalPower = player.calcStat(Stats.MENTAL_POWER, target, null); double mentalResist = player.calcStat(Stats.MENTAL_RESIST, target, null); double debuffPower = player.calcStat(Stats.DEBUFF_POWER, target, null); double debuffResist = player.calcStat(Stats.DEBUFF_RESIST, target, null); double cancelPower = player.calcStat(Stats.CANCEL_POWER, target, null); double cancelResist = player.calcStat(Stats.CANCEL_RESIST, target, null); double swordResist = 100. - player.calcStat(Stats.SWORD_WPN_VULNERABILITY, target, null); double dualResist = 100. - player.calcStat(Stats.DUAL_WPN_VULNERABILITY, target, null); double bluntResist = 100. - player.calcStat(Stats.BLUNT_WPN_VULNERABILITY, target, null); double daggerResist = 100. - player.calcStat(Stats.DAGGER_WPN_VULNERABILITY, target, null); double bowResist = 100. - player.calcStat(Stats.BOW_WPN_VULNERABILITY, target, null); double crossbowResist = 100. - player.calcStat(Stats.CROSSBOW_WPN_VULNERABILITY, target, null); double poleResist = 100. - player.calcStat(Stats.POLE_WPN_VULNERABILITY, target, null); double fistResist = 100. - player.calcStat(Stats.FIST_WPN_VULNERABILITY, target, null); double critChanceResist = 100. - player.calcStat(Stats.CRIT_CHANCE_RECEPTIVE, target, null); double critDamResistStatic = player.calcStat(Stats.CRIT_DAMAGE_RECEPTIVE, target, null); double critDamResist = 100. - (100 * (player.calcStat(Stats.CRIT_DAMAGE_RECEPTIVE, 1., target, null) - critDamResistStatic)); String dialog = HtmCache.getInstance().getNotNull("command/whoami.htm", player); NumberFormat df = NumberFormat.getInstance(Locale.ENGLISH); df.setMaximumFractionDigits(1); df.setMinimumFractionDigits(1); StrBuilder sb = new StrBuilder(dialog); sb.replaceFirst("%hpRegen%", df.format(hpRegen)); sb.replaceFirst("%cpRegen%", df.format(cpRegen)); sb.replaceFirst("%mpRegen%", df.format(mpRegen)); sb.replaceFirst("%hpDrain%", df.format(hpDrain)); sb.replaceFirst("%mpDrain%", df.format(mpDrain)); sb.replaceFirst("%hpGain%", df.format(hpGain)); sb.replaceFirst("%mpGain%", df.format(mpGain)); sb.replaceFirst("%critPerc%", df.format(critPerc)); sb.replaceFirst("%critStatic%", df.format(critStatic)); sb.replaceFirst("%mCritDmg%", df.format(mCritDmg)); sb.replaceFirst("%blowRate%", df.format(blowRate)); sb.replaceFirst("%shieldDef%", df.format(shieldDef)); sb.replaceFirst("%shieldRate%", df.format(shieldRate)); sb.replaceFirst("%xpRate%", df.format(xpRate)); sb.replaceFirst("%spRate%", df.format(spRate)); sb.replaceFirst("%dropRate%", df.format(dropRate)); sb.replaceFirst("%adenaRate%", df.format(adenaRate)); sb.replaceFirst("%spoilRate%", df.format(spoilRate)); sb.replaceFirst("%fireResist%", df.format(fireResist)); sb.replaceFirst("%windResist%", df.format(windResist)); sb.replaceFirst("%waterResist%", df.format(waterResist)); sb.replaceFirst("%earthResist%", df.format(earthResist)); sb.replaceFirst("%holyResist%", df.format(holyResist)); sb.replaceFirst("%darkResist%", df.format(unholyResist)); sb.replaceFirst("%bleedPower%", df.format(bleedPower)); sb.replaceFirst("%bleedResist%", df.format(bleedResist)); sb.replaceFirst("%poisonPower%", df.format(poisonPower)); sb.replaceFirst("%poisonResist%", df.format(poisonResist)); sb.replaceFirst("%stunPower%", df.format(stunPower)); sb.replaceFirst("%stunResist%", df.format(stunResist)); sb.replaceFirst("%rootPower%", df.format(rootPower)); sb.replaceFirst("%rootResist%", df.format(rootResist)); sb.replaceFirst("%sleepPower%", df.format(sleepPower)); sb.replaceFirst("%sleepResist%", df.format(sleepResist)); sb.replaceFirst("%paralyzePower%", df.format(paralyzePower)); sb.replaceFirst("%paralyzeResist%", df.format(paralyzeResist)); sb.replaceFirst("%mentalPower%", df.format(mentalPower)); sb.replaceFirst("%mentalResist%", df.format(mentalResist)); sb.replaceFirst("%debuffPower%", df.format(debuffPower)); sb.replaceFirst("%debuffResist%", df.format(debuffResist)); sb.replaceFirst("%cancelPower%", df.format(cancelPower)); sb.replaceFirst("%cancelResist%", df.format(cancelResist)); sb.replaceFirst("%swordResist%", df.format(swordResist)); sb.replaceFirst("%dualResist%", df.format(dualResist)); sb.replaceFirst("%bluntResist%", df.format(bluntResist)); sb.replaceFirst("%daggerResist%", df.format(daggerResist)); sb.replaceFirst("%bowResist%", df.format(bowResist)); sb.replaceFirst("%crossbowResist%", df.format(crossbowResist)); sb.replaceFirst("%fistResist%", df.format(fistResist)); sb.replaceFirst("%poleResist%", df.format(poleResist)); sb.replaceFirst("%critChanceResist%", df.format(critChanceResist)); sb.replaceFirst("%critDamResist%", df.format(critDamResist)); NpcHtmlMessage msg = new NpcHtmlMessage(0); msg.setHtml(Strings.bbParse(sb.toString())); player.sendPacket(msg); return true; }
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)); }// ww w . j a va 2 s.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.att.aro.ui.view.overviewtab.TraceBenchmarkChartPanel.java
/** * Creates the plot data set from the current analysis * //from w w w .j ava 2 s . c o m * @return CategoryDataset The plot data set for promotion ratio , * throughput and J/Kb. */ private CategoryDataset createDataset() { double throughputPct = 0; double jpkbPct = 0; double promotionRatioPct = 0; double kbps = 0; double jpkb = 0; double promo = 0; if (CommonHelper.isNotNull(traceBenchmarkData)) { throughputPct = traceBenchmarkData.getThroughputPct(); jpkbPct = traceBenchmarkData.getJpkbPct(); promotionRatioPct = traceBenchmarkData.getPromotionRatioPct(); kbps = traceBenchmarkData.getKbps(); jpkb = traceBenchmarkData.getJpkb(); promo = traceBenchmarkData.getPromoRatioPercentail(); } NumberFormat nFormat = NumberFormat.getNumberInstance(); nFormat.setMaximumFractionDigits(1); nFormat.setMinimumFractionDigits(1); double[][] data = new double[2][3]; data[0][0] = throughputPct; data[0][1] = jpkbPct; data[0][2] = promotionRatioPct; data[1][0] = 100.0 - throughputPct; data[1][1] = 100.0 - jpkbPct; data[1][2] = 100.0 - promotionRatioPct; return DatasetUtilities.createCategoryDataset(new Integer[] { 1, 2 }, new String[] { MessageFormat.format(ResourceBundleHelper.getMessageString("overview.traceoverview.throughput"), nFormat.format(kbps)), MessageFormat.format(ResourceBundleHelper.getMessageString("overview.traceoverview.jpkb"), nFormat.format(jpkb)), MessageFormat.format(ResourceBundleHelper.getMessageString("overview.traceoverview.promoratio"), nFormat.format(promo)) }, data); }
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 w w w .ja v a 2 s .c o m */ 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:com.trenako.entities.Money.java
@Override public String toString() { if (this == EMPTY_VALUE) { return "-"; }//w w w .j a v a 2 s.c om BigDecimal v = BigDecimal.valueOf(getValue()).divide(MONEY_VALUE_FACTOR); NumberFormat nf = NumberFormat.getCurrencyInstance(); // the user may have selected a different currency than the default Currency currency = Currency.getInstance(getCurrency()); nf.setCurrency(currency); nf.setMinimumFractionDigits(2); return nf.format(v); }
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 ww w .java 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")); } } }