List of usage examples for java.util Formatter Formatter
public Formatter(OutputStream os)
From source file:com.itemanalysis.jmetrik.stats.irt.linking.CommonItemSummaryStatistics.java
public String printItemSummary() { StringBuilder sb = new StringBuilder(); Formatter f = new Formatter(sb); f.format("%n"); f.format("%64s", " ITEM SUMMARY STATISTICS "); f.format("%n"); f.format("%64s", "================================================================"); f.format("%n"); f.format("%-15s", " Form"); f.format("%-17s", "Parameter"); f.format("%-17s", " Mean"); f.format("%-15s", "S.D."); f.format("%n"); f.format("%64s", "----------------------------------------------------------------"); f.format("%n"); f.format("%-14s", " X (From)"); f.format("%-17s", " Discrimination"); f.format("%10.6f", xAMean.getResult()); f.format("%6s", " "); f.format("%10.6f", xASd.getResult()); f.format("%n"); f.format("%-14s", " "); f.format("%-17s", " Difficulty"); f.format("%10.6f", xBMean.getResult()); f.format("%6s", " "); f.format("%10.6f", xBSd.getResult()); f.format("%n"); f.format("%-14s", " "); f.format("%-17s", " Guessing"); f.format("%10.6f", xCMean.getResult()); f.format("%6s", " "); f.format("%10.6f", xCSd.getResult()); f.format("%n"); f.format("%64s", " "); f.format("%n"); f.format("%-14s", " Y (To)"); f.format("%-17s", " Discrimination"); f.format("%10.6f", yAMean.getResult()); f.format("%6s", " "); f.format("%10.6f", yASd.getResult()); f.format("%n"); f.format("%-14s", " "); f.format("%-17s", " Difficulty"); f.format("%10.6f", yBMean.getResult()); f.format("%6s", " "); f.format("%10.6f", yBSd.getResult()); f.format("%n"); f.format("%-14s", " "); f.format("%-17s", " Guessing"); f.format("%10.6f", yCMean.getResult()); f.format("%6s", " "); f.format("%10.6f", yCSd.getResult()); f.format("%n"); f.format("%64s", "================================================================"); f.format("%n"); f.format("%n"); return f.toString(); }
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.over23.Over23IndividualCandidacy.java
@Override public void exportValues(StringBuilder result) { super.exportValues(result); Formatter formatter = new Formatter(result); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.over23.languages.read"), StringUtils.isEmpty(getLanguagesRead()) ? StringUtils.EMPTY : getLanguagesRead()); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.over23.languages.write"), StringUtils.isEmpty(getLanguagesWrite()) ? StringUtils.EMPTY : getLanguagesWrite()); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.over23.languages.speak"), StringUtils.isEmpty(getLanguagesSpeak()) ? StringUtils.EMPTY : getLanguagesSpeak()); formatter.close();//w w w . j ava 2s .co m }
From source file:nl.basjes.parse.useragent.UserAgentAnalyzer.java
public void loadResources(String resourceString, boolean showMatcherStats) { LOG.info("Loading from: \"{}\"", resourceString); flattener = new UserAgentTreeFlattener(this); yaml = new Yaml(); Map<String, Resource> resources = new TreeMap<>(); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try {/*from www .ja v a 2 s. c o m*/ Resource[] resourceArray = resolver.getResources(resourceString); for (Resource resource : resourceArray) { resources.put(resource.getFilename(), resource); } } catch (IOException e) { e.printStackTrace(); return; } doingOnlyASingleTest = false; int maxFilenameLength = 0; if (resources.isEmpty()) { throw new InvalidParserConfigurationException("Unable to find ANY config files"); } for (Map.Entry<String, Resource> resourceEntry : resources.entrySet()) { try { Resource resource = resourceEntry.getValue(); String filename = resource.getFilename(); maxFilenameLength = Math.max(maxFilenameLength, filename.length()); loadResource(resource.getInputStream(), filename); } catch (IOException e) { e.printStackTrace(); } } LOG.info("Loaded {} files", resources.size()); if (lookups != null && !lookups.isEmpty()) { // All compares are done in a case insensitive way. So we lowercase ALL keys of the lookups beforehand. Map<String, Map<String, String>> cleanedLookups = new HashMap<>(lookups.size()); for (Map.Entry<String, Map<String, String>> lookupsEntry : lookups.entrySet()) { Map<String, String> cleanedLookup = new HashMap<>(lookupsEntry.getValue().size()); for (Map.Entry<String, String> entry : lookupsEntry.getValue().entrySet()) { cleanedLookup.put(entry.getKey().toLowerCase(), entry.getValue()); } cleanedLookups.put(lookupsEntry.getKey(), cleanedLookup); } lookups = cleanedLookups; } LOG.info("Building all matchers"); int totalNumberOfMatchers = 0; int skippedMatchers = 0; if (matcherConfigs != null) { long fullStart = System.nanoTime(); for (Map.Entry<String, Resource> resourceEntry : resources.entrySet()) { Resource resource = resourceEntry.getValue(); String configFilename = resource.getFilename(); List<Map<String, List<String>>> matcherConfig = matcherConfigs.get(configFilename); if (matcherConfig == null) { continue; // No matchers in this file (probably only lookups and/or tests) } long start = System.nanoTime(); int startSize = informMatcherActions.size(); for (Map<String, List<String>> map : matcherConfig) { try { allMatchers.add(new Matcher(this, lookups, wantedFieldNames, map)); totalNumberOfMatchers++; } catch (UselessMatcherException ume) { skippedMatchers++; } } long stop = System.nanoTime(); int stopSize = informMatcherActions.size(); if (showMatcherStats) { Formatter msg = new Formatter(Locale.ENGLISH); msg.format( "Building %4d matchers from %-" + maxFilenameLength + "s took %5d msec resulted in %8d extra hashmap entries", matcherConfig.size(), configFilename, (stop - start) / 1000000, stopSize - startSize); LOG.info(msg.toString()); } } long fullStop = System.nanoTime(); Formatter msg = new Formatter(Locale.ENGLISH); msg.format( "Building %4d (dropped %4d) matchers from %4d files took %5d msec resulted in %8d hashmap entries", totalNumberOfMatchers, skippedMatchers, matcherConfigs.size(), (fullStop - fullStart) / 1000000, informMatcherActions.size()); LOG.info(msg.toString()); } LOG.info("Analyzer stats"); LOG.info("Lookups : {}", (lookups == null) ? 0 : lookups.size()); LOG.info("Matchers : {} (total:{} ; dropped: {})", allMatchers.size(), totalNumberOfMatchers, skippedMatchers); LOG.info("Hashmap size : {}", informMatcherActions.size()); LOG.info("Testcases : {}", testCases.size()); // LOG.info("All possible field names:"); // int count = 1; // for (String fieldName : getAllPossibleFieldNames()) { // LOG.info("- {}: {}", count++, fieldName); // } }
From source file:com.dubsar_dictionary.Dubsar.model.Sense.java
@Override public void parseData(Object jsonResponse) throws JSONException { JSONArray response = (JSONArray) jsonResponse; JSONArray _word = response.getJSONArray(1); JSONArray _synset = response.getJSONArray(2); int wordId = _word.getInt(0); String wordName = _word.getString(1); String wordPos = _word.getString(2); int synsetId = _synset.getInt(0); mGloss = new String(_synset.getString(1)); setPos(wordPos);// w w w. j a va 2 s. co m mWord = new Word(wordId, wordName, getPartOfSpeech()); mName = new String(wordName); mSynset = new Synset(synsetId, mGloss, getPartOfSpeech()); mIsWeakWordReference = mIsWeakSynsetReference = false; mWordReference = null; mSynsetReference = null; setLexname(response.getString(3)); getSynset().setLexname(getLexname()); if (!response.isNull(4)) { setMarker(response.getString(4)); } setFreqCnt(response.getInt(5)); JSONArray _synonyms = response.getJSONArray(6); mSynonyms = new ArrayList<Sense>(_synonyms.length()); int j; int senseId; String senseName; for (j = 0; j < _synonyms.length(); ++j) { JSONArray _synonym = _synonyms.getJSONArray(j); senseId = _synonym.getInt(0); senseName = _synonym.getString(1); String marker = null; if (!_synonym.isNull(2)) { marker = _synonym.getString(2); } int freqCnt = _synonym.getInt(3); Sense synonym = new Sense(senseId, senseName, getSynset()); synonym.setMarker(marker); synonym.setFreqCnt(freqCnt); mSynonyms.add(synonym); } JSONArray _verbFrames = response.getJSONArray(7); mVerbFrames = new ArrayList<String>(_verbFrames.length()); for (j = 0; j < _verbFrames.length(); ++j) { String frame = _verbFrames.getString(j); // Replace %s in verb frames with the name of the word // TODO: Make that a bold span. StringBuffer buffer = new StringBuffer(); Formatter formatter = new Formatter(buffer); formatter.format(frame, new Object[] { getName() }); formatter.close(); mVerbFrames.add(buffer.toString()); } JSONArray _samples = response.getJSONArray(8); mSamples = new ArrayList<String>(_samples.length()); for (j = 0; j < _samples.length(); ++j) { mSamples.add(_samples.getString(j)); } parsePointers(response.getJSONArray(9)); }
From source file:fr.inrialpes.exmo.align.cli.ExtGroupEval.java
public void printHTML(Vector<Vector<Object>> result, PrintStream writer) { // variables for computing iterative harmonic means int expected = 0; // expected so far int foundVect[]; // found so far double symVect[]; // symmetric similarity double effVect[]; // effort-based similarity double precOrVect[]; // precision-oriented similarity double recOrVect[]; // recall-oriented similarity fsize = format.length();//from www. jav a2 s. c o m try { Formatter formatter = new Formatter(writer); // Print the header writer.println("<html><head></head><body>"); writer.println("<table border='2' frame='sides' rules='groups'>"); writer.println("<colgroup align='center' />"); // for each algo <td spancol='2'>name</td> for (String m : listAlgo) { writer.println("<colgroup align='center' span='" + 2 * fsize + "' />"); } // For each file do a writer.println("<thead valign='top'><tr><th>algo</th>"); // for each algo <td spancol='2'>name</td> for (String m : listAlgo) { writer.println("<th colspan='" + ((2 * fsize)) + "'>" + m + "</th>"); } writer.println("</tr></thead><tbody><tr><td>test</td>"); // for each algo <td>Prec.</td><td>Rec.</td> for (String m : listAlgo) { for (int i = 0; i < fsize; i++) { if (format.charAt(i) == 's') { writer.println("<td colspan='2'><center>Symmetric</center></td>"); } else if (format.charAt(i) == 'e') { writer.println("<td colspan='2'><center>Effort</center></td>"); } else if (format.charAt(i) == 'p') { writer.println("<td colspan='2'><center>Prec. orient.</center></td>"); } else if (format.charAt(i) == 'r') { writer.println("<td colspan='2'><center>Rec. orient.</center></td>"); } } //writer.println("<td>Prec.</td><td>Rec.</td>"); } writer.println("</tr></tbody><tbody>"); foundVect = new int[size]; symVect = new double[size]; effVect = new double[size]; precOrVect = new double[size]; recOrVect = new double[size]; for (int k = size - 1; k >= 0; k--) { foundVect[k] = 0; symVect[k] = 0.; effVect[k] = 0.; precOrVect[k] = 0.; recOrVect[k] = 0.; } // </tr> // For each directory <tr> boolean colored = false; for (Vector<Object> test : result) { int nexpected = -1; if (colored == true && color != null) { colored = false; writer.println("<tr bgcolor=\"" + color + "\">"); } else { colored = true; writer.println("<tr>"); } ; // Print the directory <td>bla</td> writer.println("<td>" + (String) test.get(0) + "</td>"); // For each record print the values <td>bla</td> Enumeration<Object> f = test.elements(); f.nextElement(); for (int k = 0; f.hasMoreElements(); k++) { ExtPREvaluator eval = (ExtPREvaluator) f.nextElement(); if (eval != null) { // iterative H-means computation if (nexpected == -1) { nexpected = eval.getExpected(); expected += nexpected; } // If foundVect is -1 then results are invalid if (foundVect[k] != -1) foundVect[k] += eval.getFound(); for (int i = 0; i < fsize; i++) { writer.print("<td>"); if (format.charAt(i) == 's') { formatter.format("%1.2f", eval.getSymPrecision()); writer.print("</td><td>"); formatter.format("%1.2f", eval.getSymRecall()); symVect[k] += eval.getSymSimilarity(); } else if (format.charAt(i) == 'e') { formatter.format("%1.2f", eval.getEffPrecision()); writer.print("</td><td>"); formatter.format("%1.2f", eval.getEffRecall()); effVect[k] += eval.getEffSimilarity(); } else if (format.charAt(i) == 'p') { formatter.format("%1.2f", eval.getPrecisionOrientedPrecision()); writer.print("</td><td>"); formatter.format("%1.2f", eval.getPrecisionOrientedRecall()); precOrVect[k] += eval.getPrecisionOrientedSimilarity(); } else if (format.charAt(i) == 'r') { formatter.format("%1.2f", eval.getRecallOrientedPrecision()); writer.print("</td><td>"); formatter.format("%1.2f", eval.getRecallOrientedRecall()); recOrVect[k] += eval.getRecallOrientedSimilarity(); } writer.print("</td>"); } } else { for (int i = 0; i < fsize; i++) writer.print("<td>n/a</td>"); } } writer.println("</tr>"); } writer.print("<tr bgcolor=\"yellow\"><td>H-mean</td>"); int k = 0; for (String m : listAlgo) { if (foundVect[k] != -1) { for (int i = 0; i < fsize; i++) { writer.print("<td>"); if (format.charAt(i) == 's') { formatter.format("%1.2f", symVect[k] / foundVect[k]); writer.print("</td><td>"); formatter.format("%1.2f", symVect[k] / expected); } else if (format.charAt(i) == 'e') { formatter.format("%1.2f", effVect[k] / foundVect[k]); writer.print("</td><td>"); formatter.format("%1.2f", effVect[k] / expected); } else if (format.charAt(i) == 'p') { formatter.format("%1.2f", precOrVect[k] / foundVect[k]); writer.print("</td><td>"); formatter.format("%1.2f", precOrVect[k] / expected); } else if (format.charAt(i) == 'r') { formatter.format("%1.2f", recOrVect[k] / foundVect[k]); writer.print("</td><td>"); formatter.format("%1.2f", recOrVect[k] / expected); } writer.println("</td>"); } } else { writer.println("<td colspan='2'><center>Error</center></td>"); } //}; k++; } writer.println("</tr>"); writer.println("</tbody></table>"); writer.println("<p><small>n/a: result alignment not provided or not readable<br />"); writer.println("NaN: division per zero, likely due to empty alignent.</small></p>"); writer.println("</body></html>"); } catch (Exception ex) { logger.debug("IGNORED Exception", ex); } finally { writer.flush(); writer.close(); } }
From source file:umontreal.ssj.charts.EmpiricalChart.java
/** * @name LaTeX-specific method/*w ww . j av a 2 s.co m*/ * @{ */ public String toLatex(double width, double height) { double xunit, yunit; double[] save = new double[4]; if (dataset.getSeriesCollection().getSeriesCount() == 0) throw new IllegalArgumentException("Empty chart"); //Calcul des parametres d'echelle et de decalage double XScale = computeXScale(XAxis.getTwinAxisPosition()); double YScale = computeYScale(YAxis.getTwinAxisPosition()); xunit = width / ((Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) * XScale) - (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) * XScale)); //taille d'une unite en x et en cm dans l'objet "tikzpicture" yunit = height / ((Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) * YScale) - (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) * YScale)); //taille d'une unite en y et en cm dans l'objet "tikzpicture" Formatter formatter = new Formatter(Locale.US); /*Entete du document*/ if (latexDocFlag) { formatter.format("\\documentclass[12pt]{article}%n%n"); formatter.format("\\usepackage{tikz}%n\\usetikzlibrary{plotmarks}%n\\begin{document}%n%n"); } if (chart.getTitle() != null) formatter.format("%% PGF/TikZ picture from SSJ : %s%n", chart.getTitle().getText()); else formatter.format("%% PGF/TikZ picture from SSJ %n"); formatter.format("%% XScale = %s, YScale = %s, XShift = %s, YShift = %s%n", XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition()); formatter.format("%% Therefore, thisFileXValue = (originalSeriesXValue+XShift)*XScale%n"); formatter.format("%% and thisFileYValue = (originalSeriesYValue+YShift)*YScale%n%n"); if (chart.getTitle() != null) formatter.format("\\begin{figure}%n"); formatter.format("\\begin{center}%n"); formatter.format("\\begin{tikzpicture}[x=%scm, y=%scm]%n", xunit, yunit); formatter.format("\\footnotesize%n"); if (grid) formatter.format("\\draw[color=lightgray] (%s, %s) grid[xstep = %s, ystep=%s] (%s, %s);%n", (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) - XAxis.getTwinAxisPosition()) * XScale, (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) - YAxis.getTwinAxisPosition()) * YScale, xstepGrid * XScale, ystepGrid * YScale, (Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) - XAxis.getTwinAxisPosition()) * XScale, (Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) - YAxis.getTwinAxisPosition()) * YScale); setTick0Flags(); formatter.format("%s", XAxis.toLatex(XScale)); formatter.format("%s", YAxis.toLatex(YScale)); formatter.format("%s", dataset.toLatex(XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition(), XAxis.getAxis().getLowerBound(), XAxis.getAxis().getUpperBound(), YAxis.getAxis().getLowerBound(), YAxis.getAxis().getUpperBound())); formatter.format("\\end{tikzpicture}%n"); formatter.format("\\end{center}%n"); if (chart.getTitle() != null) { formatter.format("\\caption{"); formatter.format(chart.getTitle().getText()); formatter.format("}%n\\end{figure}%n"); } if (latexDocFlag) formatter.format("\\end{document}%n"); return formatter.toString(); }
From source file:com.playhaven.android.req.PlayHavenRequest.java
protected static String convertToHex(byte[] in) { StringBuilder builder = new StringBuilder(in.length * 2); Formatter formatter = new Formatter(builder); for (byte inByte : in) formatter.format("%02x", inByte); return builder.toString(); }
From source file:cross.datastructures.pipeline.CommandPipeline.java
/** * Store the runtime of the last command. * * @param start wall clock start time of the command * * @param stop wall clock stop time of the command * @param cmd the command//from ww w . j a va 2 s . co m * @param workflow the current workflow */ protected void storeCommandRuntime(long start, long stop, final IFragmentCommand cmd, final IWorkflow workflow) { final float seconds = ((float) stop - start) / ((float) 1000000000); final StringBuilder sb = new StringBuilder(); final Formatter formatter = new Formatter(sb); formatter.format(CommandPipeline.NUMBERFORMAT, (seconds)); log.info("Runtime of command {}: {} sec", cmd.getClass().getSimpleName(), sb.toString()); Map<String, Object> statsMap = new HashMap<>(); statsMap.put("RUNTIME_MILLISECONDS", (double) stop - start / 1000000.f); statsMap.put("RUNTIME_SECONDS", (double) seconds); DefaultWorkflowStatisticsResult dwsr = new DefaultWorkflowStatisticsResult(); dwsr.setWorkflowElement(cmd); dwsr.setWorkflowSlot(WorkflowSlot.STATISTICS); dwsr.setStats(statsMap); workflow.append(dwsr); }
From source file:umontreal.iro.lecuyer.charts.EmpiricalChart.java
public String toLatex(double width, double height) { double xunit, yunit; double[] save = new double[4]; if (dataset.getSeriesCollection().getSeriesCount() == 0) throw new IllegalArgumentException("Empty chart"); //Calcul des parametres d'echelle et de decalage double XScale = computeXScale(XAxis.getTwinAxisPosition()); double YScale = computeYScale(YAxis.getTwinAxisPosition()); xunit = width / ((Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) * XScale)//from www. jav a 2 s .c om - (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) * XScale)); //taille d'une unite en x et en cm dans l'objet "tikzpicture" yunit = height / ((Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) * YScale) - (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) * YScale)); //taille d'une unite en y et en cm dans l'objet "tikzpicture" Formatter formatter = new Formatter(Locale.US); /*Entete du document*/ if (latexDocFlag) { formatter.format("\\documentclass[12pt]{article}%n%n"); formatter.format("\\usepackage{tikz}%n\\usetikzlibrary{plotmarks}%n\\begin{document}%n%n"); } if (chart.getTitle() != null) formatter.format("%% PGF/TikZ picture from SSJ : %s%n", chart.getTitle().getText()); else formatter.format("%% PGF/TikZ picture from SSJ %n"); formatter.format("%% XScale = %s, YScale = %s, XShift = %s, YShift = %s%n", XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition()); formatter.format("%% Therefore, thisFileXValue = (originalSeriesXValue+XShift)*XScale%n"); formatter.format("%% and thisFileYValue = (originalSeriesYValue+YShift)*YScale%n%n"); if (chart.getTitle() != null) formatter.format("\\begin{figure}%n"); formatter.format("\\begin{center}%n"); formatter.format("\\begin{tikzpicture}[x=%scm, y=%scm]%n", xunit, yunit); formatter.format("\\footnotesize%n"); if (grid) formatter.format("\\draw[color=lightgray] (%s, %s) grid[xstep = %s, ystep=%s] (%s, %s);%n", (Math.min(XAxis.getAxis().getRange().getLowerBound(), XAxis.getTwinAxisPosition()) - XAxis.getTwinAxisPosition()) * XScale, (Math.min(YAxis.getAxis().getRange().getLowerBound(), YAxis.getTwinAxisPosition()) - YAxis.getTwinAxisPosition()) * YScale, xstepGrid * XScale, ystepGrid * YScale, (Math.max(XAxis.getAxis().getRange().getUpperBound(), XAxis.getTwinAxisPosition()) - XAxis.getTwinAxisPosition()) * XScale, (Math.max(YAxis.getAxis().getRange().getUpperBound(), YAxis.getTwinAxisPosition()) - YAxis.getTwinAxisPosition()) * YScale); setTick0Flags(); formatter.format("%s", XAxis.toLatex(XScale)); formatter.format("%s", YAxis.toLatex(YScale)); formatter.format("%s", dataset.toLatex(XScale, YScale, XAxis.getTwinAxisPosition(), YAxis.getTwinAxisPosition(), XAxis.getAxis().getLowerBound(), XAxis.getAxis().getUpperBound(), YAxis.getAxis().getLowerBound(), YAxis.getAxis().getUpperBound())); formatter.format("\\end{tikzpicture}%n"); formatter.format("\\end{center}%n"); if (chart.getTitle() != null) { formatter.format("\\caption{"); formatter.format(chart.getTitle().getText()); formatter.format("}%n\\end{figure}%n"); } if (latexDocFlag) formatter.format("\\end{document}%n"); return formatter.toString(); }
From source file:com.cloud.utils.net.NetUtils.java
public static String getMacAddress(final InetAddress address) { final StringBuffer sb = new StringBuffer(); final Formatter formatter = new Formatter(sb); try {/*ww w.j ava2 s . c o m*/ final NetworkInterface ni = NetworkInterface.getByInetAddress(address); final byte[] mac = ni.getHardwareAddress(); for (int i = 0; i < mac.length; i++) { formatter.format("%02X%s", mac[i], i < mac.length - 1 ? ":" : ""); } } catch (final SocketException e) { s_logger.error("SocketException when trying to retrieve MAC address", e); } finally { formatter.close(); } return sb.toString(); }