List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.pactera.edg.am.metamanager.extractor.dao.impl.SequenceDaoImpl.java
public String getUuid() { StringBuffer uuid = new StringBuffer(); try {/* w ww. j a v a 2s .co m*/ uuid.append(UUID.randomUUID().toString()); } catch (Exception e) { this.createUUIDGen(); uuid.append(uuidGen.nextUUID()); } if (uuid.length() == 0) { throw new RuntimeException("UUID generate fail"); } uuid.setCharAt(0, shiftHex(uuid.charAt(0))); //hibernateuuid.hex?? return uuid.toString().replaceAll("-", ""); }
From source file:com.moss.simpledeb.core.action.LaunchScriptAction.java
@Override public void run(DebState state) throws Exception { {//from w w w . jav a 2 s .c o m File target = new File(targetFile).getParentFile(); LinkedList<File> pathsNeeded = new LinkedList<File>(); File f = target; while (f != null) { pathsNeeded.addFirst(f); f = f.getParentFile(); } for (int i = 0; i < pathLevel; i++) { pathsNeeded.removeFirst(); } for (File e : pathsNeeded) { String p = "./" + e.getPath(); if (!p.endsWith("/")) { p = p + "/"; } TarArchiveEntry tarEntry = new TarArchiveEntry(p); tarEntry.setGroupId(0); tarEntry.setGroupName("root"); tarEntry.setIds(0, 0); tarEntry.setModTime(System.currentTimeMillis()); tarEntry.setSize(0); tarEntry.setUserId(0); tarEntry.setUserName("root"); tarEntry.setMode(Integer.parseInt("755", 8)); ArchivePath path = new DirArchivePath(tarEntry); state.addPath(DebComponent.CONTENT, path); } } String cp; { StringBuffer sb = new StringBuffer(); for (String path : state.classpath) { if (sb.length() == 0) { sb.append(path); } else { sb.append(":"); sb.append(path); } } cp = sb.toString(); } StringBuilder sb = new StringBuilder(); sb.append("#!/bin/bash\n"); sb.append("CP=\""); sb.append(cp); sb.append("\"\n"); sb.append("/usr/bin/java -cp $CP "); sb.append(className); sb.append(" $@\n"); byte[] data = sb.toString().getBytes(); String entryName = "./" + targetFile; TarArchiveEntry tarEntry = new TarArchiveEntry(entryName); tarEntry.setGroupId(0); tarEntry.setGroupName("root"); tarEntry.setIds(0, 0); tarEntry.setModTime(System.currentTimeMillis()); tarEntry.setSize(data.length); tarEntry.setUserId(0); tarEntry.setUserName("root"); tarEntry.setMode(Integer.parseInt("755", 8)); ArchivePath path = new BytesArchivePath(tarEntry, data); state.addPath(DebComponent.CONTENT, path); }
From source file:com.sfs.whichdoctor.export.writer.ExportWriterBase.java
/** * Builds the export table.//from w w w .j a va2s .c om * * @param headings the headings * @param values the values * @return the string */ protected final String buildExportTable(final Collection<String> headings, final TreeMap<Integer, Collection<String>> values) { final StringBuffer table = new StringBuffer(); final StringBuffer header = new StringBuffer(); for (String heading : headings) { if (header.length() > 0) { header.append(this.getKeys().getString("ITEM_DIVIDER")); } header.append(this.getKeys().getString("HEADERITEM_PREFIX")); header.append(heading); header.append(this.getKeys().getString("HEADERITEM_SUFFIX")); } if (StringUtils.isNotBlank(header.toString())) { table.append(this.getKeys().getString("LIST_BEGINNING")); table.append(this.getKeys().getString("ROW_BEGINNING")); table.append(header.toString()); table.append(this.getKeys().getString("ROW_END")); } final StringBuffer content = new StringBuffer(); for (Integer index : values.keySet()) { Collection<String> row = values.get(index); content.append(this.getKeys().getString("ROW_BEGINNING")); StringBuffer fieldValue = new StringBuffer(); for (String field : row) { if (fieldValue.length() > 0) { fieldValue.append(this.getKeys().getString("ITEM_DIVIDER")); } fieldValue.append(this.getKeys().getString("ITEM_PREFIX")); fieldValue.append(field); fieldValue.append(this.getKeys().getString("ITEM_SUFFIX")); } content.append(fieldValue.toString()); content.append(this.getKeys().getString("ROW_END")); } if (StringUtils.isNotBlank(content.toString())) { table.append(content.toString()); } if (StringUtils.isNotBlank(header.toString())) { table.append(this.getKeys().getString("LIST_END")); } return table.toString(); }
From source file:net.jawr.web.resource.bundle.factory.util.PathNormalizer.java
private static final String buildRelativePath(String toPath, String fromPath, final char separatorChar) { // use tokeniser to traverse paths and for lazy checking StringTokenizer toTokeniser = new StringTokenizer(toPath, String.valueOf(separatorChar)); StringTokenizer fromTokeniser = new StringTokenizer(fromPath, String.valueOf(separatorChar)); int count = 0; // walk along the to path looking for divergence from the from path while (toTokeniser.hasMoreTokens() && fromTokeniser.hasMoreTokens()) { if (separatorChar == '\\') { if (!fromTokeniser.nextToken().equalsIgnoreCase(toTokeniser.nextToken())) { break; }// w w w . ja va 2s.c o m } else { if (!fromTokeniser.nextToken().equals(toTokeniser.nextToken())) { break; } } count++; } // reinitialise the tokenisers to count positions to retrieve the // gobbled token toTokeniser = new StringTokenizer(toPath, String.valueOf(separatorChar)); fromTokeniser = new StringTokenizer(fromPath, String.valueOf(separatorChar)); while (count-- > 0) { fromTokeniser.nextToken(); toTokeniser.nextToken(); } StringBuffer relativePath = new StringBuffer(); // add back refs for the rest of from location. while (fromTokeniser.hasMoreTokens()) { fromTokeniser.nextToken(); relativePath.append(".."); if (fromTokeniser.hasMoreTokens()) { relativePath.append(separatorChar); } } if (relativePath.length() != 0 && toTokeniser.hasMoreTokens()) { relativePath.append(separatorChar); } // add fwd fills for whatevers left of newPath. while (toTokeniser.hasMoreTokens()) { relativePath.append(toTokeniser.nextToken()); if (toTokeniser.hasMoreTokens()) { relativePath.append(separatorChar); } } return relativePath.toString(); }
From source file:RequesterTool.java
/** * @param i// w w w. j ava 2 s. com * @return */ private String createMessageText(int index) { StringBuffer buffer = new StringBuffer(messageSize); buffer.append("Message: " + index + " sent at: " + new Date()); if (buffer.length() > messageSize) { return buffer.substring(0, messageSize); } for (int i = buffer.length(); i < messageSize; i++) { buffer.append(' '); } return buffer.toString(); }
From source file:Strings.java
/** Process one file */ protected void process(String fileName, InputStream inStream) { try {/*w w w. j ava 2s . com*/ int i; char ch; // This line alone cuts the runtime by about 66% on large files. BufferedInputStream is = new BufferedInputStream(inStream); StringBuffer sb = new StringBuffer(); // Read a byte, cast it to char, check if part of printable string. while ((i = is.read()) != -1) { ch = (char) i; if (isStringChar(ch) || (sb.length() > 0 && ch == ' ')) // If so, build up string. sb.append(ch); else { // if not, see if anything to output. if (sb.length() == 0) continue; if (sb.length() >= minLength) { report(fileName, sb); } sb.setLength(0); } } is.close(); } catch (IOException e) { System.out.println("IOException: " + e); } }
From source file:eionet.cr.web.util.columns.SubjectPredicateColumn.java
/** * * @param objects//from ww w .j a v a 2s. c o m * @return */ private String objectValuesToCSV(Collection<ObjectDTO> objects) { StringBuffer buf = new StringBuffer(); for (ObjectDTO object : objects) { buf.append(buf.length() > 0 ? ", " : "").append(object.getValue()); } return buf.toString(); }
From source file:com.concursive.connect.web.modules.wiki.utils.HTMLToWikiUtils.java
public static void processImage(StringBuffer sb, Node n, Element element, String appendToCRLF, String contextPath, int projectId) { // Images/*from www . java 2s.c o m*/ // [[Image:Filename.jpg]] // [[Image:Filename.jpg|A caption]] // [[Image:Filename.jpg|thumb]] // [[Image:Filename.jpg|right]] // [[Image:Filename.jpg|left]] // <img // style="float: right;" // style="display:block;margin: 0 auto;" // title="This is the title of the image" // longdesc="http://i.l.cnn.net/cnn/2008/LIVING/personal/04/08/fees/art.fees.jpg?1" // src="http://i.l.cnn.net/cnn/2008/LIVING/personal/04/08/fees/art.fees.jpg" // alt="This is an image description" // width="292" // height="219" /> // image right: float: right; margin: 3px; border: 3px solid black; // image left: float: left; margin: 3px; border: 3px solid black; // <img // src="${ctx}/show/some-company/wiki-image/Workflow+-+Ticket+Example.png" // alt="Workflow - Ticket Example.png" // width="315" // height="362" /> // See if the parent is a link String link = null; String title = null; if (hasParentNodeType(n, "a")) { // Get the attributes of the link StringBuffer linkSB = new StringBuffer(); processLink(linkSB, (Element) element.getParentNode(), appendToCRLF, contextPath, projectId); link = linkSB.substring(2, linkSB.length() - 2); } else { // tooltip (will be used as caption), but not for links title = element.getAttribute("title"); } // Determine if this is an embedded video link if (link != null && link.startsWith("http://www.youtube.com/v/")) { processVideoLink(sb, n, element, appendToCRLF, contextPath, link); } else { processImage(sb, n, element, appendToCRLF, contextPath, projectId, link, title); } }
From source file:ch.entwine.weblounge.bridge.oaipmh.harvester.OaiPmhRepositoryClient.java
/** * Join the query parameters.// w w w . ja v a2 s . co m */ private String join(String... as) { StringBuffer buf = new StringBuffer(); for (String a : as) { if (a.length() > 0) buf.append(a).append("&"); } return buf.substring(0, Math.max(buf.length() - "&".length(), 0)); }
From source file:com.concursive.connect.web.modules.search.utils.SearchUtils.java
/** * Generates a list of projects that the user has access to * * @param db/*w w w.j a va2 s . c o m*/ * @param userId * @param specificProjectId * @param specificCategoryId * @return * @throws SQLException */ public static String generateValidProjects(Connection db, int userId, int specificProjectId, int specificCategoryId) throws SQLException { if (userId < 1) { return ""; } // @todo get ids from user cache // @update cache everytime a user is added or removed from a project team // get the projects for the user // get the project permissions for each project // if user has access to the data, then add to query StringBuffer projectList = new StringBuffer(); PreparedStatement pst = db .prepareStatement("SELECT project_id " + "FROM project_team " + "WHERE user_id = ? " + "AND status IS NULL " + (specificProjectId > -1 ? "AND project_id = ? " : "") + (specificCategoryId > -1 ? "AND project_id IN (SELECT project_id FROM projects WHERE category_id = ?) " : "")); int i = 0; pst.setInt(++i, userId); if (specificProjectId > -1) { pst.setInt(++i, specificProjectId); } if (specificCategoryId > -1) { pst.setInt(++i, specificCategoryId); } ResultSet rs = pst.executeQuery(); while (rs.next()) { int projectId = rs.getInt("project_id"); // these projects override the lower access projects if (projectList.length() > 0) { projectList.append(" OR "); } projectList.append(projectId); } rs.close(); pst.close(); return projectList.toString(); }