List of usage examples for java.util Formatter close
public void close()
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static String getTZTimeString(Calendar val) { if (val == null) { return ("null"); } else {//from ww w .ja v a 2s .co m Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static String getTZTimestampString(Calendar val) { if (val == null) { return ("null"); } else {// w w w . j a v a2s. com Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static String getQuotedTZDateString(Calendar val) { if (val == null) { return ("null"); } else {/*w w w . ja va 2 s. c o m*/ Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static String getQuotedTZTimeString(Calendar val) { if (val == null) { return ("null"); } else {/*from w w w. j av a 2s . co m*/ Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static String getQuotedTZTimestampString(Calendar val) { if (val == null) { return ("null"); } else {/* w w w. j a v a2s . c om*/ Calendar db = CFLibDbUtil.getDbServerCalendar(val); StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static String getTimestampString(Calendar val) { if (val == null) { return ("null"); } else {//from w ww .j a v a2 s . c o m StringBuffer buff = new StringBuffer(); Formatter fmt = new Formatter(buff); Calendar db = CFLibDbUtil.getDbServerCalendar(val); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); fmt.close(); return (buff.toString()); } }
From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccMSSql.CFAccMSSqlSchema.java
public static String getQuotedTimestampString(Calendar val) { if (val == null) { return ("null"); } else {/*from w w w . j av a 2s. c o m*/ StringBuffer buff = new StringBuffer("'"); Formatter fmt = new Formatter(buff); Calendar db = CFLibDbUtil.getDbServerCalendar(val); fmt.format("%1$04d", db.get(Calendar.YEAR)); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.MONTH) + 1); buff.append("-"); fmt.format("%1$02d", db.get(Calendar.DAY_OF_MONTH)); buff.append(" "); fmt.format("%1$02d", db.get(Calendar.HOUR_OF_DAY)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.MINUTE)); buff.append(":"); fmt.format("%1$02d", db.get(Calendar.SECOND)); buff.append("'"); fmt.close(); return (buff.toString()); } }
From source file:org.openecomp.sdc.common.config.EcompErrorLogUtil.java
public static void logEcompError(String ecompErrorContext, EcompErrorEnum ecompErrorEnum, boolean logMissingParams, String... ecompDescriptionParams) { StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); try {/*from w w w.j av a 2 s . co m*/ String description = ecompErrorEnum.getEcompErrorCode().getDescription(); Either<String, Boolean> setDescriptionParamsResult = setDescriptionParams(ecompErrorEnum, ecompDescriptionParams); if (setDescriptionParamsResult.isLeft()) { description = setDescriptionParamsResult.left().value(); } else { EcompErrorEnum mismatchErrorEnum = EcompErrorEnum.EcompMismatchParam; if (logMissingParams == true) { logEcompError("logEcompError", mismatchErrorEnum, false, ecompErrorEnum.name().toString()); return; } else { log.info("Failed to log the error code " + mismatchErrorEnum); return; } } EcompClassification classification = ecompErrorEnum.getClassification(); EcompErrorConfiguration.EcompErrorSeverity severity = EcompErrorSeverity.ERROR; // Since there is no FATAL log level, this is how we distinguish the // FATAL errors if (classification == EcompClassification.FATAL) { description = FATAL_ERROR_PREFIX + description; severity = EcompErrorSeverity.FATAL; } else if (classification == EcompClassification.WARNING) { severity = EcompErrorSeverity.WARN; } else if (classification == EcompClassification.INFORMATION) { severity = EcompErrorSeverity.INFO; } String eCode = createEcode(ecompErrorEnum); MDC.put("alarmSeverity", ecompErrorEnum.alarmSeverity.name()); // else it stays ERROR formatter.format(ECOMP_ERROR_TMPL, ecompErrorEnum.geteType(), ecompErrorEnum.name(), eCode, 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:org.getobjects.appserver.core.WOApplication.java
/** * This method is called when 'info' is enabled in the profile logger. * * @param _rq - the WORequest/* w w w.j ava 2s . c o m*/ * @param _rqId - the numeric ID of the request (counter) * @param _r - the generated WOResponse */ protected void logRequestEnd(WORequest _rq, int _rqId, WOResponse _r) { final StringBuilder sb = new StringBuilder(512); sb.append("WOApp["); sb.append(_rqId); sb.append("] "); if (_r != null) { String s; final int status = _r.status(); sb.append(status); if ((s = _r.headerForKey("content-length")) != null) { sb.append(" "); sb.append(s); } else if (!_r.isStreaming()) { int len = _r.content().length; sb.append(" len="); sb.append(len); } if ((s = _r.headerForKey("content-type")) != null) { sb.append(' '); sb.append(s); } final Collection<WOCookie> cookies = _r.cookies(); if (cookies != null && cookies.size() > 0) { sb.append(" C["); WOCookie.addCookieInfo(cookies, sb); sb.append("]"); } if (status == 302 && (s = _r.headerForKey("location")) != null) { sb.append(" 302["); sb.append(s); sb.append(']'); } } else sb.append("no response"); if (_rq != null) { final double duration = _rq.requestDurationSinceStart(); if (duration > 0.0) { // TBD: are there more efficient ways to do this? (apparently there is // no way to cache the parsed format?) Formatter formatter = new Formatter(sb, Locale.US); formatter.format(" (%.3fs)", duration); formatter.close(); // didn't know that ;-) } } profile.info(sb.toString()); }
From source file:org.efaps.esjp.accounting.util.data.ImportDetails.java
/** * */// w ww. j a v a2s .c o m protected Map<String, Instance> checkDocs(final File _file, final Type _type) throws IOException, EFapsException { final CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(_file), "UTF-8")); final List<String[]> entries = reader.readAll(); reader.close(); final Map<String, Instance> ret = new HashMap<>(); entries.remove(0); String docNumber = ""; int i = 1; for (final String[] row : entries) { i++; final String docNumberTmp = row[0]; if (!docNumber.equals(docNumberTmp)) { docNumber = docNumberTmp; ImportDetails.LOG.info("Trying to read Document '{}' - Line: {}", docNumber, i); final String[] docSplit = docNumber.split("-"); if (docSplit.length != 2) { ImportDetails.LOG.warn( "Document '{}' - Line: {} has no '-' to distinguish SerialNumber and No.", docNumber, i); } else { final String serialNo = docSplit[0]; final String docNo = docSplit[1]; try { final int serial = Integer.parseInt(serialNo.trim().replaceAll("\\D", "")); final int no = Integer.parseInt(docNo.trim().replaceAll("\\D", "")); final Formatter criteria = new Formatter(); criteria.format("%03d-%06d", serial, no); ImportDetails.LOG.info("Applying Criteria: '{}'", criteria); final QueryBuilder queryBldr = new QueryBuilder(_type); queryBldr.addWhereAttrEqValue(CIERP.DocumentAbstract.Name, criteria.toString()); final InstanceQuery query = queryBldr.getQuery(); query.executeWithoutAccessCheck(); if (query.next()) { ImportDetails.LOG.info("Found Document: '{}'", query.getCurrentValue()); ret.put(criteria.toString(), query.getCurrentValue()); if (query.next()) { ImportDetails.LOG.error("Found duplicated Document: '{}'", query.getCurrentValue()); } } else { ImportDetails.LOG.error("No Document found for : '{}' - Line: {}", docNumber, i); } criteria.close(); } catch (final NumberFormatException e) { ImportDetails.LOG.error("wrong format '{}'", docNumber); } } } } return ret; }