List of usage examples for java.lang StringBuffer setLength
@Override public synchronized void setLength(int newLength)
From source file:com.pureinfo.srm.outlay.model.impl.ZjuOutlayCardCodeGenerator.java
public String getCodePrefix(Project _prj, String _sOutlayType, String sOrgCode) throws PureException { String[] fixes = getFixes(_sOutlayType); Organization college = _prj.getCollege(); Date date = _prj.getStartDate(); if (date == null) date = new Date(); String sDateString = dateFormatter.format(date); StringBuffer sbuff = new StringBuffer(); try {/*from w w w . j a v a2s .c o m*/ sbuff.append(fixes[0]); if (college != null) { sbuff.append(college.getCode()); } sbuff.append(sOrgCode); sbuff.append(fixes[1]); sbuff.append(sDateString); return sbuff.toString(); } finally { sbuff.setLength(0); } }
From source file:com.pureinfo.srm.contract.model.impl.ZjuContractSidGeneratorImpl.java
public String generateCode(Project _prj) throws PureException { StringBuffer sbuff = new StringBuffer(); IIDTableMgr mgr = (IIDTableMgr) ArkContentHelper.getContentMgrOf(IDTable.class); String sIdName = getCodePrefix(_prj); try {//from w w w.j ava 2 s . com sbuff.append(sIdName); String sFlowid = NUMBER_FORMATTER.format(mgr.getIdValue(sIdName)); sbuff.append(sFlowid); return sbuff.toString(); } finally { sbuff.setLength(0); } }
From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.HelpMojo.java
/** * Adds the specified line to the output sequence, performing line wrapping if necessary. * * @param lines The sequence of display lines, must not be <code>null</code>. * @param line The line to add, must not be <code>null</code>. * @param indentSize The size of each indentation, must not be negative. * @param lineLength The length of the line, must not be negative. *///from w w w .j ava 2 s. c o m private static void toLines(List lines, String line, int indentSize, int lineLength) { int lineIndent = getIndentLevel(line); StringBuffer buf = new StringBuffer(256); String[] tokens = line.split(" +"); for (int i = 0; i < tokens.length; i++) { String token = tokens[i]; if (i > 0) { if (buf.length() + token.length() >= lineLength) { lines.add(buf.toString()); buf.setLength(0); buf.append(repeat(" ", lineIndent * indentSize)); } else { buf.append(' '); } } for (int j = 0; j < token.length(); j++) { char c = token.charAt(j); if (c == '\t') { buf.append(repeat(" ", indentSize - buf.length() % indentSize)); } else if (c == '\u00A0') { buf.append(' '); } else { buf.append(c); } } } lines.add(buf.toString()); }
From source file:com.pureinfo.srm.project.ProjectToFinishRemindJob.java
public static String getSQL() { StringBuffer sbuff = new StringBuffer(); sbuff.append("SELECT * FROM {this} WHERE"); sbuff.append(" {this.lStatus} not in("); sbuff.append("'").append(ProjectConstants.STATUS_FINISHED).append("',"); sbuff.append("'").append(ProjectConstants.STATUS_CANCELED).append("',"); sbuff.append("'").append(ProjectConstants.STATUS_STOPED).append("',"); sbuff.append("'").append(ProjectConstants.STATUS_APPLY_FINISH_AUDIT).append("',"); sbuff.append("'").append(ProjectConstants.STATUS_APPLY_FINISH_AUDIT).append("')"); sbuff.append(" AND ("); sbuff.append("({this.finishDate}<=? AND {this.finishRemindLog}=0)");// sbuff.append(" OR "); sbuff.append("({this.finishDate}<=? AND ({this.finishRemindLog}=0 OR {this.finishRemindLog}=" + REMIND_STATUS_3MON + ") )");//1 sbuff.append(") AND {this.finishDate}>=now()");// sbuff.append(" AND {this.lPrjType}='").append(ProjectConstants.PROJECT_TYPE_V).append("'");// sbuff.append(" ORDER BY {this.finishDate}");// String sResult_ = sbuff.toString(); sbuff.setLength(0); return sResult_; }
From source file:com.ikanow.infinit.e.harvest.extraction.document.file.XmlToMetadataParser.java
/** * Parses XML and returns a new feed with the resulting HashMap as Metadata * @param reader XMLStreamReader using Stax to avoid out of memory errors * @return List of Feeds with their Metadata set */// ww w .jav a2 s. c o m public List<DocumentPojo> parseDocument(XMLStreamReader reader) throws XMLStreamException { DocumentPojo doc = new DocumentPojo(); List<DocumentPojo> docList = new ArrayList<DocumentPojo>(); boolean justIgnored = false; boolean hitIdentifier = false; while (reader.hasNext()) { int eventCode = reader.next(); switch (eventCode) { case (XMLStreamReader.START_ELEMENT): { String tagName = reader.getLocalName(); if (null == levelOneFields || levelOneFields.size() == 0) { levelOneFields = new ArrayList<String>(); levelOneFields.add(tagName); doc = new DocumentPojo(); sb.delete(0, sb.length()); justIgnored = false; } else if (levelOneFields.contains(tagName)) { sb.delete(0, sb.length()); doc = new DocumentPojo(); justIgnored = false; } else if ((null != ignoreFields) && ignoreFields.contains(tagName)) { justIgnored = true; } else { if (this.bPreserveCase) { sb.append("<").append(tagName).append(">"); } else { sb.append("<").append(tagName.toLowerCase()).append(">"); } justIgnored = false; } hitIdentifier = tagName.equalsIgnoreCase(PKElement); if (!justIgnored && (null != this.AttributePrefix)) { // otherwise ignore attributes anyway int nAttributes = reader.getAttributeCount(); StringBuffer sb2 = new StringBuffer(); for (int i = 0; i < nAttributes; ++i) { sb2.setLength(0); sb.append('<'); sb2.append(this.AttributePrefix); if (this.bPreserveCase) { sb2.append(reader.getAttributeLocalName(i).toLowerCase()); } else { sb2.append(reader.getAttributeLocalName(i)); } sb2.append('>'); sb.append(sb2); sb.append("<![CDATA[").append(reader.getAttributeValue(i).trim()).append("]]>"); sb.append("</").append(sb2); } } } break; case (XMLStreamReader.CHARACTERS): { if (reader.getText().trim().length() > 0 && justIgnored == false) sb.append("<![CDATA[").append(reader.getText().trim()).append("]]>"); if (hitIdentifier) { String tValue = reader.getText().trim(); if (null != XmlSourceName) { if (tValue.length() > 0) { doc.setUrl(XmlSourceName + tValue); } } } } break; case (XMLStreamReader.END_ELEMENT): { hitIdentifier = !reader.getLocalName().equalsIgnoreCase(PKElement); if ((null != ignoreFields) && !ignoreFields.contains(reader.getLocalName())) { if (levelOneFields.contains(reader.getLocalName())) { JSONObject json; try { json = XML.toJSONObject(sb.toString()); for (String names : JSONObject.getNames(json)) { JSONObject rec = null; JSONArray jarray = null; try { jarray = json.getJSONArray(names); doc.addToMetadata(names, handleJsonArray(jarray, false)); } catch (JSONException e) { try { rec = json.getJSONObject(names); doc.addToMetadata(names, convertJsonObjectToLinkedHashMap(rec)); } catch (JSONException e2) { try { Object[] val = { json.getString(names) }; doc.addToMetadata(names, val); } catch (JSONException e1) { e1.printStackTrace(); } } } } } catch (JSONException e) { e.printStackTrace(); } sb.delete(0, sb.length()); docList.add(doc); } else { if (this.bPreserveCase) { sb.append("</").append(reader.getLocalName()).append(">"); } else { sb.append("</").append(reader.getLocalName().toLowerCase()).append(">"); } } } } // (end case) break; } // (end switch) } return docList; }
From source file:com.yolodata.tbana.hadoop.mapred.util.CSVReader.java
protected void foundDelimiter(StringBuffer sb, List<Text> values, boolean takeDelimiterOut) throws UnsupportedEncodingException { Text text = new Text(); String val = (takeDelimiterOut) ? sb.substring(0, sb.length() - separator.length()) : sb.toString(); val = StringUtils.strip(val, "\n"); val = StringUtils.strip(val, delimiter); text.set(val); values.add(text);/*from www .j a v a 2 s . com*/ sb.setLength(0); }
From source file:FormatStorage1.IColumnDataFile.java
public void create(String fileName, IHead head, ArrayList<ArrayList<Integer>> columnprojects) throws IOException { if (columnprojects == null) { this.create(fileName, head); return;// w w w . ja v a 2 s. c o m } this.columnprojects = columnprojects; this.head = head; fieldtypes = head.fieldMap().fieldtypes(); int primaryindex = head.getPrimaryIndex(); StringBuffer sb = new StringBuffer(); for (ArrayList<Integer> cp : columnprojects) { IHead subhead = new IHead(head); subhead.setPrimaryIndex((short) -1); IFieldMap fieldMap = new IFieldMap(); sb.setLength(0); sb.append("_idx"); for (int i = 0; i < cp.size(); i++) { int c = cp.get(i); if (c == primaryindex) subhead.setPrimaryIndex(i); fieldMap.addFieldType(fieldtypes.get(c)); sb.append(c).append("_"); } subhead.setFieldMap(fieldMap); IFormatDataFile ifdf = new IFormatDataFile(conf); String subfile = fileName + sb.substring(0, sb.length() - 1); ifdf.create(subfile, subhead); this.cp2ifdfs.put(cp, ifdf); for (Integer c : cp) { this.idx2ifdfs.put(c, ifdf); } } workstatus = ConstVar.WS_Write; }
From source file:com.panet.imeta.job.entries.sql.JobEntrySQL.java
public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) { LogWriter log = LogWriter.getInstance(); Result result = previousResult; if (connection != null) { Database db = new Database(connection); FileObject SQLfile = null; db.shareVariablesWith(this); try {/*from ww w. j av a2 s . co m*/ db.connect(); if (sqlfromfile) { if (sqlfilename == null) throw new KettleDatabaseException(Messages.getString("JobSQL.NoSQLFileSpecified")); try { String realfilename = environmentSubstitute(sqlfilename); SQLfile = KettleVFS.getFileObject(realfilename); if (!SQLfile.exists()) { log.logError(toString(), Messages.getString("JobSQL.SQLFileNotExist", realfilename)); throw new KettleDatabaseException( Messages.getString("JobSQL.SQLFileNotExist", realfilename)); } if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobSQL.SQLFileExists", realfilename)); InputStream IS = KettleVFS.getInputStream(SQLfile); InputStreamReader BIS = new InputStreamReader(new BufferedInputStream(IS, 500)); StringBuffer lineStringBuffer = new StringBuffer(256); lineStringBuffer.setLength(0); BufferedReader buff = new BufferedReader(BIS); String sLine = null; String SFullLine = Const.CR; ; while ((sLine = buff.readLine()) != null) { if (Const.isEmpty(sLine)) { SFullLine = SFullLine + Const.CR; } else { SFullLine = SFullLine + Const.CR + sLine; } } if (!Const.isEmpty(SFullLine)) { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobSQL.Log.SQlStatement", SFullLine)); db.execStatement(SFullLine); } } catch (Exception e) { throw new KettleDatabaseException(Messages.getString("JobSQL.ErrorRunningSQLfromFile"), e); } } else { String mySQL = null; if (useVariableSubstitution) mySQL = environmentSubstitute(sql); else mySQL = sql; db.execStatements(mySQL); } } catch (KettleDatabaseException je) { result.setNrErrors(1); log.logError(toString(), Messages.getString("JobSQL.ErrorRunJobEntry", je.getMessage())); } finally { db.disconnect(); if (SQLfile != null) { try { SQLfile.close(); } catch (Exception e) { } } } } else { result.setNrErrors(1); log.logError(toString(), Messages.getString("JobSQL.NoDatabaseConnection")); } if (result.getNrErrors() == 0) { result.setResult(true); } else { result.setResult(false); } return result; }
From source file:Logger.java
/** * Print a dump of the current input or output network packet. * * @param streamId the owner of this packet * @param in true if this is an input packet * @param pkt the packet data// w w w .j a v a2s . c o m */ public static void logPacket(int streamId, boolean in, byte[] pkt) { int len = ((pkt[2] & 0xFF) << 8) | (pkt[3] & 0xFF); StringBuffer line = new StringBuffer(80); line.append("----- Stream #"); line.append(streamId); line.append(in ? " read" : " send"); line.append((pkt[1] != 0) ? " last " : " "); switch (pkt[0]) { case 1: line.append("Request packet "); break; case 2: line.append("Login packet "); break; case 3: line.append("RPC packet "); break; case 4: line.append("Reply packet "); break; case 6: line.append("Cancel packet "); break; case 14: line.append("XA control packet "); break; case 15: line.append("TDS5 Request packet "); break; case 16: line.append("MS Login packet "); break; case 17: line.append("NTLM Authentication packet "); break; case 18: line.append("MS Prelogin packet "); break; default: line.append("Invalid packet "); break; } println(line.toString()); println(""); line.setLength(0); for (int i = 0; i < len; i += 16) { if (i < 1000) { line.append(' '); } if (i < 100) { line.append(' '); } if (i < 10) { line.append(' '); } line.append(i); line.append(':').append(' '); int j = 0; for (; j < 16 && i + j < len; j++) { int val = pkt[i + j] & 0xFF; line.append(hex[val >> 4]); line.append(hex[val & 0x0F]); line.append(' '); } for (; j < 16; j++) { line.append(" "); } line.append('|'); for (j = 0; j < 16 && i + j < len; j++) { int val = pkt[i + j] & 0xFF; if (val > 31 && val < 127) { line.append((char) val); } else { line.append(' '); } } line.append('|'); println(line.toString()); line.setLength(0); } println(""); }
From source file:com.camel.framework.tag.ScriptTag.java
/** * ???script??/*w w w . jav a2 s .co m*/ * * @param sb * @param out */ private void parseToConventionalStyle(StringBuffer sb, String resourcesUrl, JspWriter out) { // js??? String[] srcArray = src.split(ITagBasic.SEPARATOR_COMMA); for (String srcStr : srcArray) { // sb.setLength(0); // ?script sb.append("<script type='").append(type).append("' data-config='").append(data_config) .append("' data-main='").append(data_main).append("' src='").append(resourcesUrl); // path ?? if (StringUtils.isNotBlank(path)) { sb.append(path).append("/"); } sb.append(srcStr.trim()).append("'></script>"); try { // ??script? out.println(sb.toString()); } catch (IOException e) { logger.error("Could not print out value '" + sb.toString(), e); } } }