List of usage examples for java.util Formatter close
public void close()
From source file:net.sourceforge.fenixedu.domain.candidacyProcess.Formation.java
public void exportValues(StringBuilder result) { Formatter formatter = new Formatter(result); formatter.format("\n%s:\n", BundleUtil.getString(Bundle.CANDIDATE, "title.other.academic.titles")); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.other.academic.titles.program.name"), getDesignation());//from www .ja v a 2 s .c om formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.other.academic.titles.institution"), getInstitution().getName()); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.other.academic.titles.conclusion.date"), StringUtils.isEmpty(getYear()) ? StringUtils.EMPTY : getYear()); formatter.format("%s: %s\n", BundleUtil.getString(Bundle.CANDIDATE, "label.other.academic.titles.conclusion.grade"), StringUtils.isEmpty(getConclusionGrade()) ? StringUtils.EMPTY : getConclusionGrade()); formatter.close(); }
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 {/*from w w w . j a v a 2s . c om*/ 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(); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.CFLibXmlUtil.java
public static String formatTZTimestamp(Calendar cal) { final String S_ProcName = "formatTZTimestamp"; if (cal == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(CFLibXmlUtil.class, S_ProcName, 1, "cal"); }// w w w . jav a 2 s . c om StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", cal.get(Calendar.YEAR)); buff.append('-'); fmt.format("%1$02d", cal.get(Calendar.MONTH) + 1); buff.append('-'); fmt.format("%1$02d", cal.get(Calendar.DAY_OF_MONTH)); buff.append('T'); fmt.format("%1$02d", cal.get(Calendar.HOUR_OF_DAY)); buff.append(':'); fmt.format("%1$02d", cal.get(Calendar.MINUTE)); buff.append(':'); fmt.format("%1$02d", cal.get(Calendar.SECOND)); int tzoff = cal.getTimeZone().getRawOffset() / 60000; if (tzoff < 0) { tzoff = 0 - tzoff; buff.append('-'); } else { buff.append('+'); } int tzhour = tzoff / 60; int tzmin = tzoff % 60; if (tzhour > 12) { fmt.close(); throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(CFLibXmlUtil.class, S_ProcName, 0, "tzhour", tzhour); } fmt.format("%1$02d", tzhour); buff.append(':'); fmt.format("%1$02d", tzmin); String retval = buff.toString(); fmt.close(); return (retval); }
From source file:edu.stanford.muse.index.EmailDocument.java
/** used mostly as a debug routine */ public String getHeader() { StringBuilder sb = new StringBuilder(); sb.append("Folder: " + folderName + "\n"); StringBuilder timeSB = new StringBuilder(); Formatter formatter = new Formatter(timeSB); if (date != null) { Calendar c = new GregorianCalendar(); c.setTime(date);/* w ww . j av a 2 s.c om*/ formatter.format("%02d:%02d", c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE)); sb.append("Date: " + c.get(Calendar.DATE) + " " + CalendarUtil.getDisplayMonth(c) + " " + c.get(Calendar.YEAR) + " " + timeSB + "\n"); } formatter.close(); sb.append("From: " + getFromString() + "\n"); sb.append("To: " + getToString() + "\n"); String cc = getCcString(); if (!Util.nullOrEmpty(cc)) sb.append("Cc: " + cc + "\n"); String bcc = getBccString(); if (!Util.nullOrEmpty(bcc)) sb.append("Bcc: " + bcc + "\n"); if (description == null) description = "<None>"; sb.append("Subject: " + description + "\n"); if (messageID != null) sb.append("Message-ID: " + messageID + "\n"); sb.append("\n"); return sb.toString(); }
From source file:org.openecomp.sdc.common.config.EcompErrorLogUtil.java
public static void logEcompError(EcompErrorName ecompErrorName, EcompErrorInfo ecompErrorInfo, String ecompErrorContext, String... ecompDescriptionParams) { if (ecompErrorInfo != null) { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); try {/* w w w . j ava2 s. c o m*/ String description = ecompErrorInfo.getDescription(); String severityStr = ecompErrorInfo.getSeverity(); EcompErrorConfiguration.EcompErrorSeverity severity = EcompErrorSeverity.ERROR; // Since there is no FATAL log level, this is how we distinguish // the FATAL errors if (severityStr.equals(EcompErrorConfiguration.EcompErrorSeverity.FATAL.name())) { description = FATAL_ERROR_PREFIX + description; severity = EcompErrorSeverity.FATAL; } else if (severityStr.equals(EcompErrorConfiguration.EcompErrorSeverity.WARN.name())) { severity = EcompErrorSeverity.WARN; } else if (severityStr.equals(EcompErrorConfiguration.EcompErrorSeverity.INFO.name())) { severity = EcompErrorSeverity.INFO; } MDC.put("alarmSeverity", ecompErrorInfo.getAlarmSeverity()); // else it stays ERROR formatter.format(ECOMP_ERROR_TMPL, ecompErrorInfo.getType(), ecompErrorName.name(), ecompErrorInfo.getCode(), ecompErrorContext, description); switch (severity) { case INFO: log.info(formatter.toString()); break; case WARN: log.warn(formatter.toString()); break; case ERROR: log.error(formatter.toString()); break; case FATAL: // same as ERROR for now, might be additional logic later.. log.error(formatter.toString()); break; default: break; } } finally { formatter.close(); MDC.remove("alarmSeverity"); } } }
From source file:edu.uga.cs.fluxbuster.features.FeatureCalculator.java
/** * Retrieves the number of dns queries per domain for each cluster * generated on a specific run date.//from w w w.j a va 2 s . c o m * * @param log_date the run date * @return a table of values where the keys are cluster ids and the values * are the queries per domain value * @throws SQLException if there is an error retrieving the queries * per domain values */ private Hashtable<Integer, Double> getQueriesPerDomain(Date log_date) throws SQLException { Hashtable<Integer, Double> retval = new Hashtable<Integer, Double>(); StringBuffer querybuf = new StringBuffer(); Formatter formatter = new Formatter(querybuf); formatter.format(properties.getProperty(PREVCLUSTER_QUERY3KEY), df.format(log_date)); ResultSet rs = null; try { rs = dbi.executeQueryWithResult(querybuf.toString()); while (rs.next()) { retval.put(rs.getInt(1), rs.getDouble(2)); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error(e); } } finally { if (rs != null && !rs.isClosed()) { rs.close(); } formatter.close(); } return retval; }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlSchema.java
public static String getQuotedTimeString(Calendar val) { if (val == null) { return ("null"); } else {//from ww w. ja v a2 s. c o m StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$02d", val.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", val.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:edu.stanford.muse.index.EmailDocument.java
public String getSignature() { StringBuilder sb = new StringBuilder(); StringBuilder timeSB = new StringBuilder(); Formatter formatter = new Formatter(timeSB); if (this.date != null) { GregorianCalendar cc = new GregorianCalendar(); cc.setTime(this.date); formatter.format("%02d:%02d", new Object[] { Integer.valueOf(cc.get(11)), Integer.valueOf(cc.get(12)) }); sb.append("Date: " + cc.get(5) + " " + CalendarUtil.getDisplayMonth(cc) + " " + cc.get(1) + " " + timeSB + "\n"); }/*from w w w .java 2 s . com*/ formatter.close(); sb.append("From: " + this.getFromString() + "\n"); sb.append("To: " + this.getToString() + "\n"); String cc1 = this.getCcString(); if (!Util.nullOrEmpty(cc1)) { sb.append("Cc: " + cc1 + "\n"); } String bcc = this.getBccString(); if (!Util.nullOrEmpty(bcc)) { sb.append("Bcc: " + bcc + "\n"); } if (this.description == null) { this.description = "<None>"; } sb.append("Subject: " + this.description + "\n"); sb.append("\n"); return sb.toString(); }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccPgSql.CFAccPgSqlSchema.java
public static String getQuotedDateString(Calendar val) { if (val == null) { return ("null"); } else {// w w w .j av a 2 s . c om StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", val.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", val.get(Calendar.DAY_OF_MONTH)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:org.kalypso.kalypsomodel1d2d.conv.Control1D2DConverterSWAN.java
public void writeControlFile(final OutputStream outputStream) throws IOException { Formatter formatter = null; try {//from w ww . ja v a2 s. c o m // REMARK: Made a central formatter with US locale (causing decimal point to be '.'), // so no local parameter for each format is needed any more . formatter = new Formatter(outputStream, Charset.defaultCharset().name(), Locale.US); writeInputControlFile(formatter); FormatterUtils.checkIoException(formatter); } finally { if (formatter != null) { // REMARK: do not check io-exception here, else other exception would be hidden by this on formatter.close(); } } }