List of usage examples for java.util Formatter Formatter
public Formatter()
From source file:edu.ku.brc.specify.plugins.ipadexporter.iPadRepositoryHelper.java
/** * @param hash// w w w .j av a2 s .co m * @return */ private String byteArray2Hex(byte[] hash) { Formatter formatter = new Formatter(); for (byte b : hash) { formatter.format("%02x", b); } return formatter.toString(); }
From source file:com.zimbra.cs.util.ProxyConfOverride.java
public String formatInteger(Object o) { Formatter f = new Formatter(); f.format("%d", (Integer) o); return f.toString(); }
From source file:com.tulskiy.musique.system.configuration.Configuration.java
public void setRectangle(String key, Rectangle value) { if (value == null) remove(key);/*from w ww .ja v a 2s . c o m*/ else { String s = new Formatter().format("%d %d %d %d", (int) value.getX(), (int) value.getY(), (int) value.getWidth(), (int) value.getHeight()).toString(); put(key, s); } }
From source file:fr.gael.dhus.sync.impl.ODataProductSynchronizer.java
/** * Uses the given `http_client` to download `url` into `out_tmp`. * Renames `out_tmp` to the value of the filename param of the Content-Disposition header field. * Returns a path to the renamed file.//from w w w . ja v a 2s. c om * * @param http_client synchronous interruptible HTTP client. * @param out_tmp download destination file on disk (will be created if does not exist). * @param url what to download. * @return Path to file with its actual name. * @throws IOException Anything went wrong (with IO or network, or if the HTTP header field * Content-Disposition is missing). * @throws InterruptedException Thread has been interrupted. */ private DownloadResult downloadValidateRename(InterruptibleHttpClient http_client, Path out_tmp, String url) throws IOException, InterruptedException { try (FileChannel output = FileChannel.open(out_tmp, StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) { HttpResponse response = http_client.interruptibleGet(url, output); // If the response's status code is not 200, something wrong happened if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { Formatter ff = new Formatter(); ff.format( "Synchronizer#%d cannot download product at %s," + " remote dhus returned message '%s' (HTTP%d)", getId(), url, response.getStatusLine().getReasonPhrase(), response.getStatusLine().getStatusCode()); throw new IOException(ff.out().toString()); } // Gets the filename from the HTTP header field `Content-Disposition' Pattern pat = Pattern.compile("filename=\"(.+?)\"", Pattern.CASE_INSENSITIVE); String contdis = response.getFirstHeader("Content-Disposition").getValue(); Matcher m = pat.matcher(contdis); if (!m.find()) { throw new IOException("Synchronizer#" + getId() + " Missing HTTP header field `Content-Disposition` that determines the filename"); } String filename = m.group(1); if (filename == null || filename.isEmpty()) { throw new IOException( "Synchronizer#" + getId() + " Invalid filename in HTTP header field `Content-Disposition`"); } // Renames the downloaded file output.close(); Path dest = out_tmp.getParent().resolve(filename); Files.move(out_tmp, dest, StandardCopyOption.ATOMIC_MOVE); DownloadResult res = new DownloadResult(dest, response.getEntity().getContentType().getValue(), response.getEntity().getContentLength()); return res; } finally { if (Files.exists(out_tmp)) { Files.delete(out_tmp); } } }
From source file:fll.scheduler.SchedulerUI.java
void saveScheduleDescription() { if (null == mScheduleDescriptionFile) { // prompt the user for a filename to save to final String startingDirectory = PREFS.get(DESCRIPTION_STARTING_DIRECTORY_PREF, null); final JFileChooser fileChooser = new JFileChooser(); final FileFilter filter = new BasicFileFilter("FLL Schedule Description (properties)", new String[] { "properties" }); fileChooser.setFileFilter(filter); if (null != startingDirectory) { fileChooser.setCurrentDirectory(new File(startingDirectory)); }/*from ww w . j a va 2 s . c o m*/ final int returnVal = fileChooser.showSaveDialog(SchedulerUI.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File currentDirectory = fileChooser.getCurrentDirectory(); PREFS.put(DESCRIPTION_STARTING_DIRECTORY_PREF, currentDirectory.getAbsolutePath()); mScheduleDescriptionFile = fileChooser.getSelectedFile(); mDescriptionFilename.setText(mScheduleDescriptionFile.getName()); } else { // user canceled return; } } try (final Writer writer = new OutputStreamWriter(new FileOutputStream(mScheduleDescriptionFile), Utilities.DEFAULT_CHARSET)) { final SolverParams params = mScheduleDescriptionEditor.getParams(); final List<String> errors = params.isValid(); if (!errors.isEmpty()) { final String formattedErrors = errors.stream().collect(Collectors.joining("\n")); JOptionPane.showMessageDialog(SchedulerUI.this, "There are errors that need to be corrected before the description can be saved: " + formattedErrors, "Error saving file", JOptionPane.ERROR_MESSAGE); } else { final Properties properties = new Properties(); params.save(properties); properties.store(writer, null); } } catch (final IOException e) { final Formatter errorFormatter = new Formatter(); errorFormatter.format("Error saving file: %s", e.getMessage()); LOGGER.error(errorFormatter, e); JOptionPane.showMessageDialog(SchedulerUI.this, errorFormatter, "Error saving file", JOptionPane.ERROR_MESSAGE); } }
From source file:edu.cmu.tetrad.cli.search.FgsCli.java
private static String createArgsInfo() { Formatter fmt = new Formatter(); if (dataFile != null) { fmt.format("data = %s%n", dataFile.getFileName()); }/*from w w w .j a va 2 s . c o m*/ if (excludedVariableFile != null) { fmt.format("exclude-variables = %s%n", excludedVariableFile.getFileName()); } if (knowledgeFile != null) { fmt.format("knowledge = %s%n", knowledgeFile.getFileName()); } fmt.format("delimiter = %s%n", Args.getDelimiterName(delimiter)); fmt.format("verbose = %s%n", verbose); fmt.format("thread = %s%n", numOfThreads); fmt.format("penalty-discount = %f%n", penaltyDiscount); fmt.format("ignore-linear-dependence = %s%n", ignoreLinearDependence); fmt.format("depth = %d%n", depth); fmt.format("heuristic-speedup = %s%n", heuristicSpeedup); fmt.format("graphml = %s%n", graphML); fmt.format("skip-unique-var-name = %s%n", skipUniqueVarName); fmt.format("skip-non-zero-variance = %s%n", skipZeroVariance); fmt.format("out = %s%n", dirOut.getFileName().toString()); fmt.format("output-prefix = %s%n", outputPrefix); fmt.format("no-validation-output = %s%n", !validationOutput); return fmt.toString(); }
From source file:com.imellon.android.vatchecker.VatCheckerActivity.java
/** * Request info./* www . j a v a 2s . co m*/ * * @param keyphrase the keyphrase */ public void requestInfo(String keyphrase) { HttpPost httppost = new HttpPost("https://www1.gsis.gr/wsgsis/RgWsBasStoixN/RgWsBasStoixNSoapHttpPort"); try { InputStream inputStream = getResources().openRawResource(R.raw.gsisrequesttemplate); String envelope = convertInputStreamToString(inputStream); Formatter formatter = new Formatter(); formatter.format(envelope, keyphrase); envelope = formatter.toString(); StringEntity se = new StringEntity(envelope, HTTP.UTF_8); se.setContentType("text/xml"); httppost.setEntity(se); HttpEntity entity = null; HttpResponse response = sClient.execute(httppost); InputStream in = null; if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { entity = response.getEntity(); in = entity.getContent(); } String retStr = convertInputStreamToString(in); AndroidXMLParser p = new AndroidXMLParser(retStr); message = p.parse(); updateViews(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.zimbra.cs.util.ProxyConfOverride.java
public String formatLong(Object o) { Formatter f = new Formatter(); Long l = (Long) o;/*from w ww.j av a 2 s .com*/ if (l % (1024 * 1024) == 0) f.format("%dm", l / (1024 * 1024)); else if (l % 1024 == 0) f.format("%dk", l / 1024); else f.format("%d", l); return f.toString(); }
From source file:com.tulskiy.musique.system.configuration.Configuration.java
public void setFont(String key, Font value) { if (value == null) remove(key);/* w w w .j a v a 2 s .c om*/ else { String s = new Formatter().format("%s, %d, %d", value.getName(), value.getStyle(), value.getSize()) .toString(); put(key, s); } }
From source file:edu.cmu.tetrad.cli.search.FgsDiscrete.java
private static String createArgsInfo() { Formatter fmt = new Formatter(); if (dataFile != null) { fmt.format("data = %s%n", dataFile.getFileName()); }//w ww. java 2s .c om if (excludedVariableFile != null) { fmt.format("exclude-variables = %s%n", excludedVariableFile.getFileName()); } if (knowledgeFile != null) { fmt.format("knowledge = %s%n", knowledgeFile.getFileName()); } fmt.format("delimiter = %s%n", Args.getDelimiterName(delimiter)); fmt.format("verbose = %s%n", verbose); fmt.format("thread = %s%n", numOfThreads); fmt.format("structure-prior = %f%n", structurePrior); fmt.format("sample-prior = %f%n", samplePrior); fmt.format("depth = %d%n", depth); fmt.format("heuristic-speedup = %s%n", heuristicSpeedup); fmt.format("graphml = %s%n", graphML); fmt.format("skip-unique-var-name = %s%n", skipUniqueVarName); fmt.format("skip-category-limit = %s%n", skipCategoryLimit); fmt.format("out = %s%n", dirOut.getFileName().toString()); fmt.format("output-prefix = %s%n", outputPrefix); fmt.format("no-validation-output = %s%n", !validationOutput); return fmt.toString(); }